1
0
mirror of https://github.com/bitwarden/server synced 2025-12-18 09:13:19 +00:00

Split out repositories to Infrastructure.Dapper / EntityFramework (#1759)

This commit is contained in:
Oscar Hinton
2022-01-11 10:40:51 +01:00
committed by GitHub
parent e2c6fc81f4
commit e4a10aae27
536 changed files with 1629 additions and 1589 deletions

View File

@@ -0,0 +1,55 @@
using System;
using System.Linq;
using Bit.Core.Enums;
using Bit.Core.Models.Data;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
{
public class UserCollectionDetailsQuery : IQuery<CollectionDetails>
{
private readonly Guid? _userId;
public UserCollectionDetailsQuery(Guid? userId)
{
_userId = userId;
}
public virtual IQueryable<CollectionDetails> Run(DatabaseContext dbContext)
{
var query = from c in dbContext.Collections
join ou in dbContext.OrganizationUsers
on c.OrganizationId equals ou.OrganizationId
join o in dbContext.Organizations
on c.OrganizationId equals o.Id
join cu in dbContext.CollectionUsers
on c.Id equals cu.CollectionId into cu_g
from cu in cu_g.DefaultIfEmpty()
where ou.AccessAll && cu.OrganizationUserId == ou.Id
join gu in dbContext.GroupUsers
on ou.Id equals gu.OrganizationUserId into gu_g
from gu in gu_g.DefaultIfEmpty()
where cu.CollectionId == null && !ou.AccessAll
join g in dbContext.Groups
on gu.GroupId equals g.Id into g_g
from g in g_g.DefaultIfEmpty()
join cg in dbContext.CollectionGroups
on gu.GroupId equals cg.GroupId into cg_g
from cg in cg_g.DefaultIfEmpty()
where !g.AccessAll && cg.CollectionId == c.Id &&
ou.UserId == _userId &&
ou.Status == OrganizationUserStatusType.Confirmed &&
o.Enabled &&
(ou.AccessAll || cu.CollectionId != null || g.AccessAll || cg.CollectionId != null)
select new { c, ou, o, cu, gu, g, cg };
return query.Select(x => new CollectionDetails
{
Id = x.c.Id,
OrganizationId = x.c.OrganizationId,
Name = x.c.Name,
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),
});
}
}
}