From 471851978b2ec6e232948100b4bb9ee46a6094ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Tom=C3=A9?= <108268980+r-tome@users.noreply.github.com> Date: Wed, 4 Sep 2024 11:18:23 +0100 Subject: [PATCH] [PM-10325] Rename OrganizationUser Delete and BulkDelete endpoints to Remove and BulkRemove (#4711) * Rename IDeleteOrganizationUserCommand to IRemoveOrganizationUserCommand * Rename IOrganizationService DeleteUser methods to RemoveUser * Rename API endpoints for deleting organization users to "Remove" * chore: Rename Delete method to Remove in MembersController --- .../Scim/Controllers/v2/UsersController.cs | 8 ++-- .../OrganizationUsersController.cs | 12 ++--- .../Controllers/OrganizationsController.cs | 2 +- .../Public/Controllers/MembersController.cs | 10 ++--- ...d.cs => IRemoveOrganizationUserCommand.cs} | 6 +-- ...nd.cs => RemoveOrganizationUserCommand.cs} | 12 ++--- .../Services/IOrganizationService.cs | 12 ++--- .../Implementations/OrganizationService.cs | 12 ++--- .../Services/Implementations/PolicyService.cs | 8 ++-- .../Implementations/EmergencyAccessService.cs | 2 +- ...OrganizationServiceCollectionExtensions.cs | 2 +- .../Services/Implementations/UserService.cs | 2 +- .../OrganizationsControllerTests.cs | 6 +-- .../OrganizationsControllerTests.cs | 4 +- ... => RemoveOrganizationUserCommandTests.cs} | 22 +++++----- .../Services/OrganizationServiceTests.cs | 44 +++++++++---------- .../Services/PolicyServiceTests.cs | 10 ++--- 17 files changed, 87 insertions(+), 87 deletions(-) rename src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/Interfaces/{IDeleteOrganizationUserCommand.cs => IRemoveOrganizationUserCommand.cs} (51%) rename src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/{DeleteOrganizationUserCommand.cs => RemoveOrganizationUserCommand.cs} (79%) rename test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/{DeleteOrganizationUserCommandTests.cs => RemoveOrganizationUserCommandTests.cs} (69%) diff --git a/bitwarden_license/src/Scim/Controllers/v2/UsersController.cs b/bitwarden_license/src/Scim/Controllers/v2/UsersController.cs index e76081305..1429fc387 100644 --- a/bitwarden_license/src/Scim/Controllers/v2/UsersController.cs +++ b/bitwarden_license/src/Scim/Controllers/v2/UsersController.cs @@ -21,7 +21,7 @@ public class UsersController : Controller private readonly IOrganizationUserRepository _organizationUserRepository; private readonly IOrganizationService _organizationService; private readonly IGetUsersListQuery _getUsersListQuery; - private readonly IDeleteOrganizationUserCommand _deleteOrganizationUserCommand; + private readonly IRemoveOrganizationUserCommand _removeOrganizationUserCommand; private readonly IPatchUserCommand _patchUserCommand; private readonly IPostUserCommand _postUserCommand; private readonly ILogger _logger; @@ -31,7 +31,7 @@ public class UsersController : Controller IOrganizationUserRepository organizationUserRepository, IOrganizationService organizationService, IGetUsersListQuery getUsersListQuery, - IDeleteOrganizationUserCommand deleteOrganizationUserCommand, + IRemoveOrganizationUserCommand removeOrganizationUserCommand, IPatchUserCommand patchUserCommand, IPostUserCommand postUserCommand, ILogger logger) @@ -40,7 +40,7 @@ public class UsersController : Controller _organizationUserRepository = organizationUserRepository; _organizationService = organizationService; _getUsersListQuery = getUsersListQuery; - _deleteOrganizationUserCommand = deleteOrganizationUserCommand; + _removeOrganizationUserCommand = removeOrganizationUserCommand; _patchUserCommand = patchUserCommand; _postUserCommand = postUserCommand; _logger = logger; @@ -120,7 +120,7 @@ public class UsersController : Controller [HttpDelete("{id}")] public async Task Delete(Guid organizationId, Guid id) { - await _deleteOrganizationUserCommand.DeleteUserAsync(organizationId, id, EventSystemUser.SCIM); + await _removeOrganizationUserCommand.RemoveUserAsync(organizationId, id, EventSystemUser.SCIM); return new NoContentResult(); } } diff --git a/src/Api/AdminConsole/Controllers/OrganizationUsersController.cs b/src/Api/AdminConsole/Controllers/OrganizationUsersController.cs index 69d941a74..30def6de5 100644 --- a/src/Api/AdminConsole/Controllers/OrganizationUsersController.cs +++ b/src/Api/AdminConsole/Controllers/OrganizationUsersController.cs @@ -506,8 +506,8 @@ public class OrganizationUsersController : Controller } [HttpDelete("{id}")] - [HttpPost("{id}/delete")] - public async Task Delete(string orgId, string id) + [HttpPost("{id}/remove")] + public async Task Remove(string orgId, string id) { var orgGuidId = new Guid(orgId); if (!await _currentContext.ManageUsers(orgGuidId)) @@ -516,12 +516,12 @@ public class OrganizationUsersController : Controller } var userId = _userService.GetProperUserId(User); - await _organizationService.DeleteUserAsync(orgGuidId, new Guid(id), userId.Value); + await _organizationService.RemoveUserAsync(orgGuidId, new Guid(id), userId.Value); } [HttpDelete("")] - [HttpPost("delete")] - public async Task> BulkDelete(string orgId, [FromBody] OrganizationUserBulkRequestModel model) + [HttpPost("remove")] + public async Task> BulkRemove(string orgId, [FromBody] OrganizationUserBulkRequestModel model) { var orgGuidId = new Guid(orgId); if (!await _currentContext.ManageUsers(orgGuidId)) @@ -530,7 +530,7 @@ public class OrganizationUsersController : Controller } var userId = _userService.GetProperUserId(User); - var result = await _organizationService.DeleteUsersAsync(orgGuidId, model.Ids, userId.Value); + var result = await _organizationService.RemoveUsersAsync(orgGuidId, model.Ids, userId.Value); return new ListResponseModel(result.Select(r => new OrganizationUserBulkResponseModel(r.Item1.Id, r.Item2))); } diff --git a/src/Api/AdminConsole/Controllers/OrganizationsController.cs b/src/Api/AdminConsole/Controllers/OrganizationsController.cs index 147fdd716..690652d43 100644 --- a/src/Api/AdminConsole/Controllers/OrganizationsController.cs +++ b/src/Api/AdminConsole/Controllers/OrganizationsController.cs @@ -231,7 +231,7 @@ public class OrganizationsController : Controller } - await _organizationService.DeleteUserAsync(orgGuidId, user.Id); + await _organizationService.RemoveUserAsync(orgGuidId, user.Id); } [HttpDelete("{id}")] diff --git a/src/Api/AdminConsole/Public/Controllers/MembersController.cs b/src/Api/AdminConsole/Public/Controllers/MembersController.cs index 53ae317f6..a737f0b49 100644 --- a/src/Api/AdminConsole/Public/Controllers/MembersController.cs +++ b/src/Api/AdminConsole/Public/Controllers/MembersController.cs @@ -226,24 +226,24 @@ public class MembersController : Controller } /// - /// Delete a member. + /// Remove a member. /// /// - /// Permanently deletes a member from the organization. This cannot be undone. + /// Permanently removes a member from the organization. This cannot be undone. /// The user account will still remain. The user is only removed from the organization. /// - /// The identifier of the member to be deleted. + /// The identifier of the member to be removed. [HttpDelete("{id}")] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NotFound)] - public async Task Delete(Guid id) + public async Task Remove(Guid id) { var user = await _organizationUserRepository.GetByIdAsync(id); if (user == null || user.OrganizationId != _currentContext.OrganizationId) { return new NotFoundResult(); } - await _organizationService.DeleteUserAsync(_currentContext.OrganizationId.Value, id, null); + await _organizationService.RemoveUserAsync(_currentContext.OrganizationId.Value, id, null); return new OkResult(); } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/Interfaces/IDeleteOrganizationUserCommand.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/Interfaces/IRemoveOrganizationUserCommand.cs similarity index 51% rename from src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/Interfaces/IDeleteOrganizationUserCommand.cs rename to src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/Interfaces/IRemoveOrganizationUserCommand.cs index 32c19077a..3213762ea 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/Interfaces/IDeleteOrganizationUserCommand.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/Interfaces/IRemoveOrganizationUserCommand.cs @@ -2,9 +2,9 @@ namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces; -public interface IDeleteOrganizationUserCommand +public interface IRemoveOrganizationUserCommand { - Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, Guid? deletingUserId); + Task RemoveUserAsync(Guid organizationId, Guid organizationUserId, Guid? deletingUserId); - Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, EventSystemUser eventSystemUser); + Task RemoveUserAsync(Guid organizationId, Guid organizationUserId, EventSystemUser eventSystemUser); } diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/DeleteOrganizationUserCommand.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/RemoveOrganizationUserCommand.cs similarity index 79% rename from src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/DeleteOrganizationUserCommand.cs rename to src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/RemoveOrganizationUserCommand.cs index b0b5cc00c..e2aea0249 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/DeleteOrganizationUserCommand.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/RemoveOrganizationUserCommand.cs @@ -6,12 +6,12 @@ using Bit.Core.Services; namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers; -public class DeleteOrganizationUserCommand : IDeleteOrganizationUserCommand +public class RemoveOrganizationUserCommand : IRemoveOrganizationUserCommand { private readonly IOrganizationUserRepository _organizationUserRepository; private readonly IOrganizationService _organizationService; - public DeleteOrganizationUserCommand( + public RemoveOrganizationUserCommand( IOrganizationUserRepository organizationUserRepository, IOrganizationService organizationService ) @@ -20,18 +20,18 @@ public class DeleteOrganizationUserCommand : IDeleteOrganizationUserCommand _organizationService = organizationService; } - public async Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, Guid? deletingUserId) + public async Task RemoveUserAsync(Guid organizationId, Guid organizationUserId, Guid? deletingUserId) { await ValidateDeleteUserAsync(organizationId, organizationUserId); - await _organizationService.DeleteUserAsync(organizationId, organizationUserId, deletingUserId); + await _organizationService.RemoveUserAsync(organizationId, organizationUserId, deletingUserId); } - public async Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, EventSystemUser eventSystemUser) + public async Task RemoveUserAsync(Guid organizationId, Guid organizationUserId, EventSystemUser eventSystemUser) { await ValidateDeleteUserAsync(organizationId, organizationUserId); - await _organizationService.DeleteUserAsync(organizationId, organizationUserId, eventSystemUser); + await _organizationService.RemoveUserAsync(organizationId, organizationUserId, eventSystemUser); } private async Task ValidateDeleteUserAsync(Guid organizationId, Guid organizationUserId) diff --git a/src/Core/AdminConsole/Services/IOrganizationService.cs b/src/Core/AdminConsole/Services/IOrganizationService.cs index 2162d4cbb..0780afb33 100644 --- a/src/Core/AdminConsole/Services/IOrganizationService.cs +++ b/src/Core/AdminConsole/Services/IOrganizationService.cs @@ -55,12 +55,12 @@ public interface IOrganizationService Guid confirmingUserId, IUserService userService); Task>> ConfirmUsersAsync_vNext(Guid organizationId, Dictionary keys, Guid confirmingUserId); - [Obsolete("IDeleteOrganizationUserCommand should be used instead. To be removed by EC-607.")] - Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, Guid? deletingUserId); - [Obsolete("IDeleteOrganizationUserCommand should be used instead. To be removed by EC-607.")] - Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, EventSystemUser systemUser); - Task DeleteUserAsync(Guid organizationId, Guid userId); - Task>> DeleteUsersAsync(Guid organizationId, + [Obsolete("IRemoveOrganizationUserCommand should be used instead. To be removed by EC-607.")] + Task RemoveUserAsync(Guid organizationId, Guid organizationUserId, Guid? deletingUserId); + [Obsolete("IRemoveOrganizationUserCommand should be used instead. To be removed by EC-607.")] + Task RemoveUserAsync(Guid organizationId, Guid organizationUserId, EventSystemUser systemUser); + Task RemoveUserAsync(Guid organizationId, Guid userId); + Task>> RemoveUsersAsync(Guid organizationId, IEnumerable organizationUserIds, Guid? deletingUserId); Task UpdateUserResetPasswordEnrollmentAsync(Guid organizationId, Guid userId, string resetPasswordKey, Guid? callingUserId); Task ImportAsync(Guid organizationId, IEnumerable groups, diff --git a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs index e77e5d8e6..8c8dafa5e 100644 --- a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs +++ b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs @@ -1591,15 +1591,15 @@ public class OrganizationService : IOrganizationService } } - [Obsolete("IDeleteOrganizationUserCommand should be used instead. To be removed by EC-607.")] - public async Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, Guid? deletingUserId) + [Obsolete("IRemoveOrganizationUserCommand should be used instead. To be removed by EC-607.")] + public async Task RemoveUserAsync(Guid organizationId, Guid organizationUserId, Guid? deletingUserId) { var orgUser = await RepositoryDeleteUserAsync(organizationId, organizationUserId, deletingUserId); await _eventService.LogOrganizationUserEventAsync(orgUser, EventType.OrganizationUser_Removed); } - [Obsolete("IDeleteOrganizationUserCommand should be used instead. To be removed by EC-607.")] - public async Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, + [Obsolete("IRemoveOrganizationUserCommand should be used instead. To be removed by EC-607.")] + public async Task RemoveUserAsync(Guid organizationId, Guid organizationUserId, EventSystemUser systemUser) { var orgUser = await RepositoryDeleteUserAsync(organizationId, organizationUserId, null); @@ -1640,7 +1640,7 @@ public class OrganizationService : IOrganizationService return orgUser; } - public async Task DeleteUserAsync(Guid organizationId, Guid userId) + public async Task RemoveUserAsync(Guid organizationId, Guid userId) { var orgUser = await _organizationUserRepository.GetByOrganizationAsync(organizationId, userId); if (orgUser == null) @@ -1662,7 +1662,7 @@ public class OrganizationService : IOrganizationService } } - public async Task>> DeleteUsersAsync(Guid organizationId, + public async Task>> RemoveUsersAsync(Guid organizationId, IEnumerable organizationUsersId, Guid? deletingUserId) { diff --git a/src/Core/AdminConsole/Services/Implementations/PolicyService.cs b/src/Core/AdminConsole/Services/Implementations/PolicyService.cs index 6d67cba70..1ffa2a0e2 100644 --- a/src/Core/AdminConsole/Services/Implementations/PolicyService.cs +++ b/src/Core/AdminConsole/Services/Implementations/PolicyService.cs @@ -293,7 +293,7 @@ public class PolicyService : IPolicyService "Policy could not be enabled. Non-compliant members will lose access to their accounts. Identify members without two-step login from the policies column in the members page."); } - await organizationService.DeleteUserAsync(policy.OrganizationId, orgUser.Id, + await organizationService.RemoveUserAsync(policy.OrganizationId, orgUser.Id, savingUserId); await _mailService.SendOrganizationUserRemovedForPolicyTwoStepEmailAsync( org.DisplayName(), orgUser.Email); @@ -309,7 +309,7 @@ public class PolicyService : IPolicyService && ou.OrganizationId != org.Id && ou.Status != OrganizationUserStatusType.Invited)) { - await organizationService.DeleteUserAsync(policy.OrganizationId, orgUser.Id, + await organizationService.RemoveUserAsync(policy.OrganizationId, orgUser.Id, savingUserId); await _mailService.SendOrganizationUserRemovedForPolicySingleOrgEmailAsync( org.DisplayName(), orgUser.Email); @@ -350,7 +350,7 @@ public class PolicyService : IPolicyService "Policy could not be enabled. Non-compliant members will lose access to their accounts. Identify members without two-step login from the policies column in the members page."); } - await organizationService.DeleteUserAsync(policy.OrganizationId, orgUser.Id, + await organizationService.RemoveUserAsync(policy.OrganizationId, orgUser.Id, savingUserId); await _mailService.SendOrganizationUserRemovedForPolicyTwoStepEmailAsync( org.DisplayName(), orgUser.Email); @@ -366,7 +366,7 @@ public class PolicyService : IPolicyService && ou.OrganizationId != org.Id && ou.Status != OrganizationUserStatusType.Invited)) { - await organizationService.DeleteUserAsync(policy.OrganizationId, orgUser.Id, + await organizationService.RemoveUserAsync(policy.OrganizationId, orgUser.Id, savingUserId); await _mailService.SendOrganizationUserRemovedForPolicySingleOrgEmailAsync( org.DisplayName(), orgUser.Email); diff --git a/src/Core/Auth/Services/Implementations/EmergencyAccessService.cs b/src/Core/Auth/Services/Implementations/EmergencyAccessService.cs index cb7fbd294..dffa9f65c 100644 --- a/src/Core/Auth/Services/Implementations/EmergencyAccessService.cs +++ b/src/Core/Auth/Services/Implementations/EmergencyAccessService.cs @@ -341,7 +341,7 @@ public class EmergencyAccessService : IEmergencyAccessService { if (o.Type != OrganizationUserType.Owner) { - await _organizationService.DeleteUserAsync(o.OrganizationId, grantor.Id); + await _organizationService.RemoveUserAsync(o.OrganizationId, grantor.Id); } } } diff --git a/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs b/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs index 12c4dd7e3..c954f561b 100644 --- a/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs +++ b/src/Core/OrganizationFeatures/OrganizationServiceCollectionExtensions.cs @@ -86,7 +86,7 @@ public static class OrganizationServiceCollectionExtensions private static void AddOrganizationUserCommands(this IServiceCollection services) { - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); } diff --git a/src/Core/Services/Implementations/UserService.cs b/src/Core/Services/Implementations/UserService.cs index cd1d58acd..51ce0af21 100644 --- a/src/Core/Services/Implementations/UserService.cs +++ b/src/Core/Services/Implementations/UserService.cs @@ -1298,7 +1298,7 @@ public class UserService : UserManager, IUserService, IDisposable var removeOrgUserTasks = twoFactorPolicies.Select(async p => { - await organizationService.DeleteUserAsync(p.OrganizationId, user.Id); + await organizationService.RemoveUserAsync(p.OrganizationId, user.Id); var organization = await _organizationRepository.GetByIdAsync(p.OrganizationId); await _mailService.SendOrganizationUserRemovedForPolicyTwoStepEmailAsync( organization.DisplayName(), user.Email); diff --git a/test/Api.Test/AdminConsole/Controllers/OrganizationsControllerTests.cs b/test/Api.Test/AdminConsole/Controllers/OrganizationsControllerTests.cs index c9a114fe7..156df1476 100644 --- a/test/Api.Test/AdminConsole/Controllers/OrganizationsControllerTests.cs +++ b/test/Api.Test/AdminConsole/Controllers/OrganizationsControllerTests.cs @@ -126,7 +126,7 @@ public class OrganizationsControllerTests : IDisposable Assert.Contains("Your organization's Single Sign-On settings prevent you from leaving.", exception.Message); - await _organizationService.DidNotReceiveWithAnyArgs().DeleteUserAsync(default, default); + await _organizationService.DidNotReceiveWithAnyArgs().RemoveUserAsync(default, default); } [Theory] @@ -155,8 +155,8 @@ public class OrganizationsControllerTests : IDisposable _ssoConfigRepository.GetByOrganizationIdAsync(orgId).Returns(ssoConfig); _userService.GetUserByPrincipalAsync(Arg.Any()).Returns(user); - await _organizationService.DeleteUserAsync(orgId, user.Id); - await _organizationService.Received(1).DeleteUserAsync(orgId, user.Id); + await _organizationService.RemoveUserAsync(orgId, user.Id); + await _organizationService.Received(1).RemoveUserAsync(orgId, user.Id); } [Theory, AutoData] diff --git a/test/Api.Test/Billing/Controllers/OrganizationsControllerTests.cs b/test/Api.Test/Billing/Controllers/OrganizationsControllerTests.cs index 1a28c344c..8fb648e89 100644 --- a/test/Api.Test/Billing/Controllers/OrganizationsControllerTests.cs +++ b/test/Api.Test/Billing/Controllers/OrganizationsControllerTests.cs @@ -117,8 +117,8 @@ public class OrganizationsControllerTests : IDisposable _ssoConfigRepository.GetByOrganizationIdAsync(orgId).Returns(ssoConfig); _userService.GetUserByPrincipalAsync(Arg.Any()).Returns(user); - await _organizationService.DeleteUserAsync(orgId, user.Id); - await _organizationService.Received(1).DeleteUserAsync(orgId, user.Id); + await _organizationService.RemoveUserAsync(orgId, user.Id); + await _organizationService.Received(1).RemoveUserAsync(orgId, user.Id); } [Theory, AutoData] diff --git a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/DeleteOrganizationUserCommandTests.cs b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/RemoveOrganizationUserCommandTests.cs similarity index 69% rename from test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/DeleteOrganizationUserCommandTests.cs rename to test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/RemoveOrganizationUserCommandTests.cs index 73302acc2..8d25f13cb 100644 --- a/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/DeleteOrganizationUserCommandTests.cs +++ b/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/RemoveOrganizationUserCommandTests.cs @@ -12,11 +12,11 @@ using Xunit; namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationUsers; [SutProviderCustomize] -public class DeleteOrganizationUserCommandTests +public class RemoveOrganizationUserCommandTests { [Theory] [BitAutoData] - public async Task DeleteUser_Success(SutProvider sutProvider, Guid organizationId, Guid organizationUserId) + public async Task RemoveUser_Success(SutProvider sutProvider, Guid organizationId, Guid organizationUserId) { sutProvider.GetDependency() .GetByIdAsync(organizationUserId) @@ -26,21 +26,21 @@ public class DeleteOrganizationUserCommandTests OrganizationId = organizationId }); - await sutProvider.Sut.DeleteUserAsync(organizationId, organizationUserId, null); + await sutProvider.Sut.RemoveUserAsync(organizationId, organizationUserId, null); - await sutProvider.GetDependency().Received(1).DeleteUserAsync(organizationId, organizationUserId, null); + await sutProvider.GetDependency().Received(1).RemoveUserAsync(organizationId, organizationUserId, null); } [Theory] [BitAutoData] - public async Task DeleteUser_NotFound_Throws(SutProvider sutProvider, Guid organizationId, Guid organizationUserId) + public async Task RemoveUser_NotFound_Throws(SutProvider sutProvider, Guid organizationId, Guid organizationUserId) { - await Assert.ThrowsAsync(async () => await sutProvider.Sut.DeleteUserAsync(organizationId, organizationUserId, null)); + await Assert.ThrowsAsync(async () => await sutProvider.Sut.RemoveUserAsync(organizationId, organizationUserId, null)); } [Theory] [BitAutoData] - public async Task DeleteUser_MismatchingOrganizationId_Throws(SutProvider sutProvider, Guid organizationId, Guid organizationUserId) + public async Task RemoveUser_MismatchingOrganizationId_Throws(SutProvider sutProvider, Guid organizationId, Guid organizationUserId) { sutProvider.GetDependency() .GetByIdAsync(organizationUserId) @@ -50,12 +50,12 @@ public class DeleteOrganizationUserCommandTests OrganizationId = Guid.NewGuid() }); - await Assert.ThrowsAsync(async () => await sutProvider.Sut.DeleteUserAsync(organizationId, organizationUserId, null)); + await Assert.ThrowsAsync(async () => await sutProvider.Sut.RemoveUserAsync(organizationId, organizationUserId, null)); } [Theory] [BitAutoData] - public async Task DeleteUser_WithEventSystemUser_Success(SutProvider sutProvider, Guid organizationId, Guid organizationUserId, EventSystemUser eventSystemUser) + public async Task RemoveUser_WithEventSystemUser_Success(SutProvider sutProvider, Guid organizationId, Guid organizationUserId, EventSystemUser eventSystemUser) { sutProvider.GetDependency() .GetByIdAsync(organizationUserId) @@ -65,8 +65,8 @@ public class DeleteOrganizationUserCommandTests OrganizationId = organizationId }); - await sutProvider.Sut.DeleteUserAsync(organizationId, organizationUserId, eventSystemUser); + await sutProvider.Sut.RemoveUserAsync(organizationId, organizationUserId, eventSystemUser); - await sutProvider.GetDependency().Received(1).DeleteUserAsync(organizationId, organizationUserId, eventSystemUser); + await sutProvider.GetDependency().Received(1).RemoveUserAsync(organizationId, organizationUserId, eventSystemUser); } } diff --git a/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs b/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs index 84dfca43f..5f0038a21 100644 --- a/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs +++ b/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs @@ -1182,7 +1182,7 @@ OrganizationUserInvite invite, SutProvider sutProvider) } [Theory, BitAutoData] - public async Task DeleteUser_InvalidUser(OrganizationUser organizationUser, OrganizationUser deletingUser, + public async Task RemoveUser_InvalidUser(OrganizationUser organizationUser, OrganizationUser deletingUser, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); @@ -1190,24 +1190,24 @@ OrganizationUserInvite invite, SutProvider sutProvider) organizationUserRepository.GetByIdAsync(organizationUser.Id).Returns(organizationUser); var exception = await Assert.ThrowsAsync( - () => sutProvider.Sut.DeleteUserAsync(Guid.NewGuid(), organizationUser.Id, deletingUser.UserId)); + () => sutProvider.Sut.RemoveUserAsync(Guid.NewGuid(), organizationUser.Id, deletingUser.UserId)); Assert.Contains("User not valid.", exception.Message); } [Theory, BitAutoData] - public async Task DeleteUser_RemoveYourself(OrganizationUser deletingUser, SutProvider sutProvider) + public async Task RemoveUser_RemoveYourself(OrganizationUser deletingUser, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); organizationUserRepository.GetByIdAsync(deletingUser.Id).Returns(deletingUser); var exception = await Assert.ThrowsAsync( - () => sutProvider.Sut.DeleteUserAsync(deletingUser.OrganizationId, deletingUser.Id, deletingUser.UserId)); + () => sutProvider.Sut.RemoveUserAsync(deletingUser.OrganizationId, deletingUser.Id, deletingUser.UserId)); Assert.Contains("You cannot remove yourself.", exception.Message); } [Theory, BitAutoData] - public async Task DeleteUser_NonOwnerRemoveOwner( + public async Task RemoveUser_NonOwnerRemoveOwner( [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser organizationUser, [OrganizationUser(type: OrganizationUserType.Admin)] OrganizationUser deletingUser, SutProvider sutProvider) @@ -1220,12 +1220,12 @@ OrganizationUserInvite invite, SutProvider sutProvider) currentContext.OrganizationAdmin(deletingUser.OrganizationId).Returns(true); var exception = await Assert.ThrowsAsync( - () => sutProvider.Sut.DeleteUserAsync(deletingUser.OrganizationId, organizationUser.Id, deletingUser.UserId)); + () => sutProvider.Sut.RemoveUserAsync(deletingUser.OrganizationId, organizationUser.Id, deletingUser.UserId)); Assert.Contains("Only owners can delete other owners.", exception.Message); } [Theory, BitAutoData] - public async Task DeleteUser_LastOwner( + public async Task RemoveUser_LastOwner( [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser organizationUser, OrganizationUser deletingUser, SutProvider sutProvider) @@ -1238,12 +1238,12 @@ OrganizationUserInvite invite, SutProvider sutProvider) .Returns(new[] { organizationUser }); var exception = await Assert.ThrowsAsync( - () => sutProvider.Sut.DeleteUserAsync(deletingUser.OrganizationId, organizationUser.Id, null)); + () => sutProvider.Sut.RemoveUserAsync(deletingUser.OrganizationId, organizationUser.Id, null)); Assert.Contains("Organization must have at least one confirmed owner.", exception.Message); } [Theory, BitAutoData] - public async Task DeleteUser_Success( + public async Task RemoveUser_Success( OrganizationUser organizationUser, [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser deletingUser, SutProvider sutProvider) @@ -1258,13 +1258,13 @@ OrganizationUserInvite invite, SutProvider sutProvider) .Returns(new[] { deletingUser, organizationUser }); currentContext.OrganizationOwner(deletingUser.OrganizationId).Returns(true); - await sutProvider.Sut.DeleteUserAsync(deletingUser.OrganizationId, organizationUser.Id, deletingUser.UserId); + await sutProvider.Sut.RemoveUserAsync(deletingUser.OrganizationId, organizationUser.Id, deletingUser.UserId); await sutProvider.GetDependency().Received(1).LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_Removed); } [Theory, BitAutoData] - public async Task DeleteUser_WithEventSystemUser_Success( + public async Task RemoveUser_WithEventSystemUser_Success( OrganizationUser organizationUser, [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser deletingUser, EventSystemUser eventSystemUser, SutProvider sutProvider) @@ -1279,13 +1279,13 @@ OrganizationUserInvite invite, SutProvider sutProvider) .Returns(new[] { deletingUser, organizationUser }); currentContext.OrganizationOwner(deletingUser.OrganizationId).Returns(true); - await sutProvider.Sut.DeleteUserAsync(deletingUser.OrganizationId, organizationUser.Id, eventSystemUser); + await sutProvider.Sut.RemoveUserAsync(deletingUser.OrganizationId, organizationUser.Id, eventSystemUser); await sutProvider.GetDependency().Received(1).LogOrganizationUserEventAsync(organizationUser, EventType.OrganizationUser_Removed, eventSystemUser); } [Theory, BitAutoData] - public async Task DeleteUsers_FilterInvalid(OrganizationUser organizationUser, OrganizationUser deletingUser, + public async Task RemoveUsers_FilterInvalid(OrganizationUser organizationUser, OrganizationUser deletingUser, SutProvider sutProvider) { var organizationUserRepository = sutProvider.GetDependency(); @@ -1294,12 +1294,12 @@ OrganizationUserInvite invite, SutProvider sutProvider) organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(organizationUsers); var exception = await Assert.ThrowsAsync( - () => sutProvider.Sut.DeleteUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId)); + () => sutProvider.Sut.RemoveUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId)); Assert.Contains("Users invalid.", exception.Message); } [Theory, BitAutoData] - public async Task DeleteUsers_RemoveYourself( + public async Task RemoveUsers_RemoveYourself( [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser orgUser, OrganizationUser deletingUser, SutProvider sutProvider) @@ -1310,12 +1310,12 @@ OrganizationUserInvite invite, SutProvider sutProvider) organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(organizationUsers); organizationUserRepository.GetManyByOrganizationAsync(default, default).ReturnsForAnyArgs(new[] { orgUser }); - var result = await sutProvider.Sut.DeleteUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId); + var result = await sutProvider.Sut.RemoveUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId); Assert.Contains("You cannot remove yourself.", result[0].Item2); } [Theory, BitAutoData] - public async Task DeleteUsers_NonOwnerRemoveOwner( + public async Task RemoveUsers_NonOwnerRemoveOwner( [OrganizationUser(type: OrganizationUserType.Admin)] OrganizationUser deletingUser, [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1, [OrganizationUser(OrganizationUserStatusType.Confirmed)] OrganizationUser orgUser2, @@ -1329,12 +1329,12 @@ OrganizationUserInvite invite, SutProvider sutProvider) organizationUserRepository.GetManyAsync(default).ReturnsForAnyArgs(organizationUsers); organizationUserRepository.GetManyByOrganizationAsync(default, default).ReturnsForAnyArgs(new[] { orgUser2 }); - var result = await sutProvider.Sut.DeleteUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId); + var result = await sutProvider.Sut.RemoveUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId); Assert.Contains("Only owners can delete other owners.", result[0].Item2); } [Theory, BitAutoData] - public async Task DeleteUsers_LastOwner( + public async Task RemoveUsers_LastOwner( [OrganizationUser(status: OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser orgUser, SutProvider sutProvider) { @@ -1346,12 +1346,12 @@ OrganizationUserInvite invite, SutProvider sutProvider) organizationUserRepository.GetManyByOrganizationAsync(orgUser.OrganizationId, OrganizationUserType.Owner).Returns(organizationUsers); var exception = await Assert.ThrowsAsync( - () => sutProvider.Sut.DeleteUsersAsync(orgUser.OrganizationId, organizationUserIds, null)); + () => sutProvider.Sut.RemoveUsersAsync(orgUser.OrganizationId, organizationUserIds, null)); Assert.Contains("Organization must have at least one confirmed owner.", exception.Message); } [Theory, BitAutoData] - public async Task DeleteUsers_Success( + public async Task RemoveUsers_Success( [OrganizationUser(OrganizationUserStatusType.Confirmed, OrganizationUserType.Owner)] OrganizationUser deletingUser, [OrganizationUser(type: OrganizationUserType.Owner)] OrganizationUser orgUser1, OrganizationUser orgUser2, SutProvider sutProvider) @@ -1368,7 +1368,7 @@ OrganizationUserInvite invite, SutProvider sutProvider) .Returns(new[] { deletingUser, orgUser1 }); currentContext.OrganizationOwner(deletingUser.OrganizationId).Returns(true); - await sutProvider.Sut.DeleteUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId); + await sutProvider.Sut.RemoveUsersAsync(deletingUser.OrganizationId, organizationUserIds, deletingUser.UserId); } [Theory, BitAutoData] diff --git a/test/Core.Test/AdminConsole/Services/PolicyServiceTests.cs b/test/Core.Test/AdminConsole/Services/PolicyServiceTests.cs index 989aa9067..fd7597a74 100644 --- a/test/Core.Test/AdminConsole/Services/PolicyServiceTests.cs +++ b/test/Core.Test/AdminConsole/Services/PolicyServiceTests.cs @@ -363,20 +363,20 @@ public class PolicyServiceTests await sutProvider.Sut.SaveAsync(policy, userService, organizationService, savingUserId); await organizationService.Received() - .DeleteUserAsync(policy.OrganizationId, orgUserDetailUserAcceptedWithout2FA.Id, savingUserId); + .RemoveUserAsync(policy.OrganizationId, orgUserDetailUserAcceptedWithout2FA.Id, savingUserId); await sutProvider.GetDependency().Received() .SendOrganizationUserRemovedForPolicyTwoStepEmailAsync(organization.DisplayName(), orgUserDetailUserAcceptedWithout2FA.Email); await organizationService.DidNotReceive() - .DeleteUserAsync(policy.OrganizationId, orgUserDetailUserInvited.Id, savingUserId); + .RemoveUserAsync(policy.OrganizationId, orgUserDetailUserInvited.Id, savingUserId); await sutProvider.GetDependency().DidNotReceive() .SendOrganizationUserRemovedForPolicyTwoStepEmailAsync(organization.DisplayName(), orgUserDetailUserInvited.Email); await organizationService.DidNotReceive() - .DeleteUserAsync(policy.OrganizationId, orgUserDetailUserAcceptedWith2FA.Id, savingUserId); + .RemoveUserAsync(policy.OrganizationId, orgUserDetailUserAcceptedWith2FA.Id, savingUserId); await sutProvider.GetDependency().DidNotReceive() .SendOrganizationUserRemovedForPolicyTwoStepEmailAsync(organization.DisplayName(), orgUserDetailUserAcceptedWith2FA.Email); await organizationService.DidNotReceive() - .DeleteUserAsync(policy.OrganizationId, orgUserDetailAdmin.Id, savingUserId); + .RemoveUserAsync(policy.OrganizationId, orgUserDetailAdmin.Id, savingUserId); await sutProvider.GetDependency().DidNotReceive() .SendOrganizationUserRemovedForPolicyTwoStepEmailAsync(organization.DisplayName(), orgUserDetailAdmin.Email); @@ -471,7 +471,7 @@ public class PolicyServiceTests Assert.Contains("Policy could not be enabled. Non-compliant members will lose access to their accounts. Identify members without two-step login from the policies column in the members page.", badRequestException.Message, StringComparison.OrdinalIgnoreCase); await organizationService.DidNotReceiveWithAnyArgs() - .DeleteUserAsync(organizationId: default, organizationUserId: default, deletingUserId: default); + .RemoveUserAsync(organizationId: default, organizationUserId: default, deletingUserId: default); await sutProvider.GetDependency().DidNotReceiveWithAnyArgs() .SendOrganizationUserRemovedForPolicyTwoStepEmailAsync(default, default);