20160811000001_update_role.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. class UpdateRole < ActiveRecord::Migration
  2. def up
  3. # return if it's a new setup
  4. return if !Setting.find_by(name: 'system_init_done')
  5. add_column :roles, :preferences, :text, limit: 500.kilobytes + 1, null: true
  6. add_column :roles, :default_at_signup, :boolean, null: true, default: false
  7. Role.connection.schema_cache.clear!
  8. Role.reset_column_information
  9. Role.create_or_update(
  10. id: 1,
  11. name: 'Admin',
  12. note: 'To configure your system.',
  13. preferences: {
  14. not: ['Customer'],
  15. },
  16. default_at_signup: false,
  17. updated_by_id: 1,
  18. created_by_id: 1
  19. )
  20. Role.create_or_update(
  21. id: 2,
  22. name: 'Agent',
  23. note: 'To work on Tickets.',
  24. default_at_signup: false,
  25. preferences: {
  26. not: ['Customer'],
  27. },
  28. updated_by_id: 1,
  29. created_by_id: 1
  30. )
  31. Role.create_or_update(
  32. id: 3,
  33. name: 'Customer',
  34. note: 'People who create Tickets ask for help.',
  35. preferences: {
  36. not: %w(Agent Admin),
  37. },
  38. default_at_signup: true,
  39. updated_by_id: 1,
  40. created_by_id: 1
  41. )
  42. Role.create_or_update(
  43. id: 4,
  44. name: 'Report',
  45. note: 'Access the report area.',
  46. preferences: {
  47. not: ['Customer'],
  48. },
  49. default_at_signup: false,
  50. created_by_id: 1,
  51. updated_by_id: 1,
  52. )
  53. ObjectManager::Attribute.add(
  54. force: true,
  55. object: 'Organization',
  56. name: 'shared',
  57. display: 'Shared organization',
  58. data_type: 'boolean',
  59. data_option: {
  60. null: true,
  61. default: true,
  62. note: 'Customers in the organization can view each other items.',
  63. item_class: 'formGroup--halfSize',
  64. translate: true,
  65. options: {
  66. true: 'yes',
  67. false: 'no',
  68. }
  69. },
  70. editable: false,
  71. active: true,
  72. screens: {
  73. edit: {
  74. Admin: {
  75. null: false,
  76. },
  77. },
  78. view: {
  79. '-all-' => {
  80. shown: true,
  81. },
  82. },
  83. },
  84. to_create: false,
  85. to_migrate: false,
  86. to_delete: false,
  87. position: 1400,
  88. )
  89. ObjectManager::Attribute.add(
  90. force: true,
  91. object: 'User',
  92. name: 'role_ids',
  93. display: 'Permissions',
  94. data_type: 'user_permission',
  95. data_option: {
  96. null: false,
  97. item_class: 'checkbox',
  98. },
  99. editable: false,
  100. active: true,
  101. screens: {
  102. signup: {},
  103. invite_agent: {
  104. '-all-' => {
  105. null: false,
  106. default: [Role.lookup(name: 'Agent').id],
  107. },
  108. },
  109. invite_customer: {},
  110. edit: {
  111. Admin: {
  112. null: true,
  113. },
  114. },
  115. view: {
  116. '-all-' => {
  117. shown: false,
  118. },
  119. },
  120. },
  121. to_create: false,
  122. to_migrate: false,
  123. to_delete: false,
  124. position: 1600,
  125. )
  126. end
  127. end