1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-21 12:05:42 +01:00

[AC-1890] Include collection permission details in PUT/POST response (#3658)

* [Ac-1890] Return CollectionDetailsResponseModel for collection PUT/POST endpoints when a userId is available in the current context

* [AC-1890] Fix broken tests

* [AC-1890] Update to use Organization FC column
This commit is contained in:
Shane Melton 2024-01-24 08:26:37 -08:00 committed by GitHub
parent 243e1de4ee
commit 99762667e9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 2 deletions

View File

@ -250,7 +250,17 @@ public class CollectionsController : Controller
}
await _collectionService.SaveAsync(collection, groups, users);
return new CollectionResponseModel(collection);
if (!_currentContext.UserId.HasValue)
{
return new CollectionResponseModel(collection);
}
// If we have a user, fetch the collection to get the latest permission details
var userCollectionDetails = await _collectionRepository.GetByIdAsync(collection.Id,
_currentContext.UserId.Value, await FlexibleCollectionsIsEnabledAsync(collection.OrganizationId));
return new CollectionDetailsResponseModel(userCollectionDetails);
}
[HttpPut("{id}")]
@ -618,7 +628,16 @@ public class CollectionsController : Controller
var groups = model.Groups?.Select(g => g.ToSelectionReadOnly());
var users = model.Users?.Select(g => g.ToSelectionReadOnly());
await _collectionService.SaveAsync(model.ToCollection(collection), groups, users);
return new CollectionResponseModel(collection);
if (!_currentContext.UserId.HasValue)
{
return new CollectionResponseModel(collection);
}
// If we have a user, fetch the collection details to get the latest permission details for the user
var updatedCollectionDetails = await _collectionRepository.GetByIdAsync(id, _currentContext.UserId.Value, await FlexibleCollectionsIsEnabledAsync(collection.OrganizationId));
return new CollectionDetailsResponseModel(updatedCollectionDetails);
}
private async Task PutUsers_vNext(Guid id, IEnumerable<SelectionReadOnlyRequestModel> model)

View File

@ -49,6 +49,10 @@ public class LegacyCollectionsControllerTests
sutProvider.GetDependency<IOrganizationUserRepository>().GetByOrganizationAsync(orgId, orgUser.UserId.Value)
.Returns(orgUser);
sutProvider.GetDependency<ICollectionRepository>()
.GetByIdAsync(Arg.Any<Guid>(), orgUser.UserId.Value, Arg.Any<bool>())
.Returns(new CollectionDetails());
var collectionRequest = new CollectionRequestModel
{
Name = "encrypted_string",
@ -87,6 +91,10 @@ public class LegacyCollectionsControllerTests
sutProvider.GetDependency<IOrganizationUserRepository>().GetByOrganizationAsync(orgId, orgUser.UserId.Value)
.Returns(orgUser);
sutProvider.GetDependency<ICollectionRepository>()
.GetByIdAsync(Arg.Any<Guid>(), orgUser.UserId.Value, Arg.Any<bool>())
.Returns(new CollectionDetails());
var collectionRequest = new CollectionRequestModel
{
Name = "encrypted_string",