20170910000002_out_of_office2.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class OutOfOffice2 < ActiveRecord::Migration[4.2]
  3. def up
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. if !ActiveRecord::Base.connection.column_exists?(:overviews, :out_of_office)
  7. add_column :overviews, :out_of_office, :boolean, null: false, default: false
  8. Overview.reset_column_information
  9. end
  10. if !ActiveRecord::Base.connection.column_exists?(:users, :out_of_office)
  11. add_column :users, :out_of_office, :boolean, null: false, default: false
  12. add_column :users, :out_of_office_start_at, :date, null: true
  13. add_column :users, :out_of_office_end_at, :date, null: true
  14. add_column :users, :out_of_office_replacement_id, :integer, null: true
  15. add_index :users, %i[out_of_office out_of_office_start_at out_of_office_end_at], name: 'index_out_of_office'
  16. add_index :users, [:out_of_office_replacement_id]
  17. add_foreign_key :users, :users, column: :out_of_office_replacement_id
  18. User.reset_column_information
  19. end
  20. role_ids = Role.with_permissions(['ticket.agent']).map(&:id)
  21. Overview.create_or_update(
  22. name: 'My replacement Tickets',
  23. link: 'my_replacement_tickets',
  24. prio: 1080,
  25. role_ids: role_ids,
  26. out_of_office: true,
  27. condition: {
  28. 'ticket.state_id' => {
  29. operator: 'is',
  30. value: Ticket::State.by_category(:open).pluck(:id),
  31. },
  32. 'ticket.out_of_office_replacement_id' => {
  33. operator: 'is',
  34. pre_condition: 'current_user.id',
  35. },
  36. },
  37. order: {
  38. by: 'created_at',
  39. direction: 'DESC',
  40. },
  41. view: {
  42. d: %w[title customer group owner escalation_at],
  43. s: %w[title customer group owner escalation_at],
  44. m: %w[number title customer group owner escalation_at],
  45. view_mode_default: 's',
  46. },
  47. updated_by_id: 1,
  48. created_by_id: 1,
  49. )
  50. Rails.cache.clear
  51. end
  52. end