1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-13 20:21:22 +01:00

sproc updates for user account revision bumps

This commit is contained in:
Kyle Spearrin 2017-11-24 11:53:55 -05:00
parent 49372bed38
commit 2f3c6b3b01
26 changed files with 1338 additions and 14 deletions

View File

@ -214,5 +214,7 @@
<Build Include="dbo\Stored Procedures\User_ReadByPremium.sql" /> <Build Include="dbo\Stored Procedures\User_ReadByPremium.sql" />
<Build Include="dbo\Stored Procedures\CipherDetails_ReadById.sql" /> <Build Include="dbo\Stored Procedures\CipherDetails_ReadById.sql" />
<Build Include="dbo\Stored Procedures\Cipher_DeleteByUserId.sql" /> <Build Include="dbo\Stored Procedures\Cipher_DeleteByUserId.sql" />
<Build Include="dbo\Stored Procedures\User_BumpAccountRevisionDateByCollectionId.sql" />
<Build Include="dbo\Stored Procedures\User_BumpAccountRevisionDateByCipherId.sql" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -47,7 +47,7 @@ BEGIN
IF @OrganizationId IS NOT NULL IF @OrganizationId IS NOT NULL
BEGIN BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
END END
ELSE IF @UserId IS NOT NULL ELSE IF @UserId IS NOT NULL
BEGIN BEGIN

View File

@ -52,7 +52,7 @@ BEGIN
IF @OrganizationId IS NOT NULL IF @OrganizationId IS NOT NULL
BEGIN BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
END END
ELSE IF @UserId IS NOT NULL ELSE IF @UserId IS NOT NULL
BEGIN BEGIN

View File

@ -42,7 +42,7 @@ BEGIN
IF @OrganizationId IS NOT NULL IF @OrganizationId IS NOT NULL
BEGIN BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
END END
ELSE IF @UserId IS NOT NULL ELSE IF @UserId IS NOT NULL
BEGIN BEGIN

View File

@ -28,7 +28,7 @@ BEGIN
IF @OrganizationId IS NOT NULL IF @OrganizationId IS NOT NULL
BEGIN BEGIN
EXEC [dbo].[Organization_UpdateStorage] @OrganizationId EXEC [dbo].[Organization_UpdateStorage] @OrganizationId
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
END END
ELSE IF @UserId IS NOT NULL ELSE IF @UserId IS NOT NULL
BEGIN BEGIN

View File

@ -30,7 +30,7 @@ BEGIN
BEGIN BEGIN
EXEC [dbo].[Organization_UpdateStorage] @OrganizationId EXEC [dbo].[Organization_UpdateStorage] @OrganizationId
END END
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
END END
ELSE IF @UserId IS NOT NULL ELSE IF @UserId IS NOT NULL
BEGIN BEGIN

View File

@ -34,5 +34,4 @@ BEGIN
[Id] IN (SELECT * FROM [IdsToMoveCTE]) [Id] IN (SELECT * FROM [IdsToMoveCTE])
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
-- TODO: What if some that were updated were organization ciphers? Then bump by org ids.
END END

View File

@ -30,7 +30,7 @@ BEGIN
IF @OrganizationId IS NOT NULL IF @OrganizationId IS NOT NULL
BEGIN BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
END END
ELSE IF @UserId IS NOT NULL ELSE IF @UserId IS NOT NULL
BEGIN BEGIN

View File

@ -27,7 +27,7 @@ BEGIN
IF @OrganizationId IS NOT NULL IF @OrganizationId IS NOT NULL
BEGIN BEGIN
EXEC [dbo].[Organization_UpdateStorage] @OrganizationId EXEC [dbo].[Organization_UpdateStorage] @OrganizationId
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
END END
ELSE IF @UserId IS NOT NULL ELSE IF @UserId IS NOT NULL
BEGIN BEGIN

View File

@ -84,7 +84,7 @@ BEGIN
EXEC [dbo].[User_UpdateStorage] @UserId EXEC [dbo].[User_UpdateStorage] @UserId
END END
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId
SELECT 0 -- 0 = Success SELECT 0 -- 0 = Success
END END

View File

@ -19,6 +19,6 @@ BEGIN
DECLARE @OrganizationId UNIQUEIDENTIFIER = (SELECT TOP 1 [OrganizationId] FROM [dbo].[Cipher] WHERE [Id] = @CipherId) DECLARE @OrganizationId UNIQUEIDENTIFIER = (SELECT TOP 1 [OrganizationId] FROM [dbo].[Cipher] WHERE [Id] = @CipherId)
IF @OrganizationId IS NOT NULL IF @OrganizationId IS NOT NULL
BEGIN BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @CollectionId, @OrganizationId
END END
END END

View File

@ -15,6 +15,6 @@ BEGIN
DECLARE @OrganizationId UNIQUEIDENTIFIER = (SELECT TOP 1 [OrganizationId] FROM [dbo].[Cipher] WHERE [Id] = @CipherId) DECLARE @OrganizationId UNIQUEIDENTIFIER = (SELECT TOP 1 [OrganizationId] FROM [dbo].[Cipher] WHERE [Id] = @CipherId)
IF @OrganizationId IS NOT NULL IF @OrganizationId IS NOT NULL
BEGIN BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @CollectionId, @OrganizationId
END END
END END

