diff options
author | http://jneen.net/ <jneen@jneen.net> | 2017-02-28 13:08:07 -0800 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2017-03-09 11:49:52 -0800 |
commit | 846e581732e291f8927d04a5b1b40fe8f2688885 (patch) | |
tree | 50e0a538e26ac47f37ba68f93898185608c09096 /app/policies/base_policy.rb | |
parent | 130fd255bc0735d4175f2db2770a9092882fa3a4 (diff) | |
download | gitlab-ce-846e581732e291f8927d04a5b1b40fe8f2688885.tar.gz |
use a magic default :global symbol instead of nil
to make sure we mean the global permissions
Diffstat (limited to 'app/policies/base_policy.rb')
-rw-r--r-- | app/policies/base_policy.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/app/policies/base_policy.rb b/app/policies/base_policy.rb index e07b144355a..8890409d056 100644 --- a/app/policies/base_policy.rb +++ b/app/policies/base_policy.rb @@ -12,6 +12,10 @@ class BasePolicy new(Set.new, Set.new) end + def self.none + empty.freeze + end + def can?(ability) @can_set.include?(ability) && !@cannot_set.include?(ability) end @@ -49,7 +53,8 @@ class BasePolicy end def self.class_for(subject) - return GlobalPolicy if subject.nil? + return GlobalPolicy if subject == :global + raise ArgumentError, 'no policy for nil' if subject.nil? if subject.class.try(:presenter?) subject = subject.subject @@ -79,7 +84,7 @@ class BasePolicy end def abilities - return RuleSet.empty if @user && @user.blocked? + return RuleSet.none if @user && @user.blocked? return anonymous_abilities if @user.nil? collect_rules { rules } end |