20220524074118_issue4089_fix_draft_attribute.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Issue4089FixDraftAttribute < ActiveRecord::Migration[5.0]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. field = ObjectManager::Attribute.find_by(name: 'shared_drafts', object_lookup_id: ObjectLookup.by_name('Group'))
  7. if !field
  8. add_field
  9. return
  10. end
  11. field.update(editable: false)
  12. end
  13. def add_field
  14. UserInfo.current_user_id = 1
  15. ObjectManager::Attribute.add(
  16. force: true,
  17. object: 'Group',
  18. name: 'shared_drafts',
  19. display: 'Shared Drafts',
  20. data_type: 'active',
  21. data_option: {
  22. null: false,
  23. default: true,
  24. permission: ['admin.group'],
  25. },
  26. editable: false,
  27. active: true,
  28. screens: {
  29. create: {
  30. '-all-' => {
  31. null: true,
  32. },
  33. },
  34. edit: {
  35. '-all-': {
  36. null: false,
  37. },
  38. },
  39. view: {
  40. '-all-' => {
  41. shown: false,
  42. },
  43. },
  44. },
  45. to_create: false,
  46. to_migrate: false,
  47. to_delete: false,
  48. position: 1400,
  49. )
  50. ObjectManager::Attribute.migration_execute
  51. end
  52. end