mirror of
https://github.com/bitwarden/server.git
synced 2025-06-07 19:50:32 -05:00
46 lines
1.7 KiB
C#
46 lines
1.7 KiB
C#
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers.Interfaces;
|
|
using Bit.Core.Enums;
|
|
using Bit.Core.Exceptions;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Core.Services;
|
|
|
|
namespace Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers;
|
|
|
|
public class DeleteOrganizationUserCommand : IDeleteOrganizationUserCommand
|
|
{
|
|
private readonly IOrganizationUserRepository _organizationUserRepository;
|
|
private readonly IOrganizationService _organizationService;
|
|
|
|
public DeleteOrganizationUserCommand(
|
|
IOrganizationUserRepository organizationUserRepository,
|
|
IOrganizationService organizationService
|
|
)
|
|
{
|
|
_organizationUserRepository = organizationUserRepository;
|
|
_organizationService = organizationService;
|
|
}
|
|
|
|
public async Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, Guid? deletingUserId)
|
|
{
|
|
await ValidateDeleteUserAsync(organizationId, organizationUserId);
|
|
|
|
await _organizationService.DeleteUserAsync(organizationId, organizationUserId, deletingUserId);
|
|
}
|
|
|
|
public async Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, EventSystemUser eventSystemUser)
|
|
{
|
|
await ValidateDeleteUserAsync(organizationId, organizationUserId);
|
|
|
|
await _organizationService.DeleteUserAsync(organizationId, organizationUserId, eventSystemUser);
|
|
}
|
|
|
|
private async Task ValidateDeleteUserAsync(Guid organizationId, Guid organizationUserId)
|
|
{
|
|
var orgUser = await _organizationUserRepository.GetByIdAsync(organizationUserId);
|
|
if (orgUser == null || orgUser.OrganizationId != organizationId)
|
|
{
|
|
throw new NotFoundException("User not found.");
|
|
}
|
|
}
|
|
}
|