summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhttp://jneen.net/ <jneen@jneen.net>2016-08-08 10:07:15 -0700
committerhttp://jneen.net/ <jneen@jneen.net>2016-08-30 11:32:55 -0700
commit99ee86206e3e19dd93910a4e7a3a5b6e3a7add9a (patch)
tree75b35d1341e3b9d4d97088f903a67dcc84948d16
parent0f4df86a5e559b9c15f07b43edad829928f59e87 (diff)
downloadgitlab-ce-99ee86206e3e19dd93910a4e7a3a5b6e3a7add9a.tar.gz
remove six, and use a Set instead
-rw-r--r--Gemfile3
-rw-r--r--Gemfile.lock2
-rw-r--r--app/models/ability.rb25
-rw-r--r--lib/api/helpers.rb6
-rw-r--r--spec/models/members/project_member_spec.rb3
-rw-r--r--spec/models/note_spec.rb3
6 files changed, 22 insertions, 20 deletions
diff --git a/Gemfile b/Gemfile
index 194379dd687..96841013815 100644
--- a/Gemfile
+++ b/Gemfile
@@ -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 0c28975060c..1d0fcfd3c3a 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -683,7 +683,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)
@@ -954,7 +953,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 fcd7740d79f..622f481a4fc 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -1,7 +1,23 @@
class Ability
class << self
+
+ end
+
+ def allowed?(user, action, subject)
+ allowed(user, subject).include?(action)
+ end
+
def allowed(user, subject)
- return anonymous_abilities(user, subject) if user.nil?
+ return uncached_allowed(user, subject) unless RequestStore.active?
+
+ user_key = user ? user.id : 'anonymous'
+ subject_key = subject ? "#{subject.class.name}/#{subject.id}" : 'global'
+ key = "/ability/#{user_key}/#{subject_key}"
+ RequestStore[key] ||= Set.new(uncached_allowed(user, subject)).freeze
+ end
+
+ def uncached_allowed(user, subject)
+ return anonymous_abilities(subject) if user.nil?
return [] unless user.is_a?(User)
return [] if user.blocked?
@@ -586,11 +602,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 da4b1bf9902..1afca5fe2e8 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -409,11 +409,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 913d74645a7..c2bf48da44e 100644
--- a/spec/models/members/project_member_spec.rb
+++ b/spec/models/members/project_member_spec.rb
@@ -71,8 +71,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 9e8ae07e0b2..f4b9fa270e4 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -85,8 +85,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