-
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
[PM-12479] - Adding group-details endpoint #4959
Open
jrmccannon
wants to merge
7
commits into
main
Choose a base branch
from
ac/jmccannon/pm-12479-route-change
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+241
โ139
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3621491
Added group-details endpoint.
jrmccannon c5cd432
added feature flag.
jrmccannon 8fecf61
Added stubbed out CanViewDetails Requirement.
jrmccannon 80d090f
Adding ReadDetail operation logic and tests.
jrmccannon 6cfe7b3
Moving Group auth into Admin Console core code.
jrmccannon ccdb29c
Moved OrgScope to shared folder. Moved auth stuff to admin console foโฆ
jrmccannon 3ae2399
formatting
jrmccannon 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
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
62 changes: 0 additions & 62 deletions
62
src/Api/Vault/AuthorizationHandlers/Groups/GroupAuthorizationHandler.cs
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src/Api/Vault/AuthorizationHandlers/Groups/GroupOperations.cs
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
src/Core/AdminConsole/OrganizationFeatures/Groups/Authorization/GroupAuthorizationHandler.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,42 @@ | ||
๏ปฟ#nullable enable | ||
using Bit.Core.AdminConsole.OrganizationFeatures.Shared.Authorization; | ||
using Bit.Core.Context; | ||
using Bit.Core.Enums; | ||
using Microsoft.AspNetCore.Authorization; | ||
|
||
namespace Bit.Core.AdminConsole.OrganizationFeatures.Groups.Authorization; | ||
|
||
/// <summary> | ||
/// Handles authorization logic for Group operations. | ||
/// This uses new logic implemented in the Flexible Collections initiative. | ||
/// </summary> | ||
public class GroupAuthorizationHandler(ICurrentContext currentContext) | ||
: AuthorizationHandler<GroupOperationRequirement, OrganizationScope> | ||
{ | ||
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, | ||
GroupOperationRequirement requirement, OrganizationScope organizationScope) | ||
{ | ||
var authorized = requirement switch | ||
{ | ||
not null when requirement.Name == nameof(GroupOperations.ReadAll) => | ||
await CanReadAllAsync(organizationScope), | ||
not null when requirement.Name == nameof(GroupOperations.ReadAllDetails) => | ||
await CanViewGroupDetailsAsync(organizationScope), | ||
_ => false | ||
Check warning on line 25 in src/Core/AdminConsole/OrganizationFeatures/Groups/Authorization/GroupAuthorizationHandler.cs Codecov / codecov/patchsrc/Core/AdminConsole/OrganizationFeatures/Groups/Authorization/GroupAuthorizationHandler.cs#L25
|
||
}; | ||
|
||
if (requirement is not null && authorized) | ||
{ | ||
context.Succeed(requirement); | ||
} | ||
} | ||
|
||
private async Task<bool> CanReadAllAsync(OrganizationScope organizationScope) => | ||
currentContext.GetOrganization(organizationScope) is not null | ||
|| await currentContext.ProviderUserForOrgAsync(organizationScope); | ||
|
||
private async Task<bool> CanViewGroupDetailsAsync(OrganizationScope organizationScope) => | ||
currentContext.GetOrganization(organizationScope) is { Type: OrganizationUserType.Owner } or { Type: OrganizationUserType.Admin } | ||
or { Permissions: { ManageGroups: true } or { ManageUsers: true } } | ||
|| await currentContext.ProviderUserForOrgAsync(organizationScope); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Core/AdminConsole/OrganizationFeatures/Groups/Authorization/GroupOperations.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,17 @@ | ||
๏ปฟusing Microsoft.AspNetCore.Authorization.Infrastructure; | ||
|
||
namespace Bit.Core.AdminConsole.OrganizationFeatures.Groups.Authorization; | ||
|
||
public class GroupOperationRequirement : OperationAuthorizationRequirement | ||
{ | ||
public GroupOperationRequirement(string name) | ||
{ | ||
Name = name; | ||
} | ||
} | ||
|
||
public static class GroupOperations | ||
{ | ||
public static readonly GroupOperationRequirement ReadAll = new(nameof(ReadAll)); | ||
public static readonly GroupOperationRequirement ReadAllDetails = new(nameof(ReadAllDetails)); | ||
} |
1 change: 1 addition & 0 deletions
1
...atures/OrganizationUsers/Authorization/OrganizationUserUserDetailsAuthorizationHandler.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
10 changes: 3 additions & 7 deletions
10
...es/OrganizationUsers/Authorization/OrganizationUserUserMiniDetailsAuthorizationHandler.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
2 changes: 1 addition & 1 deletion
2
...nUsers/Authorization/OrganizationScope.cs โ ...Shared/Authorization/OrganizationScope.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
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.
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.
Why remove
groups
from the top-level route here?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.
The top level was removed since the new route would be
organizations/{id}/group-details
since group details isn't following/groups
. I believe the only way to override that would be to put a/
at the start of the route, but then you'd override any additional route pathing that was set up higher in the stack.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.
In that case I suggest leaving
groups
in the top-level route and usingdetails
at the method level, i.e.organizations/{id}/groups/details
. (We already do this for collection details.) My main concern is that all our controllers use a controller-level route, this would be an outlier that is easily missed. This also keeps all groups-related resources under thegroups
path which I think might be better REST design (although that might be arguable).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 see I specified
group-details
in the Jira ticket, that's my bad!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.
No worries. Easy fix. I'll move group back to the top and make this one details. I'll update the client code accordingly as well.