Moved from User.update_default_preferences_by_role to User.update_default_preferences_by_permission (if somebody has renamed role names).
This commit is contained in:
parent
28fe4fa80b
commit
146bd7f9d4
3 changed files with 39 additions and 21 deletions
|
@ -654,9 +654,9 @@ returns
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
update/sync default preferences of users in a dedecated role
|
update/sync default preferences of users in a dedecated permissions
|
||||||
|
|
||||||
result = User.update_default_preferences('Agent', force)
|
result = User.update_default_preferences_by_permission('ticket.agent', force)
|
||||||
|
|
||||||
returns
|
returns
|
||||||
|
|
||||||
|
@ -664,12 +664,12 @@ returns
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.update_default_preferences(role_name, force = false)
|
def self.update_default_preferences_by_permission(permission_name, force = false)
|
||||||
role = Role.lookup(name: role_name)
|
permission = Object.const_get('Permission').lookup(name: permission_name)
|
||||||
|
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
|
||||||
default.deep_stringify_keys!
|
default.deep_stringify_keys!
|
||||||
role.permissions.each { |permission|
|
|
||||||
User.with_permissions(permission.name).each { |user|
|
User.with_permissions(permission.name).each { |user|
|
||||||
next if !default[permission.name]
|
next if !default[permission.name]
|
||||||
has_changed = false
|
has_changed = false
|
||||||
|
@ -682,6 +682,29 @@ returns
|
||||||
user.save!
|
user.save!
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
|
update/sync default preferences of users in a dedecated role
|
||||||
|
|
||||||
|
result = User.update_default_preferences_by_role('Agent', force)
|
||||||
|
|
||||||
|
returns
|
||||||
|
|
||||||
|
result = true # false
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def self.update_default_preferences_by_role(role_name, force = false)
|
||||||
|
role = Role.lookup(name: role_name)
|
||||||
|
return if !role
|
||||||
|
default = Rails.configuration.preferences_default_by_permission
|
||||||
|
return false if !default
|
||||||
|
default.deep_stringify_keys!
|
||||||
|
role.permissions.each { |permission|
|
||||||
|
User.update_default_preferences_by_permission(permission.name, force)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
class UpdateDefaultPreferences < ActiveRecord::Migration
|
|
||||||
def up
|
|
||||||
User.update_default_preferences('Agent')
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -4,6 +4,6 @@ class UserPreferencesUpdate < ActiveRecord::Migration
|
||||||
# return if it's a new setup
|
# return if it's a new setup
|
||||||
return if !Setting.find_by(name: 'system_init_done')
|
return if !Setting.find_by(name: 'system_init_done')
|
||||||
|
|
||||||
User.update_default_preferences('Agent')
|
User.update_default_preferences_by_permission('ticket.agent')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue