20201112000000_role_signup_column_fix.rb 1.0 KB

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