mirror of
https://github.com/bitwarden/server.git
synced 2025-07-04 01:22:50 -05:00
[PM-15637] Notify Custom Users with “Manage Account Recovery” permission for Device Approval Requests (#5359)
* Add stored procedure to read organization user details by role * Add OrganizationUserRepository method to retrieve OrganizationUser details by role * Enhance AuthRequestService to send notifications to custom users with ManageResetPassword permission * Enhance AuthRequestServiceTests to include custom user permissions and validate notification email recipients
This commit is contained in:
@ -60,4 +60,12 @@ public interface IOrganizationUserRepository : IRepository<OrganizationUser, Gui
|
||||
Task<ICollection<OrganizationUser>> GetManyByOrganizationWithClaimedDomainsAsync(Guid organizationId);
|
||||
|
||||
Task RevokeManyByIdAsync(IEnumerable<Guid> organizationUserIds);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of OrganizationUsersUserDetails with the specified role.
|
||||
/// </summary>
|
||||
/// <param name="organizationId">The organization to search within</param>
|
||||
/// <param name="role">The role to search for</param>
|
||||
/// <returns>A list of OrganizationUsersUserDetails with the specified role</returns>
|
||||
Task<IEnumerable<OrganizationUserUserDetails>> GetManyDetailsByRoleAsync(Guid organizationId, OrganizationUserType role);
|
||||
}
|
||||
|
@ -297,10 +297,34 @@ public class AuthRequestService : IAuthRequestService
|
||||
return;
|
||||
}
|
||||
|
||||
var admins = await _organizationUserRepository.GetManyByMinimumRoleAsync(
|
||||
var adminEmails = await GetAdminAndAccountRecoveryEmailsAsync(organizationUser.OrganizationId);
|
||||
|
||||
await _mailService.SendDeviceApprovalRequestedNotificationEmailAsync(
|
||||
adminEmails,
|
||||
organizationUser.OrganizationId,
|
||||
user.Email,
|
||||
user.Name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of emails for admins and custom users with the ManageResetPassword permission.
|
||||
/// </summary>
|
||||
/// <param name="organizationId">The organization to search within</param>
|
||||
private async Task<List<string>> GetAdminAndAccountRecoveryEmailsAsync(Guid organizationId)
|
||||
{
|
||||
var admins = await _organizationUserRepository.GetManyByMinimumRoleAsync(
|
||||
organizationId,
|
||||
OrganizationUserType.Admin);
|
||||
var adminEmails = admins.Select(a => a.Email).Distinct().ToList();
|
||||
await _mailService.SendDeviceApprovalRequestedNotificationEmailAsync(adminEmails, organizationUser.OrganizationId, user.Email, user.Name);
|
||||
|
||||
var customUsers = await _organizationUserRepository.GetManyDetailsByRoleAsync(
|
||||
organizationId,
|
||||
OrganizationUserType.Custom);
|
||||
|
||||
return admins.Select(a => a.Email)
|
||||
.Concat(customUsers
|
||||
.Where(a => a.GetPermissions().ManageResetPassword)
|
||||
.Select(a => a.Email))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user