View File

@ -24,4 +24,6 @@ BEGIN
@CreationDate, @CreationDate,
@RevisionDate @RevisionDate
) )
EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @Id, @OrganizationId
END END

View File

@ -33,4 +33,6 @@ BEGIN
@Groups @Groups
WHERE WHERE
[Id] IN (SELECT [Id] FROM [AvailableGroupsCTE]) [Id] IN (SELECT [Id] FROM [AvailableGroupsCTE])
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
END END

View File

@ -4,6 +4,12 @@ AS
BEGIN BEGIN
SET NOCOUNT ON SET NOCOUNT ON
DECLARE @OrganizationId UNIQUEIDENTIFIER = (SELECT TOP 1 [OrganizationId] FROM [dbo].[Collection] WHERE [Id] = @Id)
IF @OrganizationId IS NOT NULL
BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @Id, @OrganizationId
END
DELETE DELETE
FROM FROM
[dbo].[CollectionGroup] [dbo].[CollectionGroup]

View File

@ -17,4 +17,6 @@ BEGIN
[RevisionDate] = @RevisionDate [RevisionDate] = @RevisionDate
WHERE WHERE
[Id] = @Id [Id] = @Id
EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @Id, @OrganizationId
END END

View File

@ -41,5 +41,5 @@ BEGIN
DELETE DELETE
; ;
-- TODO: Update user revision date times that this affects EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @Id, @OrganizationId
END END

View File

@ -42,5 +42,5 @@ BEGIN
DELETE DELETE
; ;
-- TODO: Bump account revision date for all @OrganizationUserIds EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrgId
END END

View File

@ -35,4 +35,6 @@ BEGIN
@Collections @Collections
WHERE WHERE
[Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE]) [Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE])
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
END END

View File

@ -4,6 +4,12 @@ AS
BEGIN BEGIN
SET NOCOUNT ON SET NOCOUNT ON
DECLARE @OrganizationId UNIQUEIDENTIFIER = (SELECT TOP 1 [OrganizationId] FROM [dbo].[Group] WHERE [Id] = @Id)
IF @OrganizationId IS NOT NULL
BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
END
DELETE DELETE
FROM FROM
[dbo].[Group] [dbo].[Group]

View File

@ -43,5 +43,5 @@ BEGIN
DELETE DELETE
; ;
-- TODO: Update user revision date times that this affects EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
END END

View File

@ -3,6 +3,8 @@
AS AS
BEGIN BEGIN
SET NOCOUNT ON SET NOCOUNT ON
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @Id
DELETE DELETE
FROM FROM

View File

@ -0,0 +1,39 @@
CREATE PROCEDURE [dbo].[User_BumpAccountRevisionDateByCipherId]
@CipherId UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
UPDATE
U
SET
U.[AccountRevisionDate] = GETUTCDATE()
FROM
[dbo].[User] U
LEFT JOIN
[dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id]
LEFT JOIN
[dbo].[CollectionCipher] CC ON CC.[CipherId] = @CipherId
LEFT JOIN
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = CC.[CollectionId]
LEFT JOIN
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id]
LEFT JOIN
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
LEFT JOIN
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = CC.[CollectionId]
WHERE
OU.[Status] = 2 -- 2 = Confirmed
AND (
CU.[CollectionId] IS NOT NULL
OR CG.[CollectionId] IS NOT NULL
OR (
OU.[OrganizationId] = @OrganizationId
AND (
OU.[AccessAll] = 1
OR G.[AccessAll] = 1
)
)
)
END

View File

@ -0,0 +1,37 @@
CREATE PROCEDURE [dbo].[User_BumpAccountRevisionDateByCollectionId]
@CollectionId UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
UPDATE
U
SET
U.[AccountRevisionDate] = GETUTCDATE()
FROM
[dbo].[User] U
LEFT JOIN
[dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id]
LEFT JOIN
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId
LEFT JOIN
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id]
LEFT JOIN
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
LEFT JOIN
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId
WHERE
OU.[Status] = 2 -- 2 = Confirmed
AND (
CU.[CollectionId] IS NOT NULL
OR CG.[CollectionId] IS NOT NULL
OR (
OU.[OrganizationId] = @OrganizationId
AND (
OU.[AccessAll] = 1
OR G.[AccessAll] = 1
)
)
)
END

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="DbScripts\2017-11-24_00_UpdateProcs.sql" />
<EmbeddedResource Include="DbScripts\2017-11-13_00_IndexTuning.sql" /> <EmbeddedResource Include="DbScripts\2017-11-13_00_IndexTuning.sql" />
<EmbeddedResource Include="DbScripts\2017-11-06_00_FamilyPlanAdjustments.sql" /> <EmbeddedResource Include="DbScripts\2017-11-06_00_FamilyPlanAdjustments.sql" />
<EmbeddedResource Include="DbScripts\2017-10-25_00_OrgUserUpdates.sql" /> <EmbeddedResource Include="DbScripts\2017-10-25_00_OrgUserUpdates.sql" />