diff --git a/cinder/context.py b/cinder/context.py index a7a6544638a..6d6274c8304 100644 --- a/cinder/context.py +++ b/cinder/context.py @@ -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() diff --git a/cinder/policy.py b/cinder/policy.py index a2a09792744..9a94d075ca1 100644 --- a/cinder/policy.py +++ b/cinder/policy.py @@ -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)