1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

Fix empty grantee or grantor names in emergency access emails (#1162)

* Fix empty grantee or grantor names in emails

* Add migrator dbscript for changes to ReadToNotify
This commit is contained in:
Thomas Rittson 2021-02-26 08:11:58 +10:00 committed by GitHub
parent b21c9042ca
commit 3850f0e400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 5 deletions

View File

@ -10,5 +10,6 @@ namespace Bit.Core.Models.Data
{ {
public string GrantorEmail { get; set; } public string GrantorEmail { get; set; }
public string GranteeName { get; set; } public string GranteeName { get; set; }
public string GranteeEmail { get; set; }
} }
} }

View File

@ -313,8 +313,10 @@ namespace Bit.Core.Services
var ea = notify.ToEmergencyAccess(); var ea = notify.ToEmergencyAccess();
ea.LastNotificationDate = DateTime.UtcNow; ea.LastNotificationDate = DateTime.UtcNow;
await _emergencyAccessRepository.ReplaceAsync(ea); await _emergencyAccessRepository.ReplaceAsync(ea);
await _mailService.SendEmergencyAccessRecoveryReminder(ea, notify.GranteeName, notify.GrantorEmail); var granteeNameOrEmail = string.IsNullOrWhiteSpace(notify.GranteeName) ? notify.GranteeEmail : notify.GranteeName;
await _mailService.SendEmergencyAccessRecoveryReminder(ea, granteeNameOrEmail, notify.GrantorEmail);
} }
} }
@ -327,9 +329,12 @@ namespace Bit.Core.Services
var ea = details.ToEmergencyAccess(); var ea = details.ToEmergencyAccess();
ea.Status = EmergencyAccessStatusType.RecoveryApproved; ea.Status = EmergencyAccessStatusType.RecoveryApproved;
await _emergencyAccessRepository.ReplaceAsync(ea); await _emergencyAccessRepository.ReplaceAsync(ea);
await _mailService.SendEmergencyAccessRecoveryApproved(ea, details.GrantorName, details.GranteeEmail); var grantorNameOrEmail = string.IsNullOrWhiteSpace(details.GrantorName) ? details.GrantorEmail : details.GrantorName;
await _mailService.SendEmergencyAccessRecoveryTimedOut(ea, details.GranteeName, details.GrantorEmail); var granteeNameOrEmail = string.IsNullOrWhiteSpace(details.GranteeName) ? details.GranteeEmail : details.GranteeName;
await _mailService.SendEmergencyAccessRecoveryApproved(ea, grantorNameOrEmail, details.GranteeEmail);
await _mailService.SendEmergencyAccessRecoveryTimedOut(ea, granteeNameOrEmail, details.GrantorEmail);
} }
} }

View File

@ -6,6 +6,7 @@ BEGIN
SELECT SELECT
EA.*, EA.*,
Grantee.Name as GranteeName, Grantee.Name as GranteeName,
Grantee.Email as GranteeEmail,
Grantor.Email as GrantorEmail Grantor.Email as GrantorEmail
FROM FROM
[dbo].[EmergencyAccess] EA [dbo].[EmergencyAccess] EA

View File

@ -0,0 +1,30 @@
IF OBJECT_ID('[dbo].[EmergencyAccess_ReadToNotify]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[EmergencyAccess_ReadToNotify]
END
GO
CREATE PROCEDURE [dbo].[EmergencyAccess_ReadToNotify]
AS
BEGIN
SET NOCOUNT ON
SELECT
EA.*,
Grantee.Name as GranteeName,
Grantee.Email as GranteeEmail,
Grantor.Email as GrantorEmail
FROM
[dbo].[EmergencyAccess] EA
LEFT JOIN
[dbo].[User] Grantor ON Grantor.[Id] = EA.[GrantorId]
LEFT JOIN
[dbo].[User] Grantee On Grantee.[Id] = EA.[GranteeId]
WHERE
EA.[Status] = 3
AND
DATEADD(DAY, EA.[WaitTimeDays] - 1, EA.[RecoveryInitiatedDate]) <= GETUTCDATE()
AND
DATEADD(DAY, 1, EA.[LastNotificationDate]) <= GETUTCDATE()
END
GO