mirror of
https://github.com/bitwarden/server.git
synced 2025-05-20 19:14:32 -05: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:
parent
243e1de4ee
commit
99762667e9
@ -250,7 +250,17 @@ public class CollectionsController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
await _collectionService.SaveAsync(collection, groups, users);
|
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}")]
|
[HttpPut("{id}")]
|
||||||
@ -618,7 +628,16 @@ public class CollectionsController : Controller
|
|||||||
var groups = model.Groups?.Select(g => g.ToSelectionReadOnly());
|
var groups = model.Groups?.Select(g => g.ToSelectionReadOnly());
|
||||||
var users = model.Users?.Select(g => g.ToSelectionReadOnly());
|
var users = model.Users?.Select(g => g.ToSelectionReadOnly());
|
||||||
await _collectionService.SaveAsync(model.ToCollection(collection), groups, users);
|
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)
|
private async Task PutUsers_vNext(Guid id, IEnumerable<SelectionReadOnlyRequestModel> model)
|
||||||
|
@ -49,6 +49,10 @@ public class LegacyCollectionsControllerTests
|
|||||||
sutProvider.GetDependency<IOrganizationUserRepository>().GetByOrganizationAsync(orgId, orgUser.UserId.Value)
|
sutProvider.GetDependency<IOrganizationUserRepository>().GetByOrganizationAsync(orgId, orgUser.UserId.Value)
|
||||||
.Returns(orgUser);
|
.Returns(orgUser);
|
||||||
|
|
||||||
|
sutProvider.GetDependency<ICollectionRepository>()
|
||||||
|
.GetByIdAsync(Arg.Any<Guid>(), orgUser.UserId.Value, Arg.Any<bool>())
|
||||||
|
.Returns(new CollectionDetails());
|
||||||
|
|
||||||
var collectionRequest = new CollectionRequestModel
|
var collectionRequest = new CollectionRequestModel
|
||||||
{
|
{
|
||||||
Name = "encrypted_string",
|
Name = "encrypted_string",
|
||||||
@ -87,6 +91,10 @@ public class LegacyCollectionsControllerTests
|
|||||||
sutProvider.GetDependency<IOrganizationUserRepository>().GetByOrganizationAsync(orgId, orgUser.UserId.Value)
|
sutProvider.GetDependency<IOrganizationUserRepository>().GetByOrganizationAsync(orgId, orgUser.UserId.Value)
|
||||||
.Returns(orgUser);
|
.Returns(orgUser);
|
||||||
|
|
||||||
|
sutProvider.GetDependency<ICollectionRepository>()
|
||||||
|
.GetByIdAsync(Arg.Any<Guid>(), orgUser.UserId.Value, Arg.Any<bool>())
|
||||||
|
.Returns(new CollectionDetails());
|
||||||
|
|
||||||
var collectionRequest = new CollectionRequestModel
|
var collectionRequest = new CollectionRequestModel
|
||||||
{
|
{
|
||||||
Name = "encrypted_string",
|
Name = "encrypted_string",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user