1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

[AC-1191] TDE admin approval email (#3044)

* feat: add new command for updating request and emailing user, refs AC-1191

* feat: inject service with organization service collection extensions, refs AC-1191

* feat: add function to send admin approval email to mail services (interface/noop/handlebars), refs AC-1191

* feat: add html/text mail templates and add view model for email data, refs AC-1191

* feat: update org auth request controller to use new command during auth request update, refs AC-1191

* fix: dotnet format, refs AC-1191

* refactor: update user not found error, FirstOrDefault for enum type display name, refs AC-1191

* refactor: update user not found to log error instead of throws, refs AC-1191

* fix: remove whitespace lint errors, refs AC-1191

* refactor: update hardcoded UTC timezone string, refs AC-1191

* refactor: add unit test for new command, refs AC-1191

* refactor: improve enum name fallback and identifier string creation, refs AC-1191

* refactor: add addtional unit tests, refs AC-1191

* refactor: update success test to use more generated params, refs AC-1191

* fix: dotnet format...again, refs AC-1191

* refactor: make UTC display a constant for handlebars mail service, refs AC-1191

* refactor: update displayTypeIdentifer to displayTypeAndIdentifier for clarity, refs AC-1191
This commit is contained in:
Vincent Salucci
2023-07-06 10:03:49 -05:00
committed by GitHub
parent 62beb7d1e8
commit 3b4c8afea0
11 changed files with 243 additions and 8 deletions

View File

@ -17,6 +17,7 @@ namespace Bit.Core.Services;
public class HandlebarsMailService : IMailService
{
private const string Namespace = "Bit.Core.MailTemplates.Handlebars";
private const string _utcTimeZoneDisplay = "UTC";
private readonly GlobalSettings _globalSettings;
private readonly IMailDeliveryService _mailDeliveryService;
@ -353,7 +354,7 @@ public class HandlebarsMailService : IMailService
DeviceType = deviceType,
TheDate = timestamp.ToLongDateString(),
TheTime = timestamp.ToShortTimeString(),
TimeZone = "UTC",
TimeZone = _utcTimeZoneDisplay,
IpAddress = ip
};
await AddMessageContentAsync(message, "NewDeviceLoggedIn", model);
@ -370,7 +371,7 @@ public class HandlebarsMailService : IMailService
SiteName = _globalSettings.SiteName,
TheDate = timestamp.ToLongDateString(),
TheTime = timestamp.ToShortTimeString(),
TimeZone = "UTC",
TimeZone = _utcTimeZoneDisplay,
IpAddress = ip
};
await AddMessageContentAsync(message, "Auth.RecoverTwoFactor", model);
@ -856,7 +857,7 @@ public class HandlebarsMailService : IMailService
{
TheDate = utcNow.ToLongDateString(),
TheTime = utcNow.ToShortTimeString(),
TimeZone = "UTC",
TimeZone = _utcTimeZoneDisplay,
IpAddress = ip,
AffectedEmail = email
@ -873,7 +874,7 @@ public class HandlebarsMailService : IMailService
{
TheDate = utcNow.ToLongDateString(),
TheTime = utcNow.ToShortTimeString(),
TimeZone = "UTC",
TimeZone = _utcTimeZoneDisplay,
IpAddress = ip,
AffectedEmail = email
@ -896,8 +897,26 @@ public class HandlebarsMailService : IMailService
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendTrustedDeviceAdminApprovalEmailAsync(string email, DateTime utcNow, string ip,
string deviceTypeAndIdentifier)
{
var message = CreateDefaultMessage("Login request approved", email);
var model = new TrustedDeviceAdminApprovalViewModel
{
TheDate = utcNow.ToLongDateString(),
TheTime = utcNow.ToShortTimeString(),
TimeZone = _utcTimeZoneDisplay,
IpAddress = ip,
DeviceType = deviceTypeAndIdentifier,
};
await AddMessageContentAsync(message, "Auth.TrustedDeviceAdminApproval", model);
message.Category = "TrustedDeviceAdminApproval";
await _mailDeliveryService.SendEmailAsync(message);
}
private static string GetUserIdentifier(string email, string userName)
{
return string.IsNullOrEmpty(userName) ? email : CoreHelpers.SanitizeForEmail(userName, false);
}
}