add passing property to PolicyEngine
This commit is contained in:
parent
64033031b1
commit
296d4f691a
|
@ -66,7 +66,7 @@ class AuthenticationView(UserPassesTestMixin, View):
|
||||||
for factor in _all_factors:
|
for factor in _all_factors:
|
||||||
policy_engine = PolicyEngine(factor.policies.all())
|
policy_engine = PolicyEngine(factor.policies.all())
|
||||||
policy_engine.for_user(self.pending_user).with_request(request).build()
|
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))
|
self.pending_factors.append((factor.uuid.hex, factor.type))
|
||||||
# Read and instantiate factor from session
|
# Read and instantiate factor from session
|
||||||
factor_uuid, factor_class = None, None
|
factor_uuid, factor_class = None, None
|
||||||
|
|
|
@ -79,3 +79,8 @@ class PolicyEngine:
|
||||||
if not passing:
|
if not passing:
|
||||||
return False, messages
|
return False, messages
|
||||||
return True, messages
|
return True, messages
|
||||||
|
|
||||||
|
@property
|
||||||
|
def passing(self):
|
||||||
|
"""Only get true/false if user passes"""
|
||||||
|
return self.result[0]
|
||||||
|
|
|
@ -17,6 +17,6 @@ def user_factors(context):
|
||||||
_link = factor.has_user_settings()
|
_link = factor.has_user_settings()
|
||||||
policy_engine = PolicyEngine(factor.policies.all())
|
policy_engine = PolicyEngine(factor.policies.all())
|
||||||
policy_engine.for_user(user).with_request(context.get('request')).build()
|
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)
|
matching_factors.append(_link)
|
||||||
return matching_factors
|
return matching_factors
|
||||||
|
|
|
@ -105,7 +105,7 @@ class LoginProcessView(ProviderMixin, LoginRequiredMixin, View):
|
||||||
"""Check if user has access to application"""
|
"""Check if user has access to application"""
|
||||||
policy_engine = PolicyEngine(self.provider.application.policies.all())
|
policy_engine = PolicyEngine(self.provider.application.policies.all())
|
||||||
policy_engine.for_user(self.request.user).with_request(self.request).build()
|
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):
|
def get(self, request, application):
|
||||||
"""Handle get request, i.e. render form"""
|
"""Handle get request, i.e. render form"""
|
||||||
|
|
Reference in New Issue