20220124104955_update_object_attributes.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class UpdateObjectAttributes < ActiveRecord::Migration[6.0]
  3. def change
  4. return if !Setting.exists?(name: 'system_init_done')
  5. # rubocop:disable Lint/BooleanSymbol
  6. object_attributes_update = [
  7. {
  8. object: 'Organization',
  9. name: 'domain_assignment',
  10. data_option: {
  11. null: true,
  12. default: false,
  13. note: 'Assign users based on user domain.',
  14. item_class: 'formGroup--halfSize',
  15. options: {
  16. true: 'yes',
  17. false: 'no',
  18. },
  19. translate: true,
  20. permission: ['admin.organization'],
  21. },
  22. },
  23. {
  24. object: 'TicketArticle',
  25. name: 'cc',
  26. display: 'CC',
  27. },
  28. {
  29. object: 'Organization',
  30. name: 'shared',
  31. data_option: {
  32. null: true,
  33. default: true,
  34. note: "Customers in the organization can view each other's items.",
  35. item_class: 'formGroup--halfSize',
  36. options: {
  37. true: 'yes',
  38. false: 'no',
  39. },
  40. translate: true,
  41. permission: ['admin.organization'],
  42. },
  43. },
  44. {
  45. object: 'User',
  46. name: 'firstname',
  47. display: 'First name',
  48. },
  49. {
  50. object: 'User',
  51. name: 'lastname',
  52. display: 'Last name',
  53. },
  54. ]
  55. # rubocop:enable Lint/BooleanSymbol
  56. object_attributes_update.each do |attribute|
  57. fetched_attribute = ObjectManager::Attribute.get(name: attribute[:name], object: attribute[:object])
  58. next if !fetched_attribute
  59. if attribute[:display]
  60. # p "Updating display of #{attribute[:name]} to #{attribute[:display]}"
  61. fetched_attribute.display = attribute[:display]
  62. end
  63. if attribute[:data_option]
  64. # p "Updating data_option of #{attribute[:name]} to #{attribute[:data_option]}"
  65. fetched_attribute.data_option = attribute[:data_option]
  66. end
  67. fetched_attribute.save!
  68. end
  69. end
  70. end