From 5227ee7d9052641d27fcb59afea9637217aa7ed7 Mon Sep 17 00:00:00 2001 From: Jimmy Vo Date: Tue, 19 Nov 2024 17:19:22 -0500 Subject: [PATCH 1/2] [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) From 77cde50ee1ffe43a5ba2517e9f4e107eeb405009 Mon Sep 17 00:00:00 2001 From: Conner Turnbull <133619638+cturnbull-bitwarden@users.noreply.github.com> Date: Wed, 20 Nov 2024 09:32:53 -0500 Subject: [PATCH 2/2] Updated customer metadata when updating to use bank account (#5050) --- src/Core/Billing/Services/Implementations/SubscriberService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Core/Billing/Services/Implementations/SubscriberService.cs b/src/Core/Billing/Services/Implementations/SubscriberService.cs index 401d9ce2c..b0d290a55 100644 --- a/src/Core/Billing/Services/Implementations/SubscriberService.cs +++ b/src/Core/Billing/Services/Implementations/SubscriberService.cs @@ -768,8 +768,9 @@ public class SubscriberService( { var metadata = customer.Metadata ?? new Dictionary(); - if (metadata.ContainsKey(BraintreeCustomerIdKey)) + if (metadata.TryGetValue(BraintreeCustomerIdKey, out var value)) { + metadata[BraintreeCustomerIdOldKey] = value; metadata[BraintreeCustomerIdKey] = null; await stripeAdapter.CustomerUpdateAsync(customer.Id, new CustomerUpdateOptions