mirror of
https://github.com/bitwarden/mobile
synced 2025-12-10 05:13:31 +00:00
Move policy checks inside PolicyService (#1533)
* Move policy checks inside PolicyService * Remove leftover code * Remove duplicate code * Reorder code for consistency
This commit is contained in:
@@ -198,29 +198,30 @@ namespace Bit.Core.Services
|
||||
return new Tuple<ResetPasswordPolicyOptions, bool>(resetPasswordPolicyOptions, policy != null);
|
||||
}
|
||||
|
||||
public async Task<bool> PolicyAppliesToUser(PolicyType policyType, Func<Policy, bool> policyFilter = null)
|
||||
public async Task<bool> PolicyAppliesToUser(PolicyType policyType, Func<Policy, bool> policyFilter)
|
||||
{
|
||||
if (policyFilter == null) {
|
||||
policyFilter = _ => true;
|
||||
}
|
||||
|
||||
var policies = await GetAll(policyType);
|
||||
var organizations = await _userService.GetAllOrganizationAsync();
|
||||
|
||||
var filteredPolicies = policies.Where(p =>
|
||||
p.Enabled &&
|
||||
p.Type == policyType &&
|
||||
policyFilter(p))
|
||||
.Select(p => p.OrganizationId);
|
||||
IEnumerable<Policy> filteredPolicies;
|
||||
|
||||
var policySet = filteredPolicies.Distinct();
|
||||
if (policyFilter != null)
|
||||
{
|
||||
filteredPolicies = policies.Where(p => p.Enabled && policyFilter(p));
|
||||
}
|
||||
else
|
||||
{
|
||||
filteredPolicies = policies.Where(p => p.Enabled);
|
||||
}
|
||||
|
||||
var policySet = new HashSet<string>(filteredPolicies.Select(p => p.OrganizationId));
|
||||
|
||||
return organizations.Any(o =>
|
||||
o.Enabled &&
|
||||
o.Status >= OrganizationUserStatusType.Accepted &&
|
||||
o.UsePolicies &&
|
||||
!o.IsExemptFromPolicies &&
|
||||
policySet.Distinct().Contains(o.Id));
|
||||
!o.isExemptFromPolicies &&
|
||||
policySet.Contains(o.Id));
|
||||
}
|
||||
|
||||
public int? GetPolicyInt(Policy policy, string key)
|
||||
|
||||
Reference in New Issue
Block a user