mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
[AC-1110] add deleteAnyCollection permission to bulk delete (#2766)
* [AC-1110] add deleteAnyCollection permission to bulk delete * [AC-1110] call collection service instead of repo for user collections * [AC-1110] fix tests * [AC-1110] fix more tests
This commit is contained in:
parent
e5aafe1c8b
commit
dafcdde715
@ -204,12 +204,12 @@ public class CollectionsController : Controller
|
|||||||
{
|
{
|
||||||
var orgId = new Guid(model.OrganizationId);
|
var orgId = new Guid(model.OrganizationId);
|
||||||
var collectionIds = model.Ids.Select(i => new Guid(i));
|
var collectionIds = model.Ids.Select(i => new Guid(i));
|
||||||
if (!await _currentContext.DeleteAssignedCollections(orgId))
|
if (!await _currentContext.DeleteAssignedCollections(orgId) && !await _currentContext.DeleteAnyCollection(orgId))
|
||||||
{
|
{
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
var userCollections = await _collectionRepository.GetManyByUserIdAsync(_currentContext.UserId.Value);
|
var userCollections = await _collectionService.GetOrganizationCollections(orgId);
|
||||||
var filteredCollections = userCollections.Where(c => collectionIds.Contains(c.Id) && c.OrganizationId == orgId);
|
var filteredCollections = userCollections.Where(c => collectionIds.Contains(c.Id) && c.OrganizationId == orgId);
|
||||||
|
|
||||||
if (!filteredCollections.Any())
|
if (!filteredCollections.Any())
|
||||||
|
@ -148,7 +148,7 @@ public class CollectionsControllerTests
|
|||||||
OrganizationId = orgId.ToString()
|
OrganizationId = orgId.ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
var collections = new List<CollectionDetails>
|
var collections = new List<Collection>
|
||||||
{
|
{
|
||||||
new CollectionDetails
|
new CollectionDetails
|
||||||
{
|
{
|
||||||
@ -170,8 +170,8 @@ public class CollectionsControllerTests
|
|||||||
.UserId
|
.UserId
|
||||||
.Returns(user.Id);
|
.Returns(user.Id);
|
||||||
|
|
||||||
sutProvider.GetDependency<ICollectionRepository>()
|
sutProvider.GetDependency<ICollectionService>()
|
||||||
.GetManyByUserIdAsync(user.Id)
|
.GetOrganizationCollections(orgId)
|
||||||
.Returns(collections);
|
.Returns(collections);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@ -219,7 +219,7 @@ public class CollectionsControllerTests
|
|||||||
OrganizationId = orgId.ToString()
|
OrganizationId = orgId.ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
var collections = new List<CollectionDetails>
|
var collections = new List<Collection>
|
||||||
{
|
{
|
||||||
new CollectionDetails
|
new CollectionDetails
|
||||||
{
|
{
|
||||||
@ -236,8 +236,8 @@ public class CollectionsControllerTests
|
|||||||
.UserId
|
.UserId
|
||||||
.Returns(user.Id);
|
.Returns(user.Id);
|
||||||
|
|
||||||
sutProvider.GetDependency<ICollectionRepository>()
|
sutProvider.GetDependency<ICollectionService>()
|
||||||
.GetManyByUserIdAsync(user.Id)
|
.GetOrganizationCollections(orgId)
|
||||||
.Returns(collections);
|
.Returns(collections);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
Loading…
Reference in New Issue
Block a user