mirror of
https://github.com/bitwarden/server
synced 2025-12-16 08:13:33 +00:00
[PS-1806] Fix EF CollectionRepository GetManyByUserId (#2409)
* Rewrite ReadOnly and HidePasswords * Rewrote them to generate a CASE statement similar to T-SQL * Rewrite Grouping Expression * Use multiple groups just like T-SQL * Run it all on the database instead of in memory * Fix linter
This commit is contained in:
@@ -10,6 +10,7 @@ public class UserCollectionDetailsQuery : IQuery<CollectionDetails>
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
|
||||
public virtual IQueryable<CollectionDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from c in dbContext.Collections
|
||||
@@ -44,6 +45,8 @@ public class UserCollectionDetailsQuery : IQuery<CollectionDetails>
|
||||
o.Enabled &&
|
||||
(ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null)
|
||||
select new { c, ou, o, cu, gu, g, cg };
|
||||
#pragma warning disable IDE0075
|
||||
// I want to leave the ReadOnly and HidePasswords the way they are because it helps show the exact logic we are trying to replicate
|
||||
return query.Select(x => new CollectionDetails
|
||||
{
|
||||
Id = x.c.Id,
|
||||
@@ -52,8 +55,11 @@ public class UserCollectionDetailsQuery : IQuery<CollectionDetails>
|
||||
ExternalId = x.c.ExternalId,
|
||||
CreationDate = x.c.CreationDate,
|
||||
RevisionDate = x.c.RevisionDate,
|
||||
ReadOnly = !x.ou.AccessAll || !x.g.AccessAll || (x.cu.ReadOnly || x.cg.ReadOnly),
|
||||
HidePasswords = !x.ou.AccessAll || !x.g.AccessAll || (x.cu.HidePasswords || x.cg.HidePasswords),
|
||||
ReadOnly = x.ou.AccessAll || x.g.AccessAll || ((x.cu != null ? x.cu.ReadOnly : (bool?)null) ?? (x.cg != null ? x.cg.ReadOnly : (bool?)null) ?? false) ? false : true,
|
||||
HidePasswords = x.ou.AccessAll || x.g.AccessAll || ((x.cu != null ? x.cu.HidePasswords : (bool?)null) ?? (x.cg != null ? x.cg.HidePasswords : (bool?)null) ?? false) ? false : true,
|
||||
});
|
||||
#pragma warning restore IDE0075
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user