remove six, and use a Set instead
This commit is contained in:
parent
0f4df86a5e
commit
99ee86206e
3
Gemfile
3
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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -409,11 +409,7 @@ module API
|
|||
end
|
||||
|
||||
def abilities
|
||||
@abilities ||= begin
|
||||
abilities = Six.new
|
||||
abilities << Ability
|
||||
abilities
|
||||
end
|
||||
Ability
|
||||
end
|
||||
|
||||
def secret_token
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue