mirror of
https://github.com/bitwarden/server
synced 2025-12-24 20:23:21 +00:00
[PM-22219] - [Vault] [Server] Exclude items in default collections from Admin Console (#5992)
* add GetAllOrganizationCiphersExcludingDefaultUserCollections * add sproc * update sproc and feature flag name * add sproc. update tests * rename sproc * rename sproc * use single sproc * revert change * remove unused code. update sproc * remove joins from proc * update migration filename * fix syntax * fix indentation * remove unnecessary feature flag and go statements. clean up code * update sproc, view, and index * update sproc * update index * update timestamp * update filename. update sproc to match EF filter * match only enabled organizations. make index creation idempotent * update file timestamp * update timestamp * use square brackets * add square brackets * formatting fixes * rename view * remove index
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using AutoMapper;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.KeyManagement.UserKey;
|
||||
using Bit.Core.Utilities;
|
||||
using Bit.Core.Vault.Enums;
|
||||
@@ -1001,6 +1002,55 @@ public class CipherRepository : Repository<Core.Vault.Entities.Cipher, Cipher, G
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CipherOrganizationDetailsWithCollections>>
|
||||
GetManyCipherOrganizationDetailsExcludingDefaultCollectionsAsync(Guid organizationId)
|
||||
{
|
||||
using var scope = ServiceScopeFactory.CreateScope();
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
var defaultTypeInt = (int)CollectionType.DefaultUserCollection;
|
||||
|
||||
// filter out any cipher that belongs *only* to default collections
|
||||
// i.e. keep ciphers with no collections, or with ≥1 non-default collection
|
||||
var query = from c in dbContext.Ciphers.AsNoTracking()
|
||||
where c.UserId == null
|
||||
&& c.OrganizationId == organizationId
|
||||
&& c.Organization.Enabled
|
||||
&& (
|
||||
c.CollectionCiphers.Count() == 0
|
||||
|| c.CollectionCiphers.Any(cc => (int)cc.Collection.Type != defaultTypeInt)
|
||||
)
|
||||
select new CipherOrganizationDetailsWithCollections(
|
||||
new CipherOrganizationDetails
|
||||
{
|
||||
Id = c.Id,
|
||||
UserId = c.UserId,
|
||||
OrganizationId = c.OrganizationId,
|
||||
Type = c.Type,
|
||||
Data = c.Data,
|
||||
Favorites = c.Favorites,
|
||||
Folders = c.Folders,
|
||||
Attachments = c.Attachments,
|
||||
CreationDate = c.CreationDate,
|
||||
RevisionDate = c.RevisionDate,
|
||||
DeletedDate = c.DeletedDate,
|
||||
Reprompt = c.Reprompt,
|
||||
Key = c.Key,
|
||||
OrganizationUseTotp = c.Organization.UseTotp
|
||||
},
|
||||
new Dictionary<Guid, IGrouping<Guid, Bit.Core.Entities.CollectionCipher>>()
|
||||
)
|
||||
{
|
||||
CollectionIds = c.CollectionCiphers
|
||||
.Where(cc => (int)cc.Collection.Type != defaultTypeInt)
|
||||
.Select(cc => cc.CollectionId)
|
||||
.ToArray()
|
||||
};
|
||||
|
||||
var result = await query.ToListAsync();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="UpdateForKeyRotation(Guid, IEnumerable{Cipher})"/>
|
||||
/// <remarks>
|
||||
/// EF does not use the bulk resource creation service, so we need to use the regular update method.
|
||||
|
||||
Reference in New Issue
Block a user