20201112000000_role_signup_column_fix.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class RoleSignupColumnFix < ActiveRecord::Migration[5.2]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. if !column_exists?(:permissions, :allow_signup)
  7. add_column :permissions, :allow_signup, :boolean, null: false, default: false
  8. end
  9. Permission.reset_column_information
  10. signup_permissions = [
  11. 'user_preferences',
  12. 'user_preferences.password',
  13. 'user_preferences.notifications',
  14. 'user_preferences.access_token',
  15. 'user_preferences.language',
  16. 'user_preferences.linked_accounts',
  17. 'user_preferences.device',
  18. 'user_preferences.avatar',
  19. 'user_preferences.calendar',
  20. 'user_preferences.out_of_office',
  21. 'ticket.customer',
  22. ]
  23. Permission.where(name: signup_permissions).update(allow_signup: true)
  24. Role.where(default_at_signup: true).find_each do |role|
  25. role.permissions.where.not(name: signup_permissions).find_each do |permission|
  26. role.permission_revoke(permission.name)
  27. end
  28. end
  29. end
  30. end