20240320092523_permission_setting_wording.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class PermissionSettingWording < 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. update_permissions
  7. update_settings
  8. end
  9. PERMISSIONS_TO_UPDATE = [
  10. {
  11. name: 'knowledge_base',
  12. note: 'Knowledge Base',
  13. },
  14. {
  15. name: 'knowledge_base.editor',
  16. note: 'Knowledge Base Editor',
  17. },
  18. {
  19. name: 'knowledge_base.reader',
  20. note: 'Knowledge Base Reader',
  21. },
  22. {
  23. name: 'ticket.customer',
  24. note: 'Access to customer tickets'
  25. }
  26. ].freeze
  27. def update_permissions
  28. PERMISSIONS_TO_UPDATE.each do |perm_def|
  29. Permission.find_by(name: perm_def[:name])&.tap do |perm|
  30. perm.note = perm_def[:note]
  31. perm.preferences.delete('translations')
  32. perm.save!
  33. end
  34. end
  35. end
  36. SETTINGS_TO_UPDATE = [
  37. {
  38. title: 'Maximum Recursive Ticket Triggers Depth',
  39. name: 'ticket_trigger_recursive_max_loop',
  40. },
  41. {
  42. title: 'Enforce the setup of the two-factor authentication',
  43. name: 'two_factor_authentication_enforce_role_ids',
  44. description: 'Requires the setup of the two-factor authentication for certain user roles.',
  45. },
  46. {
  47. title: 'Additional notes for ticket create types.',
  48. name: 'ui_ticket_create_notes',
  49. description: 'Show additional notes for ticket creation depending on the selected type.',
  50. },
  51. {
  52. title: 'Storage Method',
  53. name: 'storage_provider',
  54. }
  55. ].freeze
  56. def update_settings
  57. SETTINGS_TO_UPDATE.each do |setting_def|
  58. Setting.find_by(name: setting_def[:name])&.tap do |setting|
  59. setting.title = setting_def[:title]
  60. setting.description = setting_def[:description] if setting_def[:description]
  61. setting.save!
  62. end
  63. end
  64. end
  65. end