diff options
author | http://jneen.net/ <jneen@jneen.net> | 2016-08-09 14:16:38 -0700 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2016-08-09 14:16:38 -0700 |
commit | 176cde89806c7e1ca5efb909a36ad33222b003db (patch) | |
tree | e965b7cbaa10583337551122d9cab449ef5c6acb | |
parent | 0719b8ed1242e8506ee0e5797ec2ba1d61211ba8 (diff) | |
download | gitlab-ce-176cde89806c7e1ca5efb909a36ad33222b003db.tar.gz |
move cached_allowed and make almost everything private
-rw-r--r-- | app/models/ability.rb | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb index 68d926bfbbd..93d14e5b139 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -1,15 +1,11 @@ class Ability class << self - def cached_allowed(user, subject) - user_key = user ? user.id : 'anonymous' - key = "/ability/#{user_key}/#{subject.object_id}" - RequestStore[key] ||= Set.new(allowed(user, subject)) - end - def allowed?(user, action, subject) cached_allowed(user, subject).include?(action) end + private + def allowed(user, subject) return anonymous_abilities(user, subject) if user.nil? return [] unless user.is_a?(User) @@ -18,6 +14,12 @@ class Ability abilities_by_subject_class(user: user, subject: subject) end + def cached_allowed(user, subject) + user_key = user ? user.id : 'anonymous' + key = "/ability/#{user_key}/#{subject.object_id}" + RequestStore[key] ||= Set.new(allowed(user, subject)) + end + def abilities_by_subject_class(user:, subject:) case subject when CommitStatus then commit_status_abilities(user, subject) @@ -575,8 +577,6 @@ class Ability [:read_user] end - private - def restricted_public_level? current_application_settings.restricted_visibility_levels.include?(Gitlab::VisibilityLevel::PUBLIC) end |