Merge "Use to_policy_values for enforcing policy"

This commit is contained in:
Jenkins 2016-09-14 22:57:37 +00:00 committed by Gerrit Code Review
commit 5aa16450cd
2 changed files with 10 additions and 1 deletions

View File

@ -145,6 +145,13 @@ class RequestContext(context.RequestContext):
user_domain=values.get('user_domain'),
project_domain=values.get('project_domain'))
def to_policy_values(self):
policy = super(RequestContext, self).to_policy_values()
policy['is_admin'] = self.is_admin
return policy
def elevated(self, read_deleted=None, overwrite=False):
"""Return a version of this context with admin flag set."""
context = self.deepcopy()

View File

@ -64,7 +64,9 @@ def enforce(context, action, target):
"""
init()
return _ENFORCER.enforce(action, target, context.to_dict(),
return _ENFORCER.enforce(action,
target,
context.to_policy_values(),
do_raise=True,
exc=exception.PolicyNotAuthorized,
action=action)