1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 23:52:50 -05:00

[PM-15637] Add Email Notification Templates and Logic for Device Approval Requests (#5270)

* Add device approval notification email templates

* Add DeviceApprovalRequestedViewModel for device approval notifications

* Add method to send device approval requested notification email

* Send email notification to Organization Admins when adding a new admin approval auth request

* Add tests for device approval notification email sending in AuthRequestServiceTests

* fix(email-templates): Remove unnecessary triple braces from user name variable in device approval notification emails

* Add feature flag for admin notifications on device approval requests

* Add logging for skipped admin notifications on device approval requests
This commit is contained in:
Rui Tomé
2025-01-27 10:59:46 +00:00
committed by GitHub
parent 3908edd08f
commit 9e718d7336
11 changed files with 249 additions and 1 deletions

View File

@ -96,5 +96,6 @@ public interface IMailService
Task SendFamiliesForEnterpriseRemoveSponsorshipsEmailAsync(string email, string offerAcceptanceDate, string organizationId,
string organizationName);
Task SendClaimedDomainUserEmailAsync(ManagedUserDomainClaimedEmails emailList);
Task SendDeviceApprovalRequestedNotificationEmailAsync(IEnumerable<string> adminEmails, Guid organizationId, string email, string userName);
}

View File

@ -2,6 +2,7 @@
using System.Reflection;
using Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.Entities.Provider;
using Bit.Core.AdminConsole.Models.Mail;
using Bit.Core.Auth.Entities;
using Bit.Core.Auth.Models.Mail;
using Bit.Core.Billing.Enums;
@ -1168,6 +1169,23 @@ public class HandlebarsMailService : IMailService
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendDeviceApprovalRequestedNotificationEmailAsync(IEnumerable<string> adminEmails, Guid organizationId, string email, string userName)
{
var templateName = _globalSettings.SelfHosted ?
"AdminConsole.SelfHostNotifyAdminDeviceApprovalRequested" :
"AdminConsole.NotifyAdminDeviceApprovalRequested";
var message = CreateDefaultMessage("Review SSO login request for new device", adminEmails);
var model = new DeviceApprovalRequestedViewModel
{
WebVaultUrl = _globalSettings.BaseServiceUri.VaultWithHash,
UserNameRequestingAccess = GetUserIdentifier(email, userName),
OrganizationId = organizationId,
};
await AddMessageContentAsync(message, templateName, model);
message.Category = "DeviceApprovalRequested";
await _mailDeliveryService.SendEmailAsync(message);
}
private static string GetUserIdentifier(string email, string userName)
{
return string.IsNullOrEmpty(userName) ? email : CoreHelpers.SanitizeForEmail(userName, false);

View File

@ -316,5 +316,10 @@ public class NoopMailService : IMailService
return Task.FromResult(0);
}
public Task SendClaimedDomainUserEmailAsync(ManagedUserDomainClaimedEmails emailList) => Task.CompletedTask;
public Task SendDeviceApprovalRequestedNotificationEmailAsync(IEnumerable<string> adminEmails, Guid organizationId, string email, string userName)
{
return Task.FromResult(0);
}
}