mirror of
https://github.com/bitwarden/server.git
synced 2025-02-17 02:01:53 +01:00
PS-1806 - fix joins on some ef queries (#2421)
* fix joins on some ef queries * fix formatting
This commit is contained in:
parent
02e4b10ae8
commit
47c8f043e1
@ -23,31 +23,39 @@ public class CipherUpdateCollectionsQuery : IQuery<CollectionCipher>
|
|||||||
}
|
}
|
||||||
|
|
||||||
var availibleCollections = !_cipher.UserId.HasValue ?
|
var availibleCollections = !_cipher.UserId.HasValue ?
|
||||||
|
|
||||||
from c in dbContext.Collections
|
from c in dbContext.Collections
|
||||||
where c.OrganizationId == _cipher.OrganizationId
|
where c.OrganizationId == _cipher.OrganizationId
|
||||||
select c.Id :
|
select c.Id :
|
||||||
|
|
||||||
from c in dbContext.Collections
|
from c in dbContext.Collections
|
||||||
|
|
||||||
join o in dbContext.Organizations
|
join o in dbContext.Organizations
|
||||||
on c.OrganizationId equals o.Id
|
on c.OrganizationId equals o.Id
|
||||||
|
|
||||||
join ou in dbContext.OrganizationUsers
|
join ou in dbContext.OrganizationUsers
|
||||||
on o.Id equals ou.OrganizationId
|
on new { OrganizationId = o.Id, _cipher.UserId } equals new { ou.OrganizationId, ou.UserId }
|
||||||
where ou.UserId == _cipher.UserId
|
|
||||||
join cu in dbContext.CollectionUsers
|
join cu in dbContext.CollectionUsers
|
||||||
on c.Id equals cu.CollectionId into cu_g
|
on new { ou.AccessAll, CollectionId = c.Id, OrganizationUserId = ou.Id } equals
|
||||||
|
new { AccessAll = false, cu.CollectionId, cu.OrganizationUserId } into cu_g
|
||||||
from cu in cu_g.DefaultIfEmpty()
|
from cu in cu_g.DefaultIfEmpty()
|
||||||
where !ou.AccessAll && cu.OrganizationUserId == ou.Id
|
|
||||||
join gu in dbContext.GroupUsers
|
join gu in dbContext.GroupUsers
|
||||||
on ou.Id equals gu.OrganizationUserId into gu_g
|
on new { CollectionId = (Guid?)cu.CollectionId, ou.AccessAll, OrganizationUserId = ou.Id } equals
|
||||||
|
new { CollectionId = (Guid?)null, AccessAll = false, gu.OrganizationUserId } into gu_g
|
||||||
from gu in gu_g.DefaultIfEmpty()
|
from gu in gu_g.DefaultIfEmpty()
|
||||||
where cu.CollectionId == null && !ou.AccessAll
|
|
||||||
join g in dbContext.Groups
|
join g in dbContext.Groups
|
||||||
on gu.GroupId equals g.Id into g_g
|
on gu.GroupId equals g.Id into g_g
|
||||||
from g in g_g.DefaultIfEmpty()
|
from g in g_g.DefaultIfEmpty()
|
||||||
|
|
||||||
join cg in dbContext.CollectionGroups
|
join cg in dbContext.CollectionGroups
|
||||||
on c.Id equals cg.CollectionId into cg_g
|
on new { g.AccessAll, CollectionId = c.Id, gu.GroupId } equals
|
||||||
|
new { AccessAll = false, cg.CollectionId, cg.GroupId } into cg_g
|
||||||
from cg in cg_g.DefaultIfEmpty()
|
from cg in cg_g.DefaultIfEmpty()
|
||||||
where !g.AccessAll && gu.GroupId == cg.GroupId &&
|
|
||||||
o.Id == _cipher.OrganizationId &&
|
where o.Id == _cipher.OrganizationId &&
|
||||||
o.Enabled &&
|
o.Enabled &&
|
||||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||||
(ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly)
|
(ou.AccessAll || !cu.ReadOnly || g.AccessAll || !cg.ReadOnly)
|
||||||
|
@ -16,29 +16,33 @@ public class UserBumpAccountRevisionDateByCipherIdQuery : IQuery<User>
|
|||||||
public IQueryable<User> Run(DatabaseContext dbContext)
|
public IQueryable<User> Run(DatabaseContext dbContext)
|
||||||
{
|
{
|
||||||
var query = from u in dbContext.Users
|
var query = from u in dbContext.Users
|
||||||
|
|
||||||
join ou in dbContext.OrganizationUsers
|
join ou in dbContext.OrganizationUsers
|
||||||
on u.Id equals ou.UserId
|
on u.Id equals ou.UserId
|
||||||
|
|
||||||
join collectionCipher in dbContext.CollectionCiphers
|
join collectionCipher in dbContext.CollectionCiphers
|
||||||
on _cipher.Id equals collectionCipher.CipherId into cc_g
|
on _cipher.Id equals collectionCipher.CipherId into cc_g
|
||||||
from cc in cc_g.DefaultIfEmpty()
|
from cc in cc_g.DefaultIfEmpty()
|
||||||
|
|
||||||
join collectionUser in dbContext.CollectionUsers
|
join collectionUser in dbContext.CollectionUsers
|
||||||
on cc.CollectionId equals collectionUser.CollectionId into cu_g
|
on new { ou.AccessAll, OrganizationUserId = ou.Id, cc.CollectionId } equals
|
||||||
|
new { AccessAll = false, collectionUser.OrganizationUserId, collectionUser.CollectionId } into cu_g
|
||||||
from cu in cu_g.DefaultIfEmpty()
|
from cu in cu_g.DefaultIfEmpty()
|
||||||
where ou.AccessAll &&
|
|
||||||
cu.OrganizationUserId == ou.Id
|
|
||||||
join groupUser in dbContext.GroupUsers
|
join groupUser in dbContext.GroupUsers
|
||||||
on ou.Id equals groupUser.OrganizationUserId into gu_g
|
on new { CollectionId = (Guid?)cu.CollectionId, ou.AccessAll, OrganizationUserId = ou.Id } equals
|
||||||
|
new { CollectionId = (Guid?)null, AccessAll = false, groupUser.OrganizationUserId } into gu_g
|
||||||
from gu in gu_g.DefaultIfEmpty()
|
from gu in gu_g.DefaultIfEmpty()
|
||||||
where cu.CollectionId == null &&
|
|
||||||
!ou.AccessAll
|
|
||||||
join grp in dbContext.Groups
|
join grp in dbContext.Groups
|
||||||
on gu.GroupId equals grp.Id into g_g
|
on gu.GroupId equals grp.Id into g_g
|
||||||
from g in g_g.DefaultIfEmpty()
|
from g in g_g.DefaultIfEmpty()
|
||||||
|
|
||||||
join collectionGroup in dbContext.CollectionGroups
|
join collectionGroup in dbContext.CollectionGroups
|
||||||
on cc.CollectionId equals collectionGroup.CollectionId into cg_g
|
on new { g.AccessAll, gu.GroupId, cc.CollectionId } equals
|
||||||
|
new { AccessAll = false, collectionGroup.GroupId, collectionGroup.CollectionId } into cg_g
|
||||||
from cg in cg_g.DefaultIfEmpty()
|
from cg in cg_g.DefaultIfEmpty()
|
||||||
where !g.AccessAll &&
|
|
||||||
cg.GroupId == gu.GroupId
|
|
||||||
where ou.OrganizationId == _cipher.OrganizationId &&
|
where ou.OrganizationId == _cipher.OrganizationId &&
|
||||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||||
(cu.CollectionId != null ||
|
(cu.CollectionId != null ||
|
||||||
|
Loading…
Reference in New Issue
Block a user