20240509100920_permission_switch_to_label_description.rb 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class PermissionSwitchToLabelDescription < 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. migrate_database
  7. change_wording
  8. end
  9. private
  10. def migrate_database
  11. rename_column :permissions, :note, :description
  12. add_column :permissions, :label, :string, limit: 255
  13. Permission.reset_column_information
  14. end
  15. def change_wording
  16. new_permission_wording.each_with_index do |(permission_name, new_values), index|
  17. change_single_permission_wording(permission_name, new_values, index)
  18. end
  19. end
  20. def change_single_permission_wording(permission_name, new_values, index)
  21. permission = Permission.find_by! name: permission_name
  22. permission.label = new_values[:label]
  23. permission.description = new_values[:description]
  24. permission.preferences.delete :translations
  25. permission.preferences[:prio] = 1_000 + (index * 10)
  26. permission.save!
  27. end
  28. def new_permission_wording
  29. {
  30. 'admin' => { label: 'Admin interface', description: 'Configure your system.' },
  31. 'admin.user' => { label: 'Users', description: 'Manage all users of your system.' },
  32. 'admin.group' => { label: 'Groups', description: 'Manage groups of your system.' },
  33. 'admin.role' => { label: 'Roles', description: 'Manage roles of your system.' },
  34. 'admin.organization' => { label: 'Organizations', description: 'Manage all organizations of your system.' },
  35. 'admin.overview' => { label: 'Overviews', description: 'Manage ticket overviews of your system.' },
  36. 'admin.text_module' => { label: 'Text modules', description: 'Manage text modules of your system.' },
  37. 'admin.macro' => { label: 'Macros', description: 'Manage ticket macros of your system.' },
  38. 'admin.template' => { label: 'Templates', description: 'Manage ticket templates of your system.' },
  39. 'admin.tag' => { label: 'Tags', description: 'Manage ticket tags of your system.' },
  40. 'admin.calendar' => { label: 'Calendars', description: 'Manage calendars of your system.' },
  41. 'admin.sla' => { label: 'SLAs', description: 'Manage Service Level Agreements of your system.' },
  42. 'admin.trigger' => { label: 'Trigger', description: 'Manage triggers of your system.' },
  43. 'admin.public_links' => { label: 'Public Links', description: 'Manage public links of your system.' },
  44. 'admin.webhook' => { label: 'Webhook', description: 'Manage webhooks of your system.' },
  45. 'admin.scheduler' => { label: 'Scheduler', description: 'Manage schedulers of your system.' },
  46. 'admin.report_profile' => { label: 'Report Profiles', description: 'Manage report profiles of your system.' },
  47. 'admin.time_accounting' => { label: 'Time Accounting', description: 'Manage time accounting settings of your system.' },
  48. 'admin.knowledge_base' => { label: 'Knowledge Base', description: 'Create and set up Knowledge Base.' },
  49. 'admin.channel_web' => { label: 'Web', description: 'Manage web channel of your system.' },
  50. 'admin.channel_formular' => { label: 'Form', description: 'Manage form channel of your system.' },
  51. 'admin.channel_email' => { label: 'Email', description: 'Manage email channel of your system.' },
  52. 'admin.channel_sms' => { label: 'SMS', description: 'Manage SMS channel of your system.' },
  53. 'admin.channel_chat' => { label: 'Chat', description: 'Manage chat channel of your system.' },
  54. 'admin.channel_google' => { label: 'Google', description: 'Manage Google mail channel of your system.' },
  55. 'admin.channel_microsoft365' => { label: 'Microsoft 365', description: 'Manage Microsoft 365 mail channel of your system.' },
  56. 'admin.channel_twitter' => { label: 'Twitter', description: 'Manage Twitter channel of your system.' },
  57. 'admin.channel_facebook' => { label: 'Facebook', description: 'Manage Facebook channel of your system.' },
  58. 'admin.channel_telegram' => { label: 'Telegram', description: 'Manage Telegram channel of your system.' },
  59. 'admin.channel_whatsapp' => { label: 'WhatsApp', description: 'Manage WhatsApp channel of your system.' },
  60. 'admin.branding' => { label: 'Branding', description: 'Manage branding settings of your system.' },
  61. 'admin.setting_system' => { label: 'System', description: 'Manage core system settings.' },
  62. 'admin.security' => { label: 'Security', description: 'Manage security settings of your system.' },
  63. 'admin.ticket' => { label: 'Ticket', description: 'Manage ticket settings of your system.' },
  64. 'admin.integration' => { label: 'Integrations', description: 'Manage integrations of your system.' },
  65. 'admin.api' => { label: 'API', description: 'Manage API of your system.' },
  66. 'admin.object' => { label: 'Objects', description: 'Manage object attributes of your system.' },
  67. 'admin.ticket_state' => { label: 'Ticket States', description: 'Manage ticket states of your system.' },
  68. 'admin.ticket_priority' => { label: 'Ticket Priorities', description: 'Manage ticket priorities of your system.' },
  69. 'admin.core_workflow' => { label: 'Core Workflows', description: 'Manage core workflows of your system.' },
  70. 'admin.translation' => { label: 'Translations', description: 'Manage translations of your system.' },
  71. 'admin.data_privacy' => { label: 'Data Privacy', description: 'Delete existing data of your system.' },
  72. 'admin.maintenance' => { label: 'Maintenance', description: 'Manage maintenance mode of your system.' },
  73. 'admin.monitoring' => { label: 'Monitoring', description: 'Manage monitoring of your system.' },
  74. 'admin.package' => { label: 'Packages', description: 'Manage packages of your system.' },
  75. 'admin.session' => { label: 'Sessions', description: 'Manage active user sessions of your system.' },
  76. 'admin.system_report' => { label: 'System Report', description: 'Manage system report of your system.' },
  77. 'chat' => { label: 'Chat', description: 'Access to the chat interface.' },
  78. 'chat.agent' => { label: 'Agent chat', description: 'Access the agent chat features.' },
  79. 'cti' => { label: 'Phone', description: 'Access to the phone interface.' },
  80. 'cti.agent' => { label: 'Agent phone', description: 'Access the agent phone features.' },
  81. 'knowledge_base' => { label: 'Knowledge Base', description: 'Access to the knowledge base interface.' },
  82. 'knowledge_base.editor' => { label: 'Knowledge Base Editor', description: 'Access the knowledge base editor features.' },
  83. 'knowledge_base.reader' => { label: 'Knowledge Base Reader', description: 'Access the knowledge base reader features.' },
  84. 'report' => { label: 'Report', description: 'Access to the report interface.' },
  85. 'ticket' => { label: 'Ticket', description: 'Access to the ticket interface.' },
  86. 'ticket.agent' => { label: 'Agent tickets', description: 'Access the tickets as agent based on group access.' },
  87. 'ticket.customer' => { label: 'Customer tickets', description: 'Access tickets as customer.' },
  88. 'user_preferences' => { label: 'Profile settings', description: 'Manage personal settings.' },
  89. 'user_preferences.appearance' => { label: 'Appearance', description: 'Manage personal appearance settings.' },
  90. 'user_preferences.language' => { label: 'Language', description: 'Manage personal language settings.' },
  91. 'user_preferences.avatar' => { label: 'Avatar', description: 'Manage personal avatar settings.' },
  92. 'user_preferences.out_of_office' => { label: 'Out of Office', description: 'Manage personal out of office settings.' },
  93. 'user_preferences.password' => { label: 'Password', description: 'Change personal account password.' },
  94. 'user_preferences.two_factor_authentication' => { label: 'Two-factor Authentication', description: 'Manage personal two-factor authentication methods.' },
  95. 'user_preferences.device' => { label: 'Devices', description: 'Manage personal devices and sessions.' },
  96. 'user_preferences.access_token' => { label: 'Token Access', description: 'Manage personal API tokens.' },
  97. 'user_preferences.linked_accounts' => { label: 'Linked Accounts', description: 'Manage personal linked accounts.' },
  98. 'user_preferences.notifications' => { label: 'Notifications', description: 'Manage personal notifications settings.' },
  99. 'user_preferences.overview_sorting' => { label: 'Overviews', description: 'Manage personal overviews.' },
  100. 'user_preferences.calendar' => { label: 'Calendar', description: 'Manage personal calendar.' },
  101. }
  102. end
  103. end