Skip to content

Commit

Permalink
Added BadRequestException to stop disabling of SingleOrg policy when …
Browse files Browse the repository at this point in the history
…org still has verified domains.
  • Loading branch information
jrmccannon committed Oct 15, 2024
1 parent 5dd339c commit 38b6b35
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Core/AdminConsole/Services/Implementations/PolicyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class PolicyService : IPolicyService
private readonly ISsoConfigRepository _ssoConfigRepository;
private readonly IMailService _mailService;
private readonly GlobalSettings _globalSettings;
private readonly IOrganizationDomainService _organizationDomainService;
private readonly ITwoFactorIsEnabledQuery _twoFactorIsEnabledQuery;

public PolicyService(
Expand All @@ -36,6 +37,7 @@ public PolicyService(
ISsoConfigRepository ssoConfigRepository,
IMailService mailService,
GlobalSettings globalSettings,
IOrganizationDomainService organizationDomainService,
ITwoFactorIsEnabledQuery twoFactorIsEnabledQuery)
{
_applicationCacheService = applicationCacheService;
Expand All @@ -46,6 +48,7 @@ public PolicyService(
_ssoConfigRepository = ssoConfigRepository;
_mailService = mailService;
_globalSettings = globalSettings;
_organizationDomainService = organizationDomainService;
_twoFactorIsEnabledQuery = twoFactorIsEnabledQuery;
}

Expand Down Expand Up @@ -212,6 +215,7 @@ private async Task HandleDependentPoliciesAsync(Policy policy, Organization org)
case PolicyType.SingleOrg:
if (!policy.Enabled)
{
await HasNoVerifiedDomainsAsync(org);
await RequiredBySsoAsync(org);
await RequiredByVaultTimeoutAsync(org);
await RequiredByKeyConnectorAsync(org);
Expand Down Expand Up @@ -252,6 +256,14 @@ private async Task HandleDependentPoliciesAsync(Policy policy, Organization org)
}
}

private async Task HasNoVerifiedDomainsAsync(Organization org)
{
if (await _organizationDomainService.HasVerifiedDomainsAsync(org.Id))
{
throw new BadRequestException("Organization still has verified domains.");
}
}

private async Task SetPolicyConfiguration(Policy policy)
{
await _policyRepository.UpsertAsync(policy);
Expand Down

0 comments on commit 38b6b35

Please sign in to comment.