diff options
author | http://jneen.net/ <jneen@jneen.net> | 2016-08-08 10:07:15 -0700 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2016-08-08 13:40:24 -0700 |
commit | 2a3db599b84b5eb14e4b2c01eb2b8cad4331b2bb (patch) | |
tree | acce75d4a563b20dcd5a6bb9ac9c2c2f112d8901 | |
parent | 59ce1af53b8d25d1b4ae8b6e59f069c5147ca572 (diff) | |
download | gitlab-ce-2a3db599b84b5eb14e4b2c01eb2b8cad4331b2bb.tar.gz |
remove six, and use a Set instead
-rw-r--r-- | Gemfile | 3 | ||||
-rw-r--r-- | Gemfile.lock | 2 | ||||
-rw-r--r-- | app/models/ability.rb | 17 | ||||
-rw-r--r-- | lib/api/helpers.rb | 6 | ||||
-rw-r--r-- | spec/models/members/project_member_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/note_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/project_security_spec.rb | 3 |
7 files changed, 16 insertions, 21 deletions
@@ -97,9 +97,6 @@ gem 'fog-rackspace', '~> 0.1.1' # for aws storage gem 'unf', '~> 0.1.4' -# Authorization -gem 'six', '~> 0.2.0' - # Seed data gem 'seed-fu', '~> 2.3.5' diff --git a/Gemfile.lock b/Gemfile.lock index 870f9397b9e..594ce36ab8b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -682,7 +682,6 @@ GEM rack (~> 1.5) rack-protection (~> 1.4) tilt (>= 1.3, < 3) - six (0.2.0) slack-notifier (1.2.1) slop (3.6.0) spinach (0.8.10) @@ -964,7 +963,6 @@ DEPENDENCIES sidekiq-cron (~> 0.4.0) simplecov (= 0.12.0) sinatra (~> 1.4.4) - six (~> 0.2.0) slack-notifier (~> 1.2.0) spinach-rails (~> 0.2.1) spinach-rerun-reporter (~> 0.0.2) diff --git a/app/models/ability.rb b/app/models/ability.rb index d9113ffd99a..6822274defa 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -1,5 +1,15 @@ 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 + # rubocop: disable Metrics/CyclomaticComplexity def allowed(user, subject) return anonymous_abilities(user, subject) if user.nil? @@ -570,11 +580,8 @@ class Ability end def abilities - @abilities ||= begin - abilities = Six.new - abilities << self - abilities - end + warn 'Ability.abilities is deprecated, use Ability.allowed?(user, action, subject) instead' + self end private diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 130509cdad6..91113d69d6e 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -400,11 +400,7 @@ module API end def abilities - @abilities ||= begin - abilities = Six.new - abilities << Ability - abilities - end + Ability end def secret_token diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb index e7c0c506463..c8605a444aa 100644 --- a/spec/models/members/project_member_spec.rb +++ b/spec/models/members/project_member_spec.rb @@ -70,8 +70,7 @@ describe ProjectMember, models: true do describe :import_team do before do - @abilities = Six.new - @abilities << Ability + @abilities = Ability @project_1 = create :project @project_2 = create :project diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 1243f5420a7..b30fd9855b7 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -83,8 +83,7 @@ describe Note, models: true do @u1 = create(:user) @u2 = create(:user) @u3 = create(:user) - @abilities = Six.new - @abilities << Ability + @abilities = Ability end describe 'read' do diff --git a/spec/models/project_security_spec.rb b/spec/models/project_security_spec.rb index 2142c7c13ef..7dfaf6a7317 100644 --- a/spec/models/project_security_spec.rb +++ b/spec/models/project_security_spec.rb @@ -10,8 +10,7 @@ describe Project, models: true do @u3 = create(:user) @u4 = @p1.owner - @abilities = Six.new - @abilities << Ability + @abilities = Ability end let(:guest_actions) { Ability.project_guest_rules } |