From 5227ee7d9052641d27fcb59afea9637217aa7ed7 Mon Sep 17 00:00:00 2001 From: Jimmy Vo Date: Tue, 19 Nov 2024 17:19:22 -0500 Subject: [PATCH] [PM-13746] Remove loggedInUserId parameter. (#5033) 1. Remove _organizationService.ValidateOrganizationUserUpdatePermissions since it is not needed for updating group associations. 2. Remove loggedInUserId since it's no longer needed. 3. Update/remove related tests. --- .../Public/Controllers/MembersController.cs | 2 +- .../IUpdateOrganizationUserGroupsCommand.cs | 2 +- .../UpdateOrganizationUserGroupsCommand.cs | 9 +------ ...pdateOrganizationUserGroupsCommandTests.cs | 25 ++----------------- 4 files changed, 5 insertions(+), 33 deletions(-) diff --git a/src/Api/AdminConsole/Public/Controllers/MembersController.cs b/src/Api/AdminConsole/Public/Controllers/MembersController.cs index 4e99353d4..76bd29d38 100644 --- a/src/Api/AdminConsole/Public/Controllers/MembersController.cs +++ b/src/Api/AdminConsole/Public/Controllers/MembersController.cs @@ -213,7 +213,7 @@ public class MembersController : Controller { return new NotFoundResult(); } - await _updateOrganizationUserGroupsCommand.UpdateUserGroupsAsync(existingUser, model.GroupIds, null); + await _updateOrganizationUserGroupsCommand.UpdateUserGroupsAsync(existingUser, model.GroupIds); return new OkResult(); } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/Interfaces/IUpdateOrganizationUserGroupsCommand.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/Interfaces/IUpdateOrganizationUserGroupsCommand.cs index 530b3839e..9e8037e68 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/Interfaces/IUpdateOrganizationUserGroupsCommand.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/Interfaces/IUpdateOrganizationUserGroupsCommand.cs @@ -4,5 +4,5 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interface public interface IUpdateOrganizationUserGroupsCommand { - Task UpdateUserGroupsAsync(OrganizationUser organizationUser, IEnumerable groupIds, Guid? loggedInUserId); + Task UpdateUserGroupsAsync(OrganizationUser organizationUser, IEnumerable groupIds); } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/UpdateOrganizationUserGroupsCommand.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/UpdateOrganizationUserGroupsCommand.cs index 0331f2ed5..615a33dbf 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/UpdateOrganizationUserGroupsCommand.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/UpdateOrganizationUserGroupsCommand.cs @@ -9,25 +9,18 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers; public class UpdateOrganizationUserGroupsCommand : IUpdateOrganizationUserGroupsCommand { private readonly IEventService _eventService; - private readonly IOrganizationService _organizationService; private readonly IOrganizationUserRepository _organizationUserRepository; public UpdateOrganizationUserGroupsCommand( IEventService eventService, - IOrganizationService organizationService, IOrganizationUserRepository organizationUserRepository) { _eventService = eventService; - _organizationService = organizationService; _organizationUserRepository = organizationUserRepository; } - public async Task UpdateUserGroupsAsync(OrganizationUser organizationUser, IEnumerable groupIds, Guid? loggedInUserId) + public async Task UpdateUserGroupsAsync(OrganizationUser organizationUser, IEnumerable groupIds) { - if (loggedInUserId.HasValue) - { - await _organizationService.ValidateOrganizationUserUpdatePermissions(organizationUser.OrganizationId, organizationUser.Type, null, organizationUser.GetPermissions()); - } await _organizationUserRepository.UpdateGroupsAsync(organizationUser.Id, groupIds); await _eventService.LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_UpdatedGroups); } diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/UpdateOrganizationUserGroupsCommandTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/UpdateOrganizationUserGroupsCommandTests.cs index a581b463f..ad598649a 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/UpdateOrganizationUserGroupsCommandTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/UpdateOrganizationUserGroupsCommandTests.cs @@ -14,34 +14,13 @@ namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationUsers; public class UpdateOrganizationUserGroupsCommandTests { [Theory, BitAutoData] - public async Task UpdateUserGroups_Passes( + public async Task UpdateUserGroups_ShouldUpdateUserGroupsAndLogUserEvent( OrganizationUser organizationUser, IEnumerable groupIds, SutProvider sutProvider) { - await sutProvider.Sut.UpdateUserGroupsAsync(organizationUser, groupIds, null); + await sutProvider.Sut.UpdateUserGroupsAsync(organizationUser, groupIds); - await sutProvider.GetDependency().DidNotReceiveWithAnyArgs() - .ValidateOrganizationUserUpdatePermissions(default, default, default, default); - await sutProvider.GetDependency().Received(1) - .UpdateGroupsAsync(organizationUser.Id, groupIds); - await sutProvider.GetDependency().Received(1) - .LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_UpdatedGroups); - } - - [Theory, BitAutoData] - public async Task UpdateUserGroups_WithSavingUserId_Passes( - OrganizationUser organizationUser, - IEnumerable groupIds, - Guid savingUserId, - SutProvider sutProvider) - { - organizationUser.Permissions = null; - - await sutProvider.Sut.UpdateUserGroupsAsync(organizationUser, groupIds, savingUserId); - - await sutProvider.GetDependency().Received(1) - .ValidateOrganizationUserUpdatePermissions(organizationUser.OrganizationId, organizationUser.Type, null, organizationUser.GetPermissions()); await sutProvider.GetDependency().Received(1) .UpdateGroupsAsync(organizationUser.Id, groupIds); await sutProvider.GetDependency().Received(1)