mirror of
https://github.com/bitwarden/server.git
synced 2025-04-06 05:28:15 -05:00
AccountRevDate bump via sprocs, no more triggers
This commit is contained in:
parent
f2aa568e86
commit
6e87d9c21f
@ -176,5 +176,8 @@
|
||||
<Build Include="dbo\Stored Procedures\Cipher_ReadByOrganizationId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\SubvaultCipher_ReadByOrganizationId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\SubvaultCipher_UpdateSubvaultsAdmin.sql" />
|
||||
<Build Include="dbo\Stored Procedures\User_BumpAccountRevisionDate.sql" />
|
||||
<Build Include="dbo\Stored Procedures\User_BumpAccountRevisionDateByOrganizationId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\User_BumpAccountRevisionDateByOrganizationUserId.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -41,4 +41,13 @@ BEGIN
|
||||
@CreationDate,
|
||||
@RevisionDate
|
||||
)
|
||||
|
||||
IF @OrganizationId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
ELSE IF @UserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
||||
END
|
@ -46,4 +46,13 @@ BEGIN
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
IF @OrganizationId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
ELSE IF @UserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
||||
END
|
@ -36,4 +36,13 @@ BEGIN
|
||||
@CreationDate,
|
||||
@RevisionDate
|
||||
)
|
||||
|
||||
IF @OrganizationId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
ELSE IF @UserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
||||
END
|
@ -4,9 +4,29 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @UserId UNIQUEIDENTIFIER
|
||||
DECLARE @OrganizationId UNIQUEIDENTIFIER
|
||||
|
||||
SELECT TOP 1
|
||||
@UserId = [UserId],
|
||||
@OrganizationId = [OrganizationId]
|
||||
FROM
|
||||
[dbo].[Cipher]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[Cipher]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
IF @OrganizationId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
ELSE IF @UserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
||||
END
|
||||
|
@ -25,4 +25,13 @@ BEGIN
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
IF @OrganizationId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
ELSE IF @UserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
||||
END
|
@ -33,4 +33,9 @@ BEGIN
|
||||
END
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
IF @UserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
||||
END
|
@ -53,4 +53,13 @@ BEGIN
|
||||
@SubvaultIds
|
||||
WHERE
|
||||
[Id] IN (SELECT [Id] FROM [AvailableSubvaultsCTE])
|
||||
|
||||
IF @OrganizationId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
ELSE IF @UserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
||||
END
|
@ -24,4 +24,6 @@ BEGIN
|
||||
@CreationDate,
|
||||
@RevisionDate
|
||||
)
|
||||
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
@ -4,9 +4,13 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM [dbo].[Folder] WHERE [Id] = @Id)
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[Folder]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
@ -17,4 +17,6 @@ BEGIN
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
@ -15,4 +15,10 @@ BEGIN
|
||||
@SubvaultId,
|
||||
@CipherId
|
||||
)
|
||||
|
||||
DECLARE @OrganizationId UNIQUEIDENTIFIER = (SELECT TOP 1 [OrganizationId] FROM [dbo].[Cipher] WHERE [Id] = @CipherId)
|
||||
IF @OrganizationId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
END
|
@ -11,4 +11,10 @@ BEGIN
|
||||
WHERE
|
||||
[SubvaultId] = @SubvaultId
|
||||
AND [CipherId] = @CipherId
|
||||
|
||||
DECLARE @OrganizationId UNIQUEIDENTIFIER = (SELECT TOP 1 [OrganizationId] FROM [dbo].[Cipher] WHERE [Id] = @CipherId)
|
||||
IF @OrganizationId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
END
|
@ -51,4 +51,9 @@ BEGIN
|
||||
AND [Target].[SubvaultId] IN (SELECT [Id] FROM [AvailableSubvaultsCTE]) THEN
|
||||
DELETE
|
||||
;
|
||||
|
||||
IF @OrgId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrgId
|
||||
END
|
||||
END
|
@ -32,4 +32,9 @@ BEGIN
|
||||
AND [Target].[CipherId] = @CipherId THEN
|
||||
DELETE
|
||||
;
|
||||
|
||||
IF @OrganizationId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
END
|
@ -27,4 +27,9 @@ BEGIN
|
||||
@CreationDate,
|
||||
@RevisionDate
|
||||
)
|
||||
|
||||
IF @OrganizationUserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @OrganizationUserId
|
||||
END
|
||||
END
|
@ -4,9 +4,16 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @OrganizationUserId UNIQUEIDENTIFIER = (SELECT TOP 1 [OrganizationUserId] FROM [dbo].[SubvaultUser] WHERE [Id] = @Id)
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[SubvaultUser]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
IF @OrganizationUserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @OrganizationUserId
|
||||
END
|
||||
END
|
@ -19,4 +19,9 @@ BEGIN
|
||||
[RevisionDate] = @RevisionDate
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
IF @OrganizationUserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @OrganizationUserId
|
||||
END
|
||||
END
|
@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[User_BumpAccountRevisionDate]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE
|
||||
[User]
|
||||
SET
|
||||
[AccountRevisionDate] = GETUTCDATE()
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
@ -0,0 +1,18 @@
|
||||
CREATE PROCEDURE [dbo].[User_BumpAccountRevisionDateByOrganizationId]
|
||||
@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]
|
||||
WHERE
|
||||
OU.[OrganizationId] = @OrganizationId
|
||||
AND OU.[Status] = 2 -- Confirmed
|
||||
END
|
@ -0,0 +1,18 @@
|
||||
CREATE PROCEDURE [dbo].[User_BumpAccountRevisionDateByOrganizationUserId]
|
||||
@OrganizationUserId 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]
|
||||
WHERE
|
||||
OU.[Id] = @OrganizationUserId
|
||||
AND OU.[Status] = 2 -- Confirmed
|
||||
END
|
@ -21,63 +21,4 @@ CREATE NONCLUSTERED INDEX [IX_Cipher_UserId_Type]
|
||||
GO
|
||||
CREATE NONCLUSTERED INDEX [IX_Cipher_OrganizationId_Type]
|
||||
ON [dbo].[Cipher]([OrganizationId] ASC, [Type] ASC)
|
||||
WHERE [OrganizationId] IS NOT NULL;
|
||||
|
||||
|
||||
GO
|
||||
CREATE TRIGGER [dbo].[Cipher_Inserted]
|
||||
ON [dbo].[Cipher] AFTER INSERT
|
||||
AS
|
||||
BEGIN
|
||||
DECLARE @Count INT = (SELECT COUNT(1) FROM INSERTED)
|
||||
IF @Count = 0 RETURN
|
||||
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM INSERTED)
|
||||
|
||||
UPDATE
|
||||
[User]
|
||||
SET
|
||||
[AccountRevisionDate] = GETUTCDATE()
|
||||
WHERE
|
||||
[Id] = @UserId
|
||||
END
|
||||
GO
|
||||
CREATE TRIGGER [dbo].[Cipher_Updated]
|
||||
ON [dbo].[Cipher] AFTER UPDATE
|
||||
AS
|
||||
BEGIN
|
||||
DECLARE @Count INT = (SELECT COUNT(1) FROM INSERTED)
|
||||
IF @Count = 0 RETURN
|
||||
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM INSERTED)
|
||||
|
||||
UPDATE
|
||||
[User]
|
||||
SET
|
||||
[AccountRevisionDate] = GETUTCDATE()
|
||||
WHERE
|
||||
[Id] = @UserId
|
||||
END
|
||||
GO
|
||||
CREATE TRIGGER [dbo].[Cipher_Deleted]
|
||||
ON [dbo].[Cipher] AFTER DELETE
|
||||
AS
|
||||
BEGIN
|
||||
DECLARE @Count INT = (SELECT COUNT(1) FROM DELETED)
|
||||
IF @Count = 0 RETURN
|
||||
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @UserId UNIQUEIDENTIFIER = (SELECT TOP 1 [UserId] FROM DELETED)
|
||||
|
||||
UPDATE
|
||||
[User]
|
||||
SET
|
||||
[AccountRevisionDate] = GETUTCDATE()
|
||||
WHERE
|
||||
[Id] = @UserId
|
||||
END
|
||||
WHERE [OrganizationId] IS NOT NULL;
|
Loading…
x
Reference in New Issue
Block a user