mirror of
https://github.com/bitwarden/server
synced 2026-01-11 21:13:50 +00:00
* Remove gathering and reporting of ReferenceEvents * Fix test that relied on reference events throwing --------- Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
58 lines
2.2 KiB
C#
58 lines
2.2 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations.Interfaces;
|
|
using Bit.Core.Auth.Enums;
|
|
using Bit.Core.Auth.Repositories;
|
|
using Bit.Core.Exceptions;
|
|
using Bit.Core.Repositories;
|
|
using Bit.Core.Services;
|
|
|
|
namespace Bit.Core.AdminConsole.OrganizationFeatures.Organizations;
|
|
|
|
public class OrganizationDeleteCommand : IOrganizationDeleteCommand
|
|
{
|
|
private readonly IApplicationCacheService _applicationCacheService;
|
|
private readonly IOrganizationRepository _organizationRepository;
|
|
private readonly IPaymentService _paymentService;
|
|
private readonly ISsoConfigRepository _ssoConfigRepository;
|
|
|
|
public OrganizationDeleteCommand(
|
|
IApplicationCacheService applicationCacheService,
|
|
IOrganizationRepository organizationRepository,
|
|
IPaymentService paymentService,
|
|
ISsoConfigRepository ssoConfigRepository)
|
|
{
|
|
_applicationCacheService = applicationCacheService;
|
|
_organizationRepository = organizationRepository;
|
|
_paymentService = paymentService;
|
|
_ssoConfigRepository = ssoConfigRepository;
|
|
}
|
|
|
|
public async Task DeleteAsync(Organization organization)
|
|
{
|
|
await ValidateDeleteOrganizationAsync(organization);
|
|
|
|
if (!string.IsNullOrWhiteSpace(organization.GatewaySubscriptionId))
|
|
{
|
|
try
|
|
{
|
|
var eop = !organization.ExpirationDate.HasValue ||
|
|
organization.ExpirationDate.Value >= DateTime.UtcNow;
|
|
await _paymentService.CancelSubscriptionAsync(organization, eop);
|
|
}
|
|
catch (GatewayException) { }
|
|
}
|
|
|
|
await _organizationRepository.DeleteAsync(organization);
|
|
await _applicationCacheService.DeleteOrganizationAbilityAsync(organization.Id);
|
|
}
|
|
|
|
private async Task ValidateDeleteOrganizationAsync(Organization organization)
|
|
{
|
|
var ssoConfig = await _ssoConfigRepository.GetByOrganizationIdAsync(organization.Id);
|
|
if (ssoConfig?.GetData()?.MemberDecryptionType == MemberDecryptionType.KeyConnector)
|
|
{
|
|
throw new BadRequestException("You cannot delete an Organization that is using Key Connector.");
|
|
}
|
|
}
|
|
}
|