-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EC-508] SCIM CQRS Refactor - Users/GetList #2265
Merged
r-tome
merged 14 commits into
feature/scim-cqrs
from
EC-535-scim-cqrs-refactor-users-get-list
Oct 18, 2022
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
148e080
[EC-390] Added Scim.Test unit tests project
r-tome b925cc7
[EC-390] Added ConflictException type. Updated BadRequestException to…
r-tome dd02704
[EC-535] Implemented CQRS for Users GetList and added unit tests
r-tome 02c5c7d
[EC-508] Created ScimServiceCollectionExtensions and renamed GetUsers…
r-tome 2873acb
Merge branch 'master' into EC-535-scim-cqrs-refactor-users-get-list
r-tome 1417f44
[EC-508] Renamed AddScimCommands to AddScimUserQueries
r-tome a5d8eb1
Merge remote-tracking branch 'origin/master' into EC-535-scim-cqrs-re…
eliykat d739da3
[EC-508] Removed unneeded IUserRepository and IOptions<ScimSettings> …
r-tome 3199685
[EC-508] Sorted UsersController properties and dependencies
r-tome 46cb688
[EC-508] Remove 'Queries' folder from Scim and Scim.Test
r-tome 6d62ffd
Merge branch 'master' into EC-535-scim-cqrs-refactor-users-get-list
r-tome b7c144f
[EC-508] Move ScimListResponseModel creation to Scim.UsersController
r-tome 4f261d0
[EC-508] Move ScimUserResponseModel creation to Scim.UsersController
r-tome 1f31f8f
Merge branch 'feature/scim-cqrs' into EC-535-scim-cqrs-refactor-users…
r-tome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Bit.Core.Models.Data.Organizations.OrganizationUsers; | ||
using Bit.Core.Repositories; | ||
using Bit.Scim.Users.Interfaces; | ||
|
||
namespace Bit.Scim.Users; | ||
|
||
public class GetUsersListQuery : IGetUsersListQuery | ||
{ | ||
private readonly IOrganizationUserRepository _organizationUserRepository; | ||
|
||
public GetUsersListQuery(IOrganizationUserRepository organizationUserRepository) | ||
{ | ||
_organizationUserRepository = organizationUserRepository; | ||
} | ||
|
||
public async Task<(IEnumerable<OrganizationUserUserDetails> userList, int totalResults)> GetUsersListAsync(Guid organizationId, string filter, int? count, int? startIndex) | ||
{ | ||
string emailFilter = null; | ||
string usernameFilter = null; | ||
string externalIdFilter = null; | ||
if (!string.IsNullOrWhiteSpace(filter)) | ||
{ | ||
if (filter.StartsWith("userName eq ")) | ||
{ | ||
usernameFilter = filter.Substring(12).Trim('"').ToLowerInvariant(); | ||
if (usernameFilter.Contains("@")) | ||
{ | ||
emailFilter = usernameFilter; | ||
} | ||
} | ||
else if (filter.StartsWith("externalId eq ")) | ||
{ | ||
externalIdFilter = filter.Substring(14).Trim('"'); | ||
} | ||
} | ||
|
||
var userList = new List<OrganizationUserUserDetails>(); | ||
var orgUsers = await _organizationUserRepository.GetManyDetailsByOrganizationAsync(organizationId); | ||
var totalResults = 0; | ||
if (!string.IsNullOrWhiteSpace(emailFilter)) | ||
{ | ||
var orgUser = orgUsers.FirstOrDefault(ou => ou.Email.ToLowerInvariant() == emailFilter); | ||
if (orgUser != null) | ||
{ | ||
userList.Add(orgUser); | ||
} | ||
totalResults = userList.Count; | ||
} | ||
else if (!string.IsNullOrWhiteSpace(externalIdFilter)) | ||
{ | ||
var orgUser = orgUsers.FirstOrDefault(ou => ou.ExternalId == externalIdFilter); | ||
if (orgUser != null) | ||
{ | ||
userList.Add(orgUser); | ||
} | ||
totalResults = userList.Count; | ||
} | ||
else if (string.IsNullOrWhiteSpace(filter) && startIndex.HasValue && count.HasValue) | ||
{ | ||
userList = orgUsers.OrderBy(ou => ou.Email) | ||
.Skip(startIndex.Value - 1) | ||
.Take(count.Value) | ||
.ToList(); | ||
totalResults = orgUsers.Count; | ||
} | ||
|
||
return (userList, totalResults); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
using Bit.Scim.Models; | ||
using Bit.Core.Models.Data.Organizations.OrganizationUsers; | ||
|
||
namespace Bit.Scim.Users.Interfaces; | ||
|
||
public interface IGetUserQuery | ||
{ | ||
Task<ScimUserResponseModel> GetUserAsync(Guid organizationId, Guid id); | ||
Task<OrganizationUserUserDetails> GetUserAsync(Guid organizationId, Guid id); | ||
} |
8 changes: 8 additions & 0 deletions
8
bitwarden_license/src/Scim/Users/Interfaces/IGetUsersListQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Bit.Core.Models.Data.Organizations.OrganizationUsers; | ||
|
||
namespace Bit.Scim.Users.Interfaces; | ||
|
||
public interface IGetUsersListQuery | ||
{ | ||
Task<(IEnumerable<OrganizationUserUserDetails> userList, int totalResults)> GetUsersListAsync(Guid organizationId, string filter, int? count, int? startIndex); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just pull this
GetUserQuery
back out into the controller (i.e. leave it how it was). It was an early one that I approved before we had that discussion with Oscar about when it's worth using a query. In this case, the repository call is basically the query, there's so little code here that we can just have it in the controller. (sorry for the busywork)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do this in a separate PR though, if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that on the next PR when merging to master. Thanks!