mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 09:02:48 -05:00
[AC-1139] Modified CollectionsController.Get to check access before getting collections
This commit is contained in:
@ -135,10 +135,13 @@ public class CollectionsController : Controller
|
||||
IEnumerable<Collection> orgCollections;
|
||||
|
||||
if (FlexibleCollectionsIsEnabled)
|
||||
{
|
||||
var readAll = (await _authorizationService.AuthorizeAsync(User, null, CollectionOperations.ReadAll(orgId))).Succeeded;
|
||||
if (readAll)
|
||||
{
|
||||
orgCollections = await _collectionRepository.GetManyByOrganizationIdAsync(orgId);
|
||||
var readAllAuthorized = (await _authorizationService.AuthorizeAsync(User, orgCollections, CollectionOperations.ReadAll)).Succeeded;
|
||||
if (!readAllAuthorized)
|
||||
}
|
||||
else
|
||||
{
|
||||
var collections = await _collectionRepository.GetManyByUserIdAsync(_currentContext.UserId.Value);
|
||||
orgCollections = collections.Where(c => c.OrganizationId == orgId);
|
||||
|
@ -2,13 +2,26 @@
|
||||
|
||||
namespace Bit.Api.Vault.AuthorizationHandlers.Collections;
|
||||
|
||||
public class CollectionOperationRequirement : OperationAuthorizationRequirement { }
|
||||
public class CollectionOperationRequirement : OperationAuthorizationRequirement
|
||||
{
|
||||
public Guid OrganizationId { get; set; }
|
||||
|
||||
public CollectionOperationRequirement() { }
|
||||
|
||||
public CollectionOperationRequirement(string name, Guid organizationId)
|
||||
{
|
||||
Name = name;
|
||||
OrganizationId = organizationId;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CollectionOperations
|
||||
{
|
||||
public static readonly CollectionOperationRequirement Create = new() { Name = nameof(Create) };
|
||||
public static readonly CollectionOperationRequirement ReadAll = new() { Name = nameof(ReadAll) };
|
||||
public static readonly CollectionOperationRequirement Update = new() { Name = nameof(Update) };
|
||||
public static CollectionOperationRequirement ReadAll(Guid organizationId)
|
||||
{
|
||||
return new CollectionOperationRequirement(nameof(ReadAll), organizationId);
|
||||
}
|
||||
public static readonly CollectionOperationRequirement Delete = new() { Name = nameof(Delete) };
|
||||
/// <summary>
|
||||
/// The operation that represents creating, updating, or removing collection access.
|
||||
|
Reference in New Issue
Block a user