- Refactoring: Replaced Object.const_get with absolut namespace call.
- Refactoring: Removed broken cache. - Refactroing: Removed obsolete preferences[:selectable].
This commit is contained in:
parent
136954f46a
commit
c710389c80
1 changed files with 11 additions and 21 deletions
|
@ -408,7 +408,7 @@ returns
|
||||||
|
|
||||||
def permissions
|
def permissions
|
||||||
list = {}
|
list = {}
|
||||||
Object.const_get('Permission').select('permissions.name, permissions.preferences').joins(:roles).where('roles.id IN (?) AND permissions.active = ?', role_ids, true).pluck(:name, :preferences).each do |permission|
|
::Permission.select('permissions.name, permissions.preferences').joins(:roles).where('roles.id IN (?) AND permissions.active = ?', role_ids, true).pluck(:name, :preferences).each do |permission|
|
||||||
next if permission[1]['selectable'] == false
|
next if permission[1]['selectable'] == false
|
||||||
list[permission[0]] = true
|
list[permission[0]] = true
|
||||||
end
|
end
|
||||||
|
@ -440,29 +440,19 @@ returns
|
||||||
keys = [key]
|
keys = [key]
|
||||||
end
|
end
|
||||||
keys.each do |local_key|
|
keys.each do |local_key|
|
||||||
cache_key = "User::permissions?:local_key:::#{id}"
|
|
||||||
if Rails.env.production?
|
|
||||||
cache = Cache.get(cache_key)
|
|
||||||
return cache if cache
|
|
||||||
end
|
|
||||||
list = []
|
list = []
|
||||||
if local_key =~ /\.\*$/
|
if local_key =~ /\.\*$/
|
||||||
local_key.sub!('.*', '.%')
|
local_key.sub!('.*', '.%')
|
||||||
permissions = Object.const_get('Permission').with_parents(local_key)
|
permissions = ::Permission.with_parents(local_key)
|
||||||
list = Object.const_get('Permission').select('preferences').joins(:roles).where('roles.id IN (?) AND roles.active = ? AND (permissions.name IN (?) OR permissions.name LIKE ?) AND permissions.active = ?', role_ids, true, permissions, local_key, true).pluck(:preferences)
|
list = ::Permission.select('preferences').joins(:roles).where('roles.id IN (?) AND roles.active = ? AND (permissions.name IN (?) OR permissions.name LIKE ?) AND permissions.active = ?', role_ids, true, permissions, local_key, true).pluck(:preferences)
|
||||||
else
|
else
|
||||||
permission = Object.const_get('Permission').lookup(name: local_key)
|
permission = ::Permission.lookup(name: local_key)
|
||||||
break if permission && permission.active == false
|
break if permission && permission.active == false
|
||||||
permissions = Object.const_get('Permission').with_parents(local_key)
|
permissions = ::Permission.with_parents(local_key)
|
||||||
list = Object.const_get('Permission').select('preferences').joins(:roles).where('roles.id IN (?) AND roles.active = ? AND permissions.name IN (?) AND permissions.active = ?', role_ids, true, permissions, true).pluck(:preferences)
|
list = ::Permission.select('preferences').joins(:roles).where('roles.id IN (?) AND roles.active = ? AND permissions.name IN (?) AND permissions.active = ?', role_ids, true, permissions, true).pluck(:preferences)
|
||||||
end
|
end
|
||||||
list.each do |preferences|
|
return true if list.present?
|
||||||
next if preferences[:selectable] == false
|
|
||||||
Cache.write(key, true, expires_in: 10.seconds)
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
Cache.write(key, false, expires_in: 10.seconds)
|
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -489,7 +479,7 @@ returns
|
||||||
where_bind.push "#{permission_name}.%"
|
where_bind.push "#{permission_name}.%"
|
||||||
end
|
end
|
||||||
return [] if where == ''
|
return [] if where == ''
|
||||||
Object.const_get('Permission').where("permissions.active = ? AND (#{where})", *where_bind).pluck(:id)
|
::Permission.where("permissions.active = ? AND (#{where})", *where_bind).pluck(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
@ -516,8 +506,8 @@ returns
|
||||||
permission_ids = []
|
permission_ids = []
|
||||||
keys.each do |key|
|
keys.each do |key|
|
||||||
role_ids = []
|
role_ids = []
|
||||||
Object.const_get('Permission').with_parents(key).each do |local_key|
|
::Permission.with_parents(key).each do |local_key|
|
||||||
permission = Object.const_get('Permission').lookup(name: local_key)
|
permission = ::Permission.lookup(name: local_key)
|
||||||
next if !permission
|
next if !permission
|
||||||
permission_ids.push permission.id
|
permission_ids.push permission.id
|
||||||
end
|
end
|
||||||
|
@ -758,7 +748,7 @@ returns
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.update_default_preferences_by_permission(permission_name, force = false)
|
def self.update_default_preferences_by_permission(permission_name, force = false)
|
||||||
permission = Object.const_get('Permission').lookup(name: permission_name)
|
permission = ::Permission.lookup(name: permission_name)
|
||||||
return if !permission
|
return if !permission
|
||||||
default = Rails.configuration.preferences_default_by_permission
|
default = Rails.configuration.preferences_default_by_permission
|
||||||
return false if !default
|
return false if !default
|
||||||
|
|
Loading…
Reference in a new issue