1
0
mirror of https://github.com/bitwarden/server synced 2025-12-10 05:13:48 +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:
Jordan Aasen
2025-09-08 08:23:08 -07:00
committed by GitHub
parent 0fbbb6a984
commit 39ad020418
11 changed files with 299 additions and 3 deletions

View File

@@ -7,6 +7,7 @@ using Bit.Core.Entities;
using Bit.Core.KeyManagement.UserKey;
using Bit.Core.Settings;
using Bit.Core.Tools.Entities;
using Bit.Core.Utilities;
using Bit.Core.Vault.Entities;
using Bit.Core.Vault.Models.Data;
using Bit.Core.Vault.Repositories;
@@ -867,6 +868,47 @@ public class CipherRepository : Repository<Cipher, Guid>, ICipherRepository
}
}
public async Task<IEnumerable<CipherOrganizationDetailsWithCollections>>
GetManyCipherOrganizationDetailsExcludingDefaultCollectionsAsync(Guid orgId)
{
await using var connection = new SqlConnection(ConnectionString);
var dict = new Dictionary<Guid, CipherOrganizationDetailsWithCollections>();
var tempCollections = new Dictionary<Guid, List<Guid>>();
await connection.QueryAsync<CipherOrganizationDetailsWithCollections, CollectionCipher, CipherOrganizationDetailsWithCollections>(
$"[{Schema}].[CipherOrganizationDetails_ReadByOrganizationIdExcludingDefaultCollections]",
(cipher, cc) =>
{
if (!dict.TryGetValue(cipher.Id, out var details))
{
details = new CipherOrganizationDetailsWithCollections(cipher, /*dummy*/null);
dict.Add(cipher.Id, details);
tempCollections[cipher.Id] = new List<Guid>();
}
if (cc?.CollectionId != null)
{
tempCollections[cipher.Id].AddIfNotExists(cc.CollectionId);
}
return details;
},
new { OrganizationId = orgId },
splitOn: "CollectionId",
commandType: CommandType.StoredProcedure
);
// now assign each List<Guid> back to the array property in one shot
foreach (var kv in dict)
{
kv.Value.CollectionIds = tempCollections[kv.Key].ToArray();
}
return dict.Values.ToList();
}
private DataTable BuildCiphersTable(SqlBulkCopy bulkCopy, IEnumerable<Cipher> ciphers)
{
var c = ciphers.FirstOrDefault();