mirror of
https://github.com/bitwarden/server
synced 2026-02-26 17:33:40 +00:00
[PM-26376] Emergency Access Delete Command (#6857)
* feat: Add initial DeleteEmergencyContactCommand * chore: remove nullable enable and add comments * test: add tests for new delete command * test: update tests to test IMailer was called. * feat: add delete by GranteeId and allow for multiple grantors to be contacted. * feat: add DeleteMany stored procedure for EmergencyAccess * test: add database tests for new SP * feat: commands use DeleteManyById for emergencyAccessDeletes * claude: send one email per grantor instead of a bulk email to all grantors. Modified tests to validate. * feat: change revision dates for confirmed grantees; * feat: add AccountRevisionDate bump for grantee users in the confirmed status * test: update integration test to validate only confirmed users are updated as well as proper deletion of emergency access
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
CREATE OR ALTER PROCEDURE [dbo].[EmergencyAccess_DeleteManyById]
|
||||
@EmergencyAccessIds [dbo].[GuidIdArray] READONLY
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @UserIds AS [GuidIdArray];
|
||||
DECLARE @BatchSize INT = 100
|
||||
|
||||
INSERT INTO @UserIds
|
||||
SELECT DISTINCT
|
||||
[GranteeId]
|
||||
FROM
|
||||
[dbo].[EmergencyAccess] EA
|
||||
INNER JOIN
|
||||
@EmergencyAccessIds EAI ON EAI.[Id] = EA.[Id]
|
||||
WHERE
|
||||
EA.[Status] = 2 -- 2 = Bit.Core.Auth.Enums.EmergencyAccessStatusType.Confirmed
|
||||
AND
|
||||
EA.[GranteeId] IS NOT NULL
|
||||
|
||||
|
||||
-- Delete EmergencyAccess Records
|
||||
WHILE @BatchSize > 0
|
||||
BEGIN
|
||||
|
||||
DELETE TOP(@BatchSize) EA
|
||||
FROM
|
||||
[dbo].[EmergencyAccess] EA
|
||||
INNER JOIN
|
||||
@EmergencyAccessIds EAI ON EAI.[Id] = EA.[Id]
|
||||
|
||||
SET @BatchSize = @@ROWCOUNT
|
||||
|
||||
END
|
||||
|
||||
-- Bump AccountRevisionDate for affected users after deletions
|
||||
Exec [dbo].[User_BumpManyAccountRevisionDates] @UserIds
|
||||
|
||||
END
|
||||
GO
|
||||
Reference in New Issue
Block a user