diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /lib/declarative_policy/base.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
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 |