1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-29 13:25:17 +01:00

Refactor RemoveOrganizationUserCommand.RemoveUsersAsync to log in bulk

This commit is contained in:
Rui Tome 2024-10-23 11:25:21 +01:00
parent dececee4b9
commit 5eab00bf9c
No known key found for this signature in database
GPG Key ID: 526239D96A8EC066
2 changed files with 11 additions and 7 deletions

View File

@ -118,12 +118,12 @@ public class RemoveOrganizationUserCommand : IRemoveOrganizationUserCommand
if (usersToDelete.Any())
{
var eventDate = DateTime.UtcNow;
await _organizationUserRepository.DeleteManyAsync(usersToDelete.Select(u => u.Id));
await _eventService.LogOrganizationUserEventsAsync(usersToDelete.Select(u => (u, EventType.OrganizationUser_Removed, (DateTime?)eventDate)));
foreach (var orgUser in usersToDelete)
{
await _eventService.LogOrganizationUserEventAsync(orgUser, EventType.OrganizationUser_Removed);
if (orgUser.UserId.HasValue)
{
await DeleteAndPushUserRegistrationAsync(organizationId, orgUser.UserId.Value);

View File

@ -453,7 +453,10 @@ public class RemoveOrganizationUserCommandTests
await sutProvider.GetDependency<IEventService>()
.Received(1)
.LogOrganizationUserEventAsync(orgUser, EventType.OrganizationUser_Removed);
.LogOrganizationUserEventsAsync(
Arg.Is<IEnumerable<(OrganizationUser, EventType, DateTime?)>>(events =>
events.Count() == 1
&& events.Any(e => e.Item1.Id == orgUser.Id && e.Item2 == EventType.OrganizationUser_Removed)));
}
[Theory, BitAutoData]
@ -484,10 +487,11 @@ public class RemoveOrganizationUserCommandTests
await sutProvider.GetDependency<IEventService>()
.Received(1)
.LogOrganizationUserEventAsync(Arg.Is<OrganizationUser>(u => u.Id == orgUser1.Id), EventType.OrganizationUser_Removed);
await sutProvider.GetDependency<IEventService>()
.Received(1)
.LogOrganizationUserEventAsync(Arg.Is<OrganizationUser>(u => u.Id == orgUser2.Id), EventType.OrganizationUser_Removed);
.LogOrganizationUserEventsAsync(
Arg.Is<IEnumerable<(OrganizationUser, EventType, DateTime?)>>(events =>
events.Count() == 2
&& events.Any(e => e.Item1.Id == orgUser1.Id && e.Item2 == EventType.OrganizationUser_Removed)
&& events.Any(e => e.Item1.Id == orgUser2.Id && e.Item2 == EventType.OrganizationUser_Removed)));
}
[Theory, BitAutoData]