Commit 99ee8620 authored by http://jneen.net/'s avatar http://jneen.net/

remove six, and use a Set instead

parent 0f4df86a
...@@ -97,9 +97,6 @@ gem 'fog-rackspace', '~> 0.1.1' ...@@ -97,9 +97,6 @@ gem 'fog-rackspace', '~> 0.1.1'
# for aws storage # for aws storage
gem 'unf', '~> 0.1.4' gem 'unf', '~> 0.1.4'
# Authorization
gem 'six', '~> 0.2.0'
# Seed data # Seed data
gem 'seed-fu', '~> 2.3.5' gem 'seed-fu', '~> 2.3.5'
......
...@@ -683,7 +683,6 @@ GEM ...@@ -683,7 +683,6 @@ GEM
rack (~> 1.5) rack (~> 1.5)
rack-protection (~> 1.4) rack-protection (~> 1.4)
tilt (>= 1.3, < 3) tilt (>= 1.3, < 3)
six (0.2.0)
slack-notifier (1.2.1) slack-notifier (1.2.1)
slop (3.6.0) slop (3.6.0)
spinach (0.8.10) spinach (0.8.10)
...@@ -954,7 +953,6 @@ DEPENDENCIES ...@@ -954,7 +953,6 @@ DEPENDENCIES
sidekiq-cron (~> 0.4.0) sidekiq-cron (~> 0.4.0)
simplecov (= 0.12.0) simplecov (= 0.12.0)
sinatra (~> 1.4.4) sinatra (~> 1.4.4)
six (~> 0.2.0)
slack-notifier (~> 1.2.0) slack-notifier (~> 1.2.0)
spinach-rails (~> 0.2.1) spinach-rails (~> 0.2.1)
spinach-rerun-reporter (~> 0.0.2) spinach-rerun-reporter (~> 0.0.2)
......
class Ability class Ability
class << self class << self
end
def allowed?(user, action, subject)
allowed(user, subject).include?(action)
end
def allowed(user, subject) 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 [] unless user.is_a?(User)
return [] if user.blocked? return [] if user.blocked?
...@@ -586,11 +602,8 @@ class Ability ...@@ -586,11 +602,8 @@ class Ability
end end
def abilities def abilities
@abilities ||= begin warn 'Ability.abilities is deprecated, use Ability.allowed?(user, action, subject) instead'
abilities = Six.new self
abilities << self
abilities
end
end end
private private
......
...@@ -409,11 +409,7 @@ module API ...@@ -409,11 +409,7 @@ module API
end end
def abilities def abilities
@abilities ||= begin Ability
abilities = Six.new
abilities << Ability
abilities
end
end end
def secret_token def secret_token
......
...@@ -71,8 +71,7 @@ describe ProjectMember, models: true do ...@@ -71,8 +71,7 @@ describe ProjectMember, models: true do
describe :import_team do describe :import_team do
before do before do
@abilities = Six.new @abilities = Ability
@abilities << Ability
@project_1 = create :project @project_1 = create :project
@project_2 = create :project @project_2 = create :project
......
...@@ -85,8 +85,7 @@ describe Note, models: true do ...@@ -85,8 +85,7 @@ describe Note, models: true do
@u1 = create(:user) @u1 = create(:user)
@u2 = create(:user) @u2 = create(:user)
@u3 = create(:user) @u3 = create(:user)
@abilities = Six.new @abilities = Ability
@abilities << Ability
end end
describe 'read' do describe 'read' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment