diff --git a/src/Api/Controllers/CollectionsController.cs b/src/Api/Controllers/CollectionsController.cs index 407251801..6c1080503 100644 --- a/src/Api/Controllers/CollectionsController.cs +++ b/src/Api/Controllers/CollectionsController.cs @@ -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 model) diff --git a/test/Api.Test/Controllers/LegacyCollectionsControllerTests.cs b/test/Api.Test/Controllers/LegacyCollectionsControllerTests.cs index 7b3bad676..0d2ec824f 100644 --- a/test/Api.Test/Controllers/LegacyCollectionsControllerTests.cs +++ b/test/Api.Test/Controllers/LegacyCollectionsControllerTests.cs @@ -49,6 +49,10 @@ public class LegacyCollectionsControllerTests sutProvider.GetDependency().GetByOrganizationAsync(orgId, orgUser.UserId.Value) .Returns(orgUser); + sutProvider.GetDependency() + .GetByIdAsync(Arg.Any(), orgUser.UserId.Value, Arg.Any()) + .Returns(new CollectionDetails()); + var collectionRequest = new CollectionRequestModel { Name = "encrypted_string", @@ -87,6 +91,10 @@ public class LegacyCollectionsControllerTests sutProvider.GetDependency().GetByOrganizationAsync(orgId, orgUser.UserId.Value) .Returns(orgUser); + sutProvider.GetDependency() + .GetByIdAsync(Arg.Any(), orgUser.UserId.Value, Arg.Any()) + .Returns(new CollectionDetails()); + var collectionRequest = new CollectionRequestModel { Name = "encrypted_string",