mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 16:42:50 -05:00
delete attachments
This commit is contained in:
@ -203,5 +203,6 @@
|
||||
<Build Include="dbo\Stored Procedures\Cipher_UpdateAttachment.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Organization_UpdateStorage.sql" />
|
||||
<Build Include="dbo\Stored Procedures\User_UpdateStorage.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Cipher_DeleteAttachment.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
43
src/Sql/dbo/Stored Procedures/Cipher_DeleteAttachment.sql
Normal file
43
src/Sql/dbo/Stored Procedures/Cipher_DeleteAttachment.sql
Normal file
@ -0,0 +1,43 @@
|
||||
CREATE PROCEDURE [dbo].[Cipher_DeleteAttachment]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@AttachmentId VARCHAR(50)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @AttachmentIdKey VARCHAR(50) = CONCAT('"', @AttachmentId, '"')
|
||||
DECLARE @AttachmentIdPath VARCHAR(50) = CONCAT('$.', @AttachmentIdKey)
|
||||
|
||||
DECLARE @Attachments NVARCHAR(MAX)
|
||||
DECLARE @UserId UNIQUEIDENTIFIER
|
||||
DECLARE @OrganizationId UNIQUEIDENTIFIER
|
||||
|
||||
SELECT
|
||||
@UserId = [UserId],
|
||||
@OrganizationId = [OrganizationId],
|
||||
@Attachments = [Attachments]
|
||||
FROM
|
||||
[dbo].[Cipher]
|
||||
WHERE [Id] = @Id
|
||||
|
||||
DECLARE @AttachmentData NVARCHAR(MAX) = JSON_QUERY(@Attachments, @AttachmentIdPath)
|
||||
DECLARE @Size BIGINT = (CAST(JSON_VALUE(@AttachmentData, '$.Size') AS BIGINT) * -1)
|
||||
|
||||
UPDATE
|
||||
[dbo].[Cipher]
|
||||
SET
|
||||
[Attachments] = JSON_MODIFY([Attachments], @AttachmentIdPath, NULL)
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
|
||||
IF @OrganizationId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[Organization_UpdateStorage] @OrganizationId, @Size
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
ELSE IF @UserId IS NOT NULL
|
||||
BEGIN
|
||||
EXEC [dbo].[User_UpdateStorage] @UserId, @Size
|
||||
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
|
||||
END
|
||||
END
|
Reference in New Issue
Block a user