feat: add AccountRevisionDate bump for grantee users in the confirmed status

This commit is contained in:
Ike Kottlowski
2026-01-29 21:34:43 -05:00
parent bdfac87d2a
commit 3a58115acf
3 changed files with 36 additions and 41 deletions

View File

@@ -149,21 +149,18 @@ public class EmergencyAccessRepository : Repository<Core.Auth.Entities.Emergency
{
using var scope = ServiceScopeFactory.CreateScope();
var dbContext = GetDatabaseContext(scope);
var rangeToRemove = from ea in dbContext.EmergencyAccesses
var entitiesToRemove = from ea in dbContext.EmergencyAccesses
where emergencyAccessIds.Contains(ea.Id)
select ea;
dbContext.EmergencyAccesses.RemoveRange(rangeToRemove);
var granteeIds = rangeToRemove
var granteeIds = entitiesToRemove
.Where(ea => ea.Status == EmergencyAccessStatusType.Confirmed)
.Where(ea => ea.GranteeId.HasValue)
.Select(ea => ea.GranteeId!.Value) // .Value is safe here due to the Where above
.Distinct();
await dbContext.UserBumpManyAccountRevisionDatesAsync(
[.. granteeIds]
);
dbContext.EmergencyAccesses.RemoveRange(entitiesToRemove);
await dbContext.UserBumpManyAccountRevisionDatesAsync([.. granteeIds]);
await dbContext.SaveChangesAsync();
}
}

View File

@@ -4,18 +4,19 @@ AS
BEGIN
SET NOCOUNT ON
-- track GranteeIds for bumping revision date prior to deletion
DECLARE @GranteeIds AS TABLE (UserId UNIQUEIDENTIFIER)
DECLARE @UserIds AS [GuidIdArray];
-- this matches the logic in User_BumpAccountRevisionDateByEmergencyAccessGranteeId
INSERT INTO @GranteeIds
(UserId)
SELECT DISTINCT GranteeId
INSERT INTO @UserIds
SELECT DISTINCT
[GranteeId]
FROM
[dbo].[EmergencyAccess] EA
WHERE EA.Id IN (SELECT Id
FROM @EmergencyAccessIds
WHERE EA.[Status] = 2 )
INNER JOIN
@EmergencyAccessIds EAI ON EAI.[Id] = EA.[Id]
WHERE
EA.[Status] = 2
AND
EA.[GranteeId] IS NOT NULL
DECLARE @BatchSize INT = 100
@@ -26,17 +27,15 @@ BEGIN
DELETE TOP(@BatchSize) EA
FROM
[dbo].[EmergencyAccess] EA
INNER JOIN
@EmergencyAccessIds EAI ON EAI.Id = EA.Id
INNER JOIN
@EmergencyAccessIds EAI ON EAI.[Id] = EA.[Id]
SET @BatchSize = @@ROWCOUNT
END
-- Bump AccountRevisionDate for affected users after deletions
Exec [dbo].[User_BumpManyAccountRevisionDates]
(
SELECT [UserId]
FROM @GranteeIds
)
Exec [dbo].[User_BumpManyAccountRevisionDates] @UserIds
END
GO
GO

View File

@@ -4,18 +4,19 @@ AS
BEGIN
SET NOCOUNT ON
-- track GranteeIds for bumping revision date prior to deletion
DECLARE @GranteeIds AS TABLE (UserId UNIQUEIDENTIFIER)
DECLARE @UserIds AS [GuidIdArray];
-- this matches the logic in User_BumpAccountRevisionDateByEmergencyAccessGranteeId
INSERT INTO @GranteeIds
(UserId)
SELECT DISTINCT GranteeId
INSERT INTO @UserIds
SELECT DISTINCT
[GranteeId]
FROM
[dbo].[EmergencyAccess] EA
WHERE EA.Id IN (SELECT Id
FROM @EmergencyAccessIds
WHERE EA.[Status] = 2 )
INNER JOIN
@EmergencyAccessIds EAI ON EAI.[Id] = EA.[Id]
WHERE
EA.[Status] = 2
AND
EA.[GranteeId] IS NOT NULL
DECLARE @BatchSize INT = 100
@@ -26,17 +27,15 @@ BEGIN
DELETE TOP(@BatchSize) EA
FROM
[dbo].[EmergencyAccess] EA
INNER JOIN
@EmergencyAccessIds EAI ON EAI.Id = EA.Id
INNER JOIN
@EmergencyAccessIds EAI ON EAI.[Id] = EA.[Id]
SET @BatchSize = @@ROWCOUNT
END
-- Bump AccountRevisionDate for affected users after deletions
Exec [dbo].[User_BumpManyAccountRevisionDates]
(
SELECT [UserId]
FROM @GranteeIds
)
Exec [dbo].[User_BumpManyAccountRevisionDates] @UserIds
END
GO
GO