1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-01 13:43:23 +01:00

Rewrite RequiredPolicies implementation to use linq

This commit is contained in:
Thomas Rittson 2024-10-04 12:37:39 +10:00
parent e93753813d
commit 8ae2f6c655
No known key found for this signature in database
GPG Key ID: CDDDA03861C35E27

View File

@ -60,13 +60,15 @@ public class PolicyServicevNext : IPolicyServicevNext
// If enabling this policy - check that all policy requirements are satisfied // If enabling this policy - check that all policy requirements are satisfied
if (currentPolicy is not { Enabled: true } && policy.Enabled) if (currentPolicy is not { Enabled: true } && policy.Enabled)
{ {
foreach (var requiredPolicyType in policyDefinition.RequiredPolicies) var missingRequiredPolicyTypes = policyDefinition.RequiredPolicies
.Where(requiredPolicyType =>
allSavedPolicies.SingleOrDefault(p => p.Type == requiredPolicyType) is not { Enabled: true })
.ToList();
if (missingRequiredPolicyTypes.Count != 0)
{ {
if (allSavedPolicies.SingleOrDefault(p => p.Type == requiredPolicyType) is not { Enabled: true }) // TODO: would be better to reference the name instead of the enum
{ throw new BadRequestException("Policy requires PolicyType " + missingRequiredPolicyTypes.First() + " to be enabled first.");
// TODO: would be better to reference the name instead of the enum
throw new BadRequestException("Policy requires PolicyType " + requiredPolicyType + " to be enabled first.");
}
} }
} }