1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 09:02:48 -05:00

Add missing flags

This commit is contained in:
Thomas Rittson
2023-10-09 14:15:33 +10:00
parent 8ebac62dff
commit 1dad2af7c3
2 changed files with 17 additions and 6 deletions

View File

@ -201,6 +201,8 @@ public class CollectionsController : Controller
} }
[HttpPost("bulk-access")] [HttpPost("bulk-access")]
[RequireFeature(FeatureFlagKeys.BulkCollectionAccess)]
[RequireFeature(FeatureFlagKeys.FlexibleCollections)]
public async Task PostBulkCollectionAccess([FromBody] BulkCollectionAccessRequestModel model) public async Task PostBulkCollectionAccess([FromBody] BulkCollectionAccessRequestModel model)
{ {
var collections = await _collectionRepository.GetManyByManyIdsAsync(model.CollectionIds); var collections = await _collectionRepository.GetManyByManyIdsAsync(model.CollectionIds);
@ -255,6 +257,7 @@ public class CollectionsController : Controller
} }
await _deleteCollectionCommand.DeleteManyAsync(collections); await _deleteCollectionCommand.DeleteManyAsync(collections);
return;
} }
// Old pre-flexible collections logic follows // Old pre-flexible collections logic follows

View File

@ -19,6 +19,7 @@ public class CollectionService : ICollectionService
private readonly IMailService _mailService; private readonly IMailService _mailService;
private readonly IReferenceEventService _referenceEventService; private readonly IReferenceEventService _referenceEventService;
private readonly ICurrentContext _currentContext; private readonly ICurrentContext _currentContext;
private readonly IFeatureService _featureService;
public CollectionService( public CollectionService(
IEventService eventService, IEventService eventService,
@ -28,7 +29,8 @@ public class CollectionService : ICollectionService
IUserRepository userRepository, IUserRepository userRepository,
IMailService mailService, IMailService mailService,
IReferenceEventService referenceEventService, IReferenceEventService referenceEventService,
ICurrentContext currentContext) ICurrentContext currentContext,
IFeatureService featureService)
{ {
_eventService = eventService; _eventService = eventService;
_organizationRepository = organizationRepository; _organizationRepository = organizationRepository;
@ -38,6 +40,7 @@ public class CollectionService : ICollectionService
_mailService = mailService; _mailService = mailService;
_referenceEventService = referenceEventService; _referenceEventService = referenceEventService;
_currentContext = currentContext; _currentContext = currentContext;
_featureService = featureService;
} }
public async Task SaveAsync(Collection collection, IEnumerable<CollectionAccessSelection> groups = null, public async Task SaveAsync(Collection collection, IEnumerable<CollectionAccessSelection> groups = null,
@ -51,12 +54,17 @@ public class CollectionService : ICollectionService
var groupsList = groups?.ToList(); var groupsList = groups?.ToList();
var usersList = users?.ToList(); var usersList = users?.ToList();
var groupHasManageAccess = groupsList?.Any(g => g.Manage) ?? false;
var userHasManageAccess = usersList?.Any(u => u.Manage) ?? false; // If using Flexible Collections - a collection should always have someone with Can Manage permissions
if (!groupHasManageAccess && !userHasManageAccess) if (_featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections, _currentContext))
{ {
throw new BadRequestException( var groupHasManageAccess = groupsList?.Any(g => g.Manage) ?? false;
"At least one member or group must have can manage permission."); var userHasManageAccess = usersList?.Any(u => u.Manage) ?? false;
if (!groupHasManageAccess && !userHasManageAccess)
{
throw new BadRequestException(
"At least one member or group must have can manage permission.");
}
} }
if (collection.Id == default(Guid)) if (collection.Id == default(Guid))