From da0da772e907f149d1c6bc26c73ec02b95248f5b Mon Sep 17 00:00:00 2001 From: Shane Melton Date: Thu, 15 Feb 2024 09:49:37 -0800 Subject: [PATCH] [PM-6325] Include permission details for non FC organizations when creating/updating a collection (#3810) --- src/Api/Controllers/CollectionsController.cs | 26 ++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Api/Controllers/CollectionsController.cs b/src/Api/Controllers/CollectionsController.cs index cd933739ff..3eeae17a50 100644 --- a/src/Api/Controllers/CollectionsController.cs +++ b/src/Api/Controllers/CollectionsController.cs @@ -253,7 +253,18 @@ public class CollectionsController : Controller await _collectionService.SaveAsync(collection, groups, users); - return new CollectionResponseModel(collection); + if (!_currentContext.UserId.HasValue || await _currentContext.ProviderUserForOrgAsync(orgId)) + { + 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 userCollectionDetails == null + ? new CollectionResponseModel(collection) + : new CollectionDetailsResponseModel(userCollectionDetails); } [HttpPut("{id}")] @@ -276,7 +287,18 @@ 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 || await _currentContext.ProviderUserForOrgAsync(collection.OrganizationId)) + { + 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 updatedCollectionDetails == null + ? new CollectionResponseModel(collection) + : new CollectionDetailsResponseModel(updatedCollectionDetails); } [HttpPut("{id}/users")]