add passing property to PolicyEngine

This commit is contained in:
Jens Langhammer 2019-03-08 19:49:53 +01:00
parent 64033031b1
commit 296d4f691a
4 changed files with 8 additions and 3 deletions

View File

@ -66,7 +66,7 @@ class AuthenticationView(UserPassesTestMixin, View):
for factor in _all_factors:
policy_engine = PolicyEngine(factor.policies.all())
policy_engine.for_user(self.pending_user).with_request(request).build()
if policy_engine.result[0]:
if policy_engine.passing:
self.pending_factors.append((factor.uuid.hex, factor.type))
# Read and instantiate factor from session
factor_uuid, factor_class = None, None

View File

@ -79,3 +79,8 @@ class PolicyEngine:
if not passing:
return False, messages
return True, messages
@property
def passing(self):
"""Only get true/false if user passes"""
return self.result[0]

View File

@ -17,6 +17,6 @@ def user_factors(context):
_link = factor.has_user_settings()
policy_engine = PolicyEngine(factor.policies.all())
policy_engine.for_user(user).with_request(context.get('request')).build()
if policy_engine.result[0] and _link:
if policy_engine.passing and _link:
matching_factors.append(_link)
return matching_factors

View File

@ -105,7 +105,7 @@ class LoginProcessView(ProviderMixin, LoginRequiredMixin, View):
"""Check if user has access to application"""
policy_engine = PolicyEngine(self.provider.application.policies.all())
policy_engine.for_user(self.request.user).with_request(self.request).build()
return policy_engine.result
return policy_engine.passing
def get(self, request, application):
"""Handle get request, i.e. render form"""