20170910000002_out_of_office2.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.create_or_update(
  21. name: 'My replacement Tickets',
  22. link: 'my_replacement_tickets',
  23. prio: 1080,
  24. role_ids: role_ids,
  25. out_of_office: true,
  26. condition: {
  27. 'ticket.state_id' => {
  28. operator: 'is',
  29. value: Ticket::State.by_category(:open).pluck(:id),
  30. },
  31. 'ticket.out_of_office_replacement_id' => {
  32. operator: 'is',
  33. pre_condition: 'current_user.id',
  34. },
  35. },
  36. order: {
  37. by: 'created_at',
  38. direction: 'DESC',
  39. },
  40. view: {
  41. d: %w[title customer group owner escalation_at],
  42. s: %w[title customer group owner escalation_at],
  43. m: %w[number title customer group owner escalation_at],
  44. view_mode_default: 's',
  45. },
  46. updated_by_id: 1,
  47. created_by_id: 1,
  48. )
  49. Cache.clear
  50. end
  51. end