Commit 26e2dff0 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'add-declarative-policy-class-option' into 'master'

Add declarative_policy_class to Declarative Policy

See merge request gitlab-org/gitlab!20132
parents 41049688 98d99c5e
......@@ -157,3 +157,18 @@ end
```
will include all rules from `ProjectPolicy`. The delegated conditions will be evaluated with the correct delegated subject, and will be sorted along with the regular rules in the policy. Note that only the relevant rules for a particular ability will actually be considered.
## Specifying Policy Class
You can also override the Policy used for a given subject:
```ruby
class Foo
def self.declarative_policy_class
'SomeOtherPolicy'
end
end
```
This will use & check permissions on the `SomeOtherPolicy` class rather than the usual calculated `FooPolicy` class.
......@@ -74,7 +74,14 @@ module DeclarativePolicy
next unless klass.name
begin
policy_class = "#{klass.name}Policy".constantize
klass_name =
if subject_class.respond_to?(:declarative_policy_class)
subject_class.declarative_policy_class
else
"#{klass.name}Policy"
end
policy_class = klass_name.constantize
# NOTE: the < operator here tests whether policy_class
# inherits from Base. We can't use #is_a? because that
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment