20240321081409_issue5083_chat_permission.rb 579 B

123456789101112131415161718
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Issue5083ChatPermission < ActiveRecord::Migration[7.0]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. parent_chat_permission = Permission.find_by(name: 'chat')
  7. chat_permissions = Permission.where("name LIKE 'chat.%'")
  8. Role.find_each do |role|
  9. next if role.permissions.exclude?(parent_chat_permission)
  10. role.permissions -= [parent_chat_permission]
  11. role.permissions += chat_permissions
  12. end
  13. end
  14. end