mirror of
https://github.com/bitwarden/server.git
synced 2025-05-06 12:12:18 -05:00
[PM-15621] Ready for app code review.
This commit is contained in:
parent
38405efc92
commit
dcc2cc7387
@ -23,6 +23,7 @@ using Bit.Core.Enums;
|
|||||||
using Bit.Core.Exceptions;
|
using Bit.Core.Exceptions;
|
||||||
using Bit.Core.Models.Business;
|
using Bit.Core.Models.Business;
|
||||||
using Bit.Core.Models.Commands;
|
using Bit.Core.Models.Commands;
|
||||||
|
using Bit.Core.Models.Data.Organizations;
|
||||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||||
using Bit.Core.OrganizationFeatures.OrganizationSubscriptions.Interface;
|
using Bit.Core.OrganizationFeatures.OrganizationSubscriptions.Interface;
|
||||||
using Bit.Core.OrganizationFeatures.OrganizationUsers.Interfaces;
|
using Bit.Core.OrganizationFeatures.OrganizationUsers.Interfaces;
|
||||||
@ -595,6 +596,12 @@ public class OrganizationUsersController : Controller
|
|||||||
|
|
||||||
var result = await _deleteManagedOrganizationUserAccountCommand.DeleteUserAsync(orgId, id, currentUser.Id);
|
var result = await _deleteManagedOrganizationUserAccountCommand.DeleteUserAsync(orgId, id, currentUser.Id);
|
||||||
|
|
||||||
|
if (result is Success<DeleteUserResponse>)
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return result.MapToActionResultWithSingleErrorMessage();
|
return result.MapToActionResultWithSingleErrorMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ using Bit.Core.Services;
|
|||||||
using Bit.Core.Tools.Enums;
|
using Bit.Core.Tools.Enums;
|
||||||
using Bit.Core.Tools.Models.Business;
|
using Bit.Core.Tools.Models.Business;
|
||||||
using Bit.Core.Tools.Services;
|
using Bit.Core.Tools.Services;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
|
||||||
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers;
|
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers;
|
||||||
@ -27,6 +28,7 @@ public class DeleteManagedOrganizationUserAccountCommand : IDeleteManagedOrganiz
|
|||||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||||
private readonly IUserRepository _userRepository;
|
private readonly IUserRepository _userRepository;
|
||||||
private readonly ICurrentContext _currentContext;
|
private readonly ICurrentContext _currentContext;
|
||||||
|
private readonly ILogger<DeleteManagedOrganizationUserAccountCommand> _logger;
|
||||||
private readonly IReferenceEventService _referenceEventService;
|
private readonly IReferenceEventService _referenceEventService;
|
||||||
private readonly IPushNotificationService _pushService;
|
private readonly IPushNotificationService _pushService;
|
||||||
|
|
||||||
@ -38,6 +40,7 @@ public class DeleteManagedOrganizationUserAccountCommand : IDeleteManagedOrganiz
|
|||||||
IOrganizationUserRepository organizationUserRepository,
|
IOrganizationUserRepository organizationUserRepository,
|
||||||
IUserRepository userRepository,
|
IUserRepository userRepository,
|
||||||
ICurrentContext currentContext,
|
ICurrentContext currentContext,
|
||||||
|
ILogger<DeleteManagedOrganizationUserAccountCommand> logger,
|
||||||
IReferenceEventService referenceEventService,
|
IReferenceEventService referenceEventService,
|
||||||
IPushNotificationService pushService)
|
IPushNotificationService pushService)
|
||||||
{
|
{
|
||||||
@ -48,6 +51,7 @@ public class DeleteManagedOrganizationUserAccountCommand : IDeleteManagedOrganiz
|
|||||||
_organizationUserRepository = organizationUserRepository;
|
_organizationUserRepository = organizationUserRepository;
|
||||||
_userRepository = userRepository;
|
_userRepository = userRepository;
|
||||||
_currentContext = currentContext;
|
_currentContext = currentContext;
|
||||||
|
_logger = logger;
|
||||||
_referenceEventService = referenceEventService;
|
_referenceEventService = referenceEventService;
|
||||||
_pushService = pushService;
|
_pushService = pushService;
|
||||||
}
|
}
|
||||||
@ -184,9 +188,9 @@ public class DeleteManagedOrganizationUserAccountCommand : IDeleteManagedOrganiz
|
|||||||
{
|
{
|
||||||
await _userService.CancelPremiumAsync(user);
|
await _userService.CancelPremiumAsync(user);
|
||||||
}
|
}
|
||||||
catch (GatewayException)
|
catch (GatewayException exception)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning(exception, "Failed to cancel the user's premium.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ public class DeleteManagedOrganizationUserAccountValidator(
|
|||||||
|
|
||||||
private static ValidationResult<DeleteUserValidationRequest> PreventSelfDeletion(DeleteUserValidationRequest request)
|
private static ValidationResult<DeleteUserValidationRequest> PreventSelfDeletion(DeleteUserValidationRequest request)
|
||||||
{
|
{
|
||||||
if (request.OrganizationUser?.UserId == request.DeletingUserId)
|
if (request.OrganizationUser.UserId == request.DeletingUserId)
|
||||||
{
|
{
|
||||||
return new Invalid<DeleteUserValidationRequest>(new BadRequestError<DeleteUserValidationRequest>("You cannot delete yourself.", request));
|
return new Invalid<DeleteUserValidationRequest>(new BadRequestError<DeleteUserValidationRequest>("You cannot delete yourself.", request));
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ public class DeleteManagedOrganizationUserAccountValidator(
|
|||||||
|
|
||||||
private async Task<ValidationResult<DeleteUserValidationRequest>> EnsureOnlyOwnersCanDeleteOwnersAsync(DeleteUserValidationRequest request)
|
private async Task<ValidationResult<DeleteUserValidationRequest>> EnsureOnlyOwnersCanDeleteOwnersAsync(DeleteUserValidationRequest request)
|
||||||
{
|
{
|
||||||
if (request.OrganizationUser?.Type != OrganizationUserType.Owner)
|
if (request.OrganizationUser.Type != OrganizationUserType.Owner)
|
||||||
{
|
{
|
||||||
return new Valid<DeleteUserValidationRequest>(request);
|
return new Valid<DeleteUserValidationRequest>(request);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user