diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 21:08:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 21:08:58 +0300 |
commit | ed16c9434ed73f68f84935b3b283baeacc632200 (patch) | |
tree | 4a75983976d001d9bb275a345f9f5fcf40685c6b /lib/declarative_policy/base.rb | |
parent | 874c603d7a21724885ed24f15f457146aa1497c2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/declarative_policy/base.rb')
-rw-r--r-- | lib/declarative_policy/base.rb | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/declarative_policy/base.rb b/lib/declarative_policy/base.rb index cd6e1606f22..4af0251b990 100644 --- a/lib/declarative_policy/base.rb +++ b/lib/declarative_policy/base.rb @@ -117,6 +117,23 @@ module DeclarativePolicy own_delegations[name] = delegation_block end + # Declare that the given abilities should not be read from delegates. + # + # This is useful if you have an ability that you want to define + # differently in a policy than in a delegated policy, but still want to + # delegate all other abilities. + # + # example: + # + # delegate { @subect.parent } + # + # overrides :drive_car, :watch_tv + # + def overrides(*names) + @overrides ||= [].to_set + @overrides.merge(names) + end + # Declares a rule, constructed using RuleDsl, and returns # a PolicyDsl which is used for registering the rule with # this class. PolicyDsl will call back into Base.enable_when, @@ -265,9 +282,13 @@ module DeclarativePolicy @runners ||= {} @runners[ability] ||= begin - delegated_runners = delegated_policies.values.compact.map { |p| p.runner(ability) } own_runner = Runner.new(own_steps(ability)) - delegated_runners.inject(own_runner, &:merge_runner) + if self.class.overrides.include?(ability) + own_runner + else + delegated_runners = delegated_policies.values.compact.map { |p| p.runner(ability) } + delegated_runners.inject(own_runner, &:merge_runner) + end end end |