mirror of
https://github.com/bitwarden/server
synced 2025-12-28 06:03:29 +00:00
update collections admin proc and repo (#6374)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using AutoMapper;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -145,9 +146,11 @@ public class CollectionCipherRepository : BaseEntityFrameworkRepository, ICollec
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var availableCollections = await (from c in dbContext.Collections
|
||||
where c.OrganizationId == organizationId
|
||||
select c).ToListAsync();
|
||||
|
||||
var availableCollectionIds = await (from c in dbContext.Collections
|
||||
where c.OrganizationId == organizationId
|
||||
&& c.Type != CollectionType.DefaultUserCollection
|
||||
select c.Id).ToListAsync();
|
||||
|
||||
var currentCollectionCiphers = await (from cc in dbContext.CollectionCiphers
|
||||
where cc.CipherId == cipherId
|
||||
@@ -155,6 +158,8 @@ public class CollectionCipherRepository : BaseEntityFrameworkRepository, ICollec
|
||||
|
||||
foreach (var requestedCollectionId in collectionIds)
|
||||
{
|
||||
if (!availableCollectionIds.Contains(requestedCollectionId)) continue;
|
||||
|
||||
var requestedCollectionCipher = currentCollectionCiphers
|
||||
.FirstOrDefault(cc => cc.CollectionId == requestedCollectionId);
|
||||
|
||||
@@ -168,7 +173,7 @@ public class CollectionCipherRepository : BaseEntityFrameworkRepository, ICollec
|
||||
}
|
||||
}
|
||||
|
||||
dbContext.RemoveRange(currentCollectionCiphers.Where(cc => !collectionIds.Contains(cc.CollectionId)));
|
||||
dbContext.RemoveRange(currentCollectionCiphers.Where(cc => availableCollectionIds.Contains(cc.CollectionId) && !collectionIds.Contains(cc.CollectionId)));
|
||||
await dbContext.UserBumpAccountRevisionDateByOrganizationIdAsync(organizationId);
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user