2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2020-11-12 10:54:29 +00:00
|
|
|
class RoleSignupColumnFix < ActiveRecord::Migration[5.2]
|
2020-10-07 12:05:07 +00:00
|
|
|
def change
|
|
|
|
|
|
|
|
# return if it's a new setup
|
|
|
|
return if !Setting.exists?(name: 'system_init_done')
|
|
|
|
|
2020-11-12 10:54:29 +00:00
|
|
|
if !column_exists?(:permissions, :allow_signup)
|
|
|
|
add_column :permissions, :allow_signup, :boolean, null: false, default: false
|
|
|
|
end
|
|
|
|
|
|
|
|
Permission.reset_column_information
|
2020-10-07 12:05:07 +00:00
|
|
|
|
|
|
|
signup_permissions = [
|
|
|
|
'user_preferences',
|
|
|
|
'user_preferences.password',
|
|
|
|
'user_preferences.notifications',
|
|
|
|
'user_preferences.access_token',
|
|
|
|
'user_preferences.language',
|
|
|
|
'user_preferences.linked_accounts',
|
|
|
|
'user_preferences.device',
|
|
|
|
'user_preferences.avatar',
|
|
|
|
'user_preferences.calendar',
|
|
|
|
'user_preferences.out_of_office',
|
|
|
|
'ticket.customer',
|
|
|
|
]
|
|
|
|
|
|
|
|
Permission.where(name: signup_permissions).update(allow_signup: true)
|
|
|
|
|
|
|
|
Role.where(default_at_signup: true).find_each do |role|
|
|
|
|
role.permissions.where.not(name: signup_permissions).find_each do |permission|
|
|
|
|
role.permission_revoke(permission.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|