mirror of
https://github.com/bitwarden/server.git
synced 2025-05-21 03:24:31 -05:00
[EC-495] Updated GroupService.SaveAsync to check if collections are supplied and prevent deleting Group-to-Collection associations. Added unit test. (#2234)
This commit is contained in:
parent
a6d97118fa
commit
e0f9d99b49
@ -61,7 +61,16 @@ public class GroupService : IGroupService
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
group.RevisionDate = DateTime.UtcNow;
|
group.RevisionDate = DateTime.UtcNow;
|
||||||
await _groupRepository.ReplaceAsync(group, collections ?? new List<SelectionReadOnly>());
|
|
||||||
|
if (collections == null)
|
||||||
|
{
|
||||||
|
await _groupRepository.ReplaceAsync(group);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await _groupRepository.ReplaceAsync(group, collections);
|
||||||
|
}
|
||||||
|
|
||||||
await _eventService.LogGroupEventAsync(group, Enums.EventType.Group_Updated);
|
await _eventService.LogGroupEventAsync(group, Enums.EventType.Group_Updated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,20 @@ public class GroupServiceTests
|
|||||||
Assert.True(group.RevisionDate - DateTime.UtcNow < TimeSpan.FromSeconds(1));
|
Assert.True(group.RevisionDate - DateTime.UtcNow < TimeSpan.FromSeconds(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory, BitAutoData]
|
||||||
|
public async Task SaveAsync_NonDefaultGroupId_ReplaceGroupInRepository_NoCollections(Group group, Organization organization, SutProvider<GroupService> sutProvider)
|
||||||
|
{
|
||||||
|
organization.UseGroups = true;
|
||||||
|
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(organization.Id).Returns(organization);
|
||||||
|
|
||||||
|
await sutProvider.Sut.SaveAsync(group, null);
|
||||||
|
|
||||||
|
await sutProvider.GetDependency<IGroupRepository>().Received().ReplaceAsync(group);
|
||||||
|
await sutProvider.GetDependency<IEventService>().Received()
|
||||||
|
.LogGroupEventAsync(group, EventType.Group_Updated);
|
||||||
|
Assert.True(group.RevisionDate - DateTime.UtcNow < TimeSpan.FromSeconds(1));
|
||||||
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task SaveAsync_NonExistingOrganizationId_ThrowsBadRequest(Group group, SutProvider<GroupService> sutProvider)
|
public async Task SaveAsync_NonExistingOrganizationId_ThrowsBadRequest(Group group, SutProvider<GroupService> sutProvider)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user