1
0
mirror of https://github.com/bitwarden/server synced 2025-12-24 20:23:21 +00:00

[PM-22558] Update IOrganizationUserRepository.ReplaceAsync to preserve existing access to collections of the type DefaultUserCollection (#6037)

* feat: exclude DefaultUserCollection from GetManyByOrganizationIdWithPermissionsAsync

Updated EF implementation, SQL procedure, and unit test to verify that default user collections are filtered from results

* Update the public CollectionsController.Get method to return a NotFoundResult for collections of type DefaultUserCollection.

* Add unit tests for the public CollectionsController

* Update ICollectionRepository.GetManyByOrganizationIdAsync to exclude results of the type DefaultUserCollection

Modified the SQL stored procedure and the EF query to reflect this change and added a new integration test to ensure the functionality works as expected.

* Refactor CollectionsController to remove unused IApplicationCacheService dependency

* Update IOrganizationUserRepository.GetDetailsByIdWithCollectionsAsync to exclude DefaultUserCollections

* Update IOrganizationUserRepository.GetManyDetailsByOrganizationAsync to exclude DefaultUserCollections

* Undo change to GetByIdWithCollectionsAsync

* Update integration test to verify exclusion of DefaultUserCollection in OrganizationUserRepository.GetDetailsByIdWithCollectionsAsync

* Clarify documentation in ICollectionRepository to specify that GetManyByOrganizationIdWithAccessAsync returns only shared collections belonging to the organization.

* Update IOrganizationUserRepository.ReplaceAsync to preserve existing access to collections of the type DefaultUserCollection
This commit is contained in:
Rui Tomé
2025-07-29 15:04:45 +01:00
committed by GitHub
parent 6dea40c868
commit b00e689ff6
4 changed files with 160 additions and 3 deletions

View File

@@ -516,9 +516,11 @@ public class OrganizationUserRepository : Repository<Core.Entities.OrganizationU
{
var dbContext = GetDatabaseContext(scope);
var existingCollectionUsers = await dbContext.CollectionUsers
.Where(cu => cu.OrganizationUserId == obj.Id)
.ToListAsync();
// Retrieve all collection assignments, excluding DefaultUserCollection
var existingCollectionUsers = await (from cu in dbContext.CollectionUsers
join c in dbContext.Collections on cu.CollectionId equals c.Id
where cu.OrganizationUserId == obj.Id && c.Type != CollectionType.DefaultUserCollection
select cu).ToListAsync();
foreach (var requestedCollection in requestedCollections)
{