mirror of
https://github.com/bitwarden/server.git
synced 2025-04-18 11:38:15 -05:00
[PM-17473] Refactor AuthRequestService to remove admin notification feature flag (#5549)
This commit is contained in:
parent
abe593d221
commit
10ea2cb3eb
@ -287,12 +287,6 @@ public class AuthRequestService : IAuthRequestService
|
|||||||
|
|
||||||
private async Task NotifyAdminsOfDeviceApprovalRequestAsync(OrganizationUser organizationUser, User user)
|
private async Task NotifyAdminsOfDeviceApprovalRequestAsync(OrganizationUser organizationUser, User user)
|
||||||
{
|
{
|
||||||
if (!_featureService.IsEnabled(FeatureFlagKeys.DeviceApprovalRequestAdminNotifications))
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Skipped sending device approval notification to admins - feature flag disabled");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var adminEmails = await GetAdminAndAccountRecoveryEmailsAsync(organizationUser.OrganizationId);
|
var adminEmails = await GetAdminAndAccountRecoveryEmailsAsync(organizationUser.OrganizationId);
|
||||||
|
|
||||||
await _mailService.SendDeviceApprovalRequestedNotificationEmailAsync(
|
await _mailService.SendDeviceApprovalRequestedNotificationEmailAsync(
|
||||||
|
@ -273,78 +273,7 @@ public class AuthRequestServiceTests
|
|||||||
/// each of them.
|
/// each of them.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task CreateAuthRequestAsync_AdminApproval_CreatesForEachOrganization(
|
public async Task CreateAuthRequestAsync_AdminApproval_CreatesForEachOrganization_SendsEmails(
|
||||||
SutProvider<AuthRequestService> sutProvider,
|
|
||||||
AuthRequestCreateRequestModel createModel,
|
|
||||||
User user,
|
|
||||||
OrganizationUser organizationUser1,
|
|
||||||
OrganizationUser organizationUser2)
|
|
||||||
{
|
|
||||||
createModel.Type = AuthRequestType.AdminApproval;
|
|
||||||
user.Email = createModel.Email;
|
|
||||||
organizationUser1.UserId = user.Id;
|
|
||||||
organizationUser2.UserId = user.Id;
|
|
||||||
|
|
||||||
sutProvider.GetDependency<IUserRepository>()
|
|
||||||
.GetByEmailAsync(user.Email)
|
|
||||||
.Returns(user);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<ICurrentContext>()
|
|
||||||
.DeviceType
|
|
||||||
.Returns(DeviceType.ChromeExtension);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<ICurrentContext>()
|
|
||||||
.UserId
|
|
||||||
.Returns(user.Id);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<IGlobalSettings>()
|
|
||||||
.PasswordlessAuth.KnownDevicesOnly
|
|
||||||
.Returns(false);
|
|
||||||
|
|
||||||
|
|
||||||
sutProvider.GetDependency<IOrganizationUserRepository>()
|
|
||||||
.GetManyByUserAsync(user.Id)
|
|
||||||
.Returns(new List<OrganizationUser>
|
|
||||||
{
|
|
||||||
organizationUser1,
|
|
||||||
organizationUser2,
|
|
||||||
});
|
|
||||||
|
|
||||||
sutProvider.GetDependency<IAuthRequestRepository>()
|
|
||||||
.CreateAsync(Arg.Any<AuthRequest>())
|
|
||||||
.Returns(c => c.ArgAt<AuthRequest>(0));
|
|
||||||
|
|
||||||
var authRequest = await sutProvider.Sut.CreateAuthRequestAsync(createModel);
|
|
||||||
|
|
||||||
Assert.Equal(organizationUser1.OrganizationId, authRequest.OrganizationId);
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<IAuthRequestRepository>()
|
|
||||||
.Received(1)
|
|
||||||
.CreateAsync(Arg.Is<AuthRequest>(o => o.OrganizationId == organizationUser1.OrganizationId));
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<IAuthRequestRepository>()
|
|
||||||
.Received(1)
|
|
||||||
.CreateAsync(Arg.Is<AuthRequest>(o => o.OrganizationId == organizationUser2.OrganizationId));
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<IAuthRequestRepository>()
|
|
||||||
.Received(2)
|
|
||||||
.CreateAsync(Arg.Any<AuthRequest>());
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<IEventService>()
|
|
||||||
.Received(1)
|
|
||||||
.LogUserEventAsync(user.Id, EventType.User_RequestedDeviceApproval);
|
|
||||||
|
|
||||||
await sutProvider.GetDependency<IMailService>()
|
|
||||||
.DidNotReceiveWithAnyArgs()
|
|
||||||
.SendDeviceApprovalRequestedNotificationEmailAsync(
|
|
||||||
Arg.Any<IEnumerable<string>>(),
|
|
||||||
Arg.Any<Guid>(),
|
|
||||||
Arg.Any<string>(),
|
|
||||||
Arg.Any<string>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
|
||||||
public async Task CreateAuthRequestAsync_AdminApproval_WithAdminNotifications_CreatesForEachOrganization_SendsEmails(
|
|
||||||
SutProvider<AuthRequestService> sutProvider,
|
SutProvider<AuthRequestService> sutProvider,
|
||||||
AuthRequestCreateRequestModel createModel,
|
AuthRequestCreateRequestModel createModel,
|
||||||
User user,
|
User user,
|
||||||
@ -369,10 +298,6 @@ public class AuthRequestServiceTests
|
|||||||
ManageResetPassword = true,
|
ManageResetPassword = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
sutProvider.GetDependency<IFeatureService>()
|
|
||||||
.IsEnabled(FeatureFlagKeys.DeviceApprovalRequestAdminNotifications)
|
|
||||||
.Returns(true);
|
|
||||||
|
|
||||||
sutProvider.GetDependency<IUserRepository>()
|
sutProvider.GetDependency<IUserRepository>()
|
||||||
.GetByEmailAsync(user.Email)
|
.GetByEmailAsync(user.Email)
|
||||||
.Returns(user);
|
.Returns(user);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user