20170910000002_out_of_office2.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. class OutOfOffice2 < ActiveRecord::Migration[4.2]
  2. def up
  3. # return if it's a new setup
  4. return if !Setting.find_by(name: 'system_init_done')
  5. if !ActiveRecord::Base.connection.column_exists?(:overviews, :out_of_office)
  6. add_column :overviews, :out_of_office, :boolean, null: false, default: false
  7. Overview.reset_column_information
  8. end
  9. if !ActiveRecord::Base.connection.column_exists?(:users, :out_of_office)
  10. add_column :users, :out_of_office, :boolean, null: false, default: false
  11. add_column :users, :out_of_office_start_at, :date, null: true
  12. add_column :users, :out_of_office_end_at, :date, null: true
  13. add_column :users, :out_of_office_replacement_id, :integer, null: true
  14. add_index :users, %i[out_of_office out_of_office_start_at out_of_office_end_at], name: 'index_out_of_office'
  15. add_index :users, [:out_of_office_replacement_id]
  16. add_foreign_key :users, :users, column: :out_of_office_replacement_id
  17. User.reset_column_information
  18. end
  19. role_ids = Role.with_permissions(['ticket.agent']).map(&:id)
  20. overview_role = Role.find_by(name: 'Agent')
  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. Cache.clear
  51. end
  52. end