mirror of
https://github.com/bitwarden/server.git
synced 2024-12-01 13:43:23 +01:00
Refactor RemoveOrganizationUserCommand.RemoveUsersAsync to log in bulk
This commit is contained in:
parent
dececee4b9
commit
5eab00bf9c
@ -118,12 +118,12 @@ public class RemoveOrganizationUserCommand : IRemoveOrganizationUserCommand
|
|||||||
|
|
||||||
if (usersToDelete.Any())
|
if (usersToDelete.Any())
|
||||||
{
|
{
|
||||||
|
var eventDate = DateTime.UtcNow;
|
||||||
await _organizationUserRepository.DeleteManyAsync(usersToDelete.Select(u => u.Id));
|
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)
|
foreach (var orgUser in usersToDelete)
|
||||||
{
|
{
|
||||||
await _eventService.LogOrganizationUserEventAsync(orgUser, EventType.OrganizationUser_Removed);
|
|
||||||
|
|
||||||
if (orgUser.UserId.HasValue)
|
if (orgUser.UserId.HasValue)
|
||||||
{
|
{
|
||||||
await DeleteAndPushUserRegistrationAsync(organizationId, orgUser.UserId.Value);
|
await DeleteAndPushUserRegistrationAsync(organizationId, orgUser.UserId.Value);
|
||||||
|
@ -453,7 +453,10 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
|
|
||||||
await sutProvider.GetDependency<IEventService>()
|
await sutProvider.GetDependency<IEventService>()
|
||||||
.Received(1)
|
.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]
|
[Theory, BitAutoData]
|
||||||
@ -484,10 +487,11 @@ public class RemoveOrganizationUserCommandTests
|
|||||||
|
|
||||||
await sutProvider.GetDependency<IEventService>()
|
await sutProvider.GetDependency<IEventService>()
|
||||||
.Received(1)
|
.Received(1)
|
||||||
.LogOrganizationUserEventAsync(Arg.Is<OrganizationUser>(u => u.Id == orgUser1.Id), EventType.OrganizationUser_Removed);
|
.LogOrganizationUserEventsAsync(
|
||||||
await sutProvider.GetDependency<IEventService>()
|
Arg.Is<IEnumerable<(OrganizationUser, EventType, DateTime?)>>(events =>
|
||||||
.Received(1)
|
events.Count() == 2
|
||||||
.LogOrganizationUserEventAsync(Arg.Is<OrganizationUser>(u => u.Id == orgUser2.Id), EventType.OrganizationUser_Removed);
|
&& 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]
|
[Theory, BitAutoData]
|
||||||
|
Loading…
Reference in New Issue
Block a user