mirror of
https://github.com/bitwarden/server.git
synced 2024-11-28 13:15:12 +01:00
[AC-2732] Remove AccessAll - Bump account revision date sprocs (#4490)
* Remove AccessAll logic from bump account revision date sprocs and corresponding EF methods
This commit is contained in:
parent
4ab608a636
commit
8f70dd98ba
@ -48,26 +48,24 @@ public static class DatabaseContextExtensions
|
|||||||
join ou in context.OrganizationUsers
|
join ou in context.OrganizationUsers
|
||||||
on u.Id equals ou.UserId
|
on u.Id equals ou.UserId
|
||||||
join cu in context.CollectionUsers
|
join cu in context.CollectionUsers
|
||||||
on new { ou.AccessAll, OrganizationUserId = ou.Id, CollectionId = collectionId } equals
|
on new { OrganizationUserId = ou.Id, CollectionId = collectionId } equals
|
||||||
new { AccessAll = false, cu.OrganizationUserId, cu.CollectionId } into cu_g
|
new { cu.OrganizationUserId, cu.CollectionId } into cu_g
|
||||||
from cu in cu_g.DefaultIfEmpty()
|
from cu in cu_g.DefaultIfEmpty()
|
||||||
join gu in context.GroupUsers
|
join gu in context.GroupUsers
|
||||||
on new { CollectionId = (Guid?)cu.CollectionId, ou.AccessAll, OrganizationUserId = ou.Id } equals
|
on new { CollectionId = (Guid?)cu.CollectionId, OrganizationUserId = ou.Id } equals
|
||||||
new { CollectionId = (Guid?)null, AccessAll = false, gu.OrganizationUserId } into gu_g
|
new { CollectionId = (Guid?)null, gu.OrganizationUserId } into gu_g
|
||||||
from gu in gu_g.DefaultIfEmpty()
|
from gu in gu_g.DefaultIfEmpty()
|
||||||
join g in context.Groups
|
join g in context.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 context.CollectionGroups
|
join cg in context.CollectionGroups
|
||||||
on new { g.AccessAll, gu.GroupId, CollectionId = collectionId } equals
|
on new { gu.GroupId, CollectionId = collectionId } equals
|
||||||
new { AccessAll = false, cg.GroupId, cg.CollectionId } into cg_g
|
new { cg.GroupId, cg.CollectionId } into cg_g
|
||||||
from cg in cg_g.DefaultIfEmpty()
|
from cg in cg_g.DefaultIfEmpty()
|
||||||
where ou.OrganizationId == organizationId &&
|
where ou.OrganizationId == organizationId &&
|
||||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||||
(cu.CollectionId != null ||
|
(cu.CollectionId != null ||
|
||||||
cg.CollectionId != null ||
|
cg.CollectionId != null)
|
||||||
ou.AccessAll == true ||
|
|
||||||
g.AccessAll == true)
|
|
||||||
select u;
|
select u;
|
||||||
|
|
||||||
var users = await query.ToListAsync();
|
var users = await query.ToListAsync();
|
||||||
@ -81,26 +79,24 @@ public static class DatabaseContextExtensions
|
|||||||
join ou in context.OrganizationUsers
|
join ou in context.OrganizationUsers
|
||||||
on u.Id equals ou.UserId
|
on u.Id equals ou.UserId
|
||||||
join cu in context.CollectionUsers
|
join cu in context.CollectionUsers
|
||||||
on new { ou.AccessAll, OrganizationUserId = ou.Id, CollectionId = c.Id } equals
|
on new { OrganizationUserId = ou.Id, CollectionId = c.Id } equals
|
||||||
new { AccessAll = false, cu.OrganizationUserId, cu.CollectionId } into cu_g
|
new { cu.OrganizationUserId, cu.CollectionId } into cu_g
|
||||||
from cu in cu_g.DefaultIfEmpty()
|
from cu in cu_g.DefaultIfEmpty()
|
||||||
join gu in context.GroupUsers
|
join gu in context.GroupUsers
|
||||||
on new { CollectionId = (Guid?)cu.CollectionId, ou.AccessAll, OrganizationUserId = ou.Id } equals
|
on new { CollectionId = (Guid?)cu.CollectionId, OrganizationUserId = ou.Id } equals
|
||||||
new { CollectionId = (Guid?)null, AccessAll = false, gu.OrganizationUserId } into gu_g
|
new { CollectionId = (Guid?)null, gu.OrganizationUserId } into gu_g
|
||||||
from gu in gu_g.DefaultIfEmpty()
|
from gu in gu_g.DefaultIfEmpty()
|
||||||
join g in context.Groups
|
join g in context.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 context.CollectionGroups
|
join cg in context.CollectionGroups
|
||||||
on new { g.AccessAll, gu.GroupId, CollectionId = c.Id } equals
|
on new { gu.GroupId, CollectionId = c.Id } equals
|
||||||
new { AccessAll = false, cg.GroupId, cg.CollectionId } into cg_g
|
new { cg.GroupId, cg.CollectionId } into cg_g
|
||||||
from cg in cg_g.DefaultIfEmpty()
|
from cg in cg_g.DefaultIfEmpty()
|
||||||
where ou.OrganizationId == organizationId && collectionIds.Contains(c.Id) &&
|
where ou.OrganizationId == organizationId && collectionIds.Contains(c.Id) &&
|
||||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||||
(cu.CollectionId != null ||
|
(cu.CollectionId != null ||
|
||||||
cg.CollectionId != null ||
|
cg.CollectionId != null)
|
||||||
ou.AccessAll == true ||
|
|
||||||
g.AccessAll == true)
|
|
||||||
select u;
|
select u;
|
||||||
|
|
||||||
var users = await query.ToListAsync();
|
var users = await query.ToListAsync();
|
||||||
|
@ -26,13 +26,13 @@ public class UserBumpAccountRevisionDateByCipherIdQuery : IQuery<User>
|
|||||||
from cc in cc_g.DefaultIfEmpty()
|
from cc in cc_g.DefaultIfEmpty()
|
||||||
|
|
||||||
join collectionUser in dbContext.CollectionUsers
|
join collectionUser in dbContext.CollectionUsers
|
||||||
on new { ou.AccessAll, OrganizationUserId = ou.Id, cc.CollectionId } equals
|
on new { OrganizationUserId = ou.Id, cc.CollectionId } equals
|
||||||
new { AccessAll = false, collectionUser.OrganizationUserId, collectionUser.CollectionId } into cu_g
|
new { collectionUser.OrganizationUserId, collectionUser.CollectionId } into cu_g
|
||||||
from cu in cu_g.DefaultIfEmpty()
|
from cu in cu_g.DefaultIfEmpty()
|
||||||
|
|
||||||
join groupUser in dbContext.GroupUsers
|
join groupUser in dbContext.GroupUsers
|
||||||
on new { CollectionId = (Guid?)cu.CollectionId, ou.AccessAll, OrganizationUserId = ou.Id } equals
|
on new { CollectionId = (Guid?)cu.CollectionId, OrganizationUserId = ou.Id } equals
|
||||||
new { CollectionId = (Guid?)null, AccessAll = false, groupUser.OrganizationUserId } into gu_g
|
new { CollectionId = (Guid?)null, groupUser.OrganizationUserId } into gu_g
|
||||||
from gu in gu_g.DefaultIfEmpty()
|
from gu in gu_g.DefaultIfEmpty()
|
||||||
|
|
||||||
join grp in dbContext.Groups
|
join grp in dbContext.Groups
|
||||||
@ -40,16 +40,14 @@ public class UserBumpAccountRevisionDateByCipherIdQuery : IQuery<User>
|
|||||||
from g in g_g.DefaultIfEmpty()
|
from g in g_g.DefaultIfEmpty()
|
||||||
|
|
||||||
join collectionGroup in dbContext.CollectionGroups
|
join collectionGroup in dbContext.CollectionGroups
|
||||||
on new { g.AccessAll, gu.GroupId, cc.CollectionId } equals
|
on new { gu.GroupId, cc.CollectionId } equals
|
||||||
new { AccessAll = false, collectionGroup.GroupId, collectionGroup.CollectionId } into cg_g
|
new { collectionGroup.GroupId, collectionGroup.CollectionId } into cg_g
|
||||||
from cg in cg_g.DefaultIfEmpty()
|
from cg in cg_g.DefaultIfEmpty()
|
||||||
|
|
||||||
where ou.OrganizationId == _organizationId &&
|
where ou.OrganizationId == _organizationId &&
|
||||||
ou.Status == OrganizationUserStatusType.Confirmed &&
|
ou.Status == OrganizationUserStatusType.Confirmed &&
|
||||||
(cu.CollectionId != null ||
|
(cu.CollectionId != null ||
|
||||||
cg.CollectionId != null ||
|
cg.CollectionId != null)
|
||||||
ou.AccessAll ||
|
|
||||||
g.AccessAll)
|
|
||||||
select u;
|
select u;
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -16,20 +16,18 @@ BEGIN
|
|||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[CollectionCipher] CC ON CC.[CipherId] = @CipherId
|
[dbo].[CollectionCipher] CC ON CC.[CipherId] = @CipherId
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = CC.[CollectionId]
|
[dbo].[CollectionUser] CU ON CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = CC.[CollectionId]
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id]
|
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND GU.[OrganizationUserId] = OU.[Id]
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = CC.[CollectionId]
|
[dbo].[CollectionGroup] CG ON CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = CC.[CollectionId]
|
||||||
WHERE
|
WHERE
|
||||||
OU.[OrganizationId] = @OrganizationId
|
OU.[OrganizationId] = @OrganizationId
|
||||||
AND OU.[Status] = 2 -- 2 = Confirmed
|
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||||
AND (
|
AND (
|
||||||
CU.[CollectionId] IS NOT NULL
|
CU.[CollectionId] IS NOT NULL
|
||||||
OR CG.[CollectionId] IS NOT NULL
|
OR CG.[CollectionId] IS NOT NULL
|
||||||
OR OU.[AccessAll] = 1
|
|
||||||
OR G.[AccessAll] = 1
|
|
||||||
)
|
)
|
||||||
END
|
END
|
||||||
|
@ -14,20 +14,18 @@ BEGIN
|
|||||||
INNER JOIN
|
INNER JOIN
|
||||||
[dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id]
|
[dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id]
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId
|
[dbo].[CollectionUser] CU ON CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id]
|
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND GU.[OrganizationUserId] = OU.[Id]
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId
|
[dbo].[CollectionGroup] CG ON CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId
|
||||||
WHERE
|
WHERE
|
||||||
OU.[OrganizationId] = @OrganizationId
|
OU.[OrganizationId] = @OrganizationId
|
||||||
AND OU.[Status] = 2 -- 2 = Confirmed
|
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||||
AND (
|
AND (
|
||||||
CU.[CollectionId] IS NOT NULL
|
CU.[CollectionId] IS NOT NULL
|
||||||
OR CG.[CollectionId] IS NOT NULL
|
OR CG.[CollectionId] IS NOT NULL
|
||||||
OR OU.[AccessAll] = 1
|
|
||||||
OR G.[AccessAll] = 1
|
|
||||||
)
|
)
|
||||||
END
|
END
|
||||||
|
@ -16,20 +16,18 @@ SET
|
|||||||
INNER JOIN
|
INNER JOIN
|
||||||
[dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id]
|
[dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id]
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = C.[Id]
|
[dbo].[CollectionUser] CU ON CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = C.[Id]
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id]
|
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND GU.[OrganizationUserId] = OU.[Id]
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = C.[Id]
|
[dbo].[CollectionGroup] CG ON CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = C.[Id]
|
||||||
WHERE
|
WHERE
|
||||||
OU.[OrganizationId] = @OrganizationId
|
OU.[OrganizationId] = @OrganizationId
|
||||||
AND OU.[Status] = 2 -- 2 = Confirmed
|
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||||
AND (
|
AND (
|
||||||
CU.[CollectionId] IS NOT NULL
|
CU.[CollectionId] IS NOT NULL
|
||||||
OR CG.[CollectionId] IS NOT NULL
|
OR CG.[CollectionId] IS NOT NULL
|
||||||
OR OU.[AccessAll] = 1
|
|
||||||
OR G.[AccessAll] = 1
|
|
||||||
)
|
)
|
||||||
END
|
END
|
||||||
|
@ -0,0 +1,107 @@
|
|||||||
|
-- Remove AccessAll logic from bump account revision date sprocs
|
||||||
|
|
||||||
|
-- User_BumpAccountRevisionDateByCipherId
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[User_BumpAccountRevisionDateByCipherId]
|
||||||
|
@CipherId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
U
|
||||||
|
SET
|
||||||
|
U.[AccountRevisionDate] = GETUTCDATE()
|
||||||
|
FROM
|
||||||
|
[dbo].[User] U
|
||||||
|
INNER JOIN
|
||||||
|
[dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id]
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[CollectionCipher] CC ON CC.[CipherId] = @CipherId
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[CollectionUser] CU ON CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = CC.[CollectionId]
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND GU.[OrganizationUserId] = OU.[Id]
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[CollectionGroup] CG ON CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = CC.[CollectionId]
|
||||||
|
WHERE
|
||||||
|
OU.[OrganizationId] = @OrganizationId
|
||||||
|
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||||
|
AND (
|
||||||
|
CU.[CollectionId] IS NOT NULL
|
||||||
|
OR CG.[CollectionId] IS NOT NULL
|
||||||
|
)
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- User_BumpAccountRevisionDateByCollectionId
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[User_BumpAccountRevisionDateByCollectionId]
|
||||||
|
@CollectionId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
U
|
||||||
|
SET
|
||||||
|
U.[AccountRevisionDate] = GETUTCDATE()
|
||||||
|
FROM
|
||||||
|
[dbo].[User] U
|
||||||
|
INNER JOIN
|
||||||
|
[dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id]
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[CollectionUser] CU ON CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND GU.[OrganizationUserId] = OU.[Id]
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[CollectionGroup] CG ON CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId
|
||||||
|
WHERE
|
||||||
|
OU.[OrganizationId] = @OrganizationId
|
||||||
|
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||||
|
AND (
|
||||||
|
CU.[CollectionId] IS NOT NULL
|
||||||
|
OR CG.[CollectionId] IS NOT NULL
|
||||||
|
)
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- User_BumpAccountRevisionDateByCollectionIds
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[User_BumpAccountRevisionDateByCollectionIds]
|
||||||
|
@CollectionIds AS [dbo].[GuidIdArray] READONLY,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
UPDATE
|
||||||
|
U
|
||||||
|
SET
|
||||||
|
U.[AccountRevisionDate] = GETUTCDATE()
|
||||||
|
FROM
|
||||||
|
[dbo].[User] U
|
||||||
|
INNER JOIN
|
||||||
|
[dbo].[Collection] C ON C.[Id] IN (SELECT [Id] FROM @CollectionIds)
|
||||||
|
INNER JOIN
|
||||||
|
[dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id]
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[CollectionUser] CU ON CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = C.[Id]
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND GU.[OrganizationUserId] = OU.[Id]
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
||||||
|
LEFT JOIN
|
||||||
|
[dbo].[CollectionGroup] CG ON CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = C.[Id]
|
||||||
|
WHERE
|
||||||
|
OU.[OrganizationId] = @OrganizationId
|
||||||
|
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||||
|
AND (
|
||||||
|
CU.[CollectionId] IS NOT NULL
|
||||||
|
OR CG.[CollectionId] IS NOT NULL
|
||||||
|
)
|
||||||
|
END
|
||||||
|
GO
|
Loading…
Reference in New Issue
Block a user