20210528000000_update_session_timeout_dropdown.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. class UpdateSessionTimeoutDropdown < ActiveRecord::Migration[5.2]
  2. def change
  3. return if !Setting.exists?(name: 'system_init_done')
  4. change_column :settings, :options, :text, null: true
  5. Setting.reset_column_information
  6. update_setting
  7. end
  8. def options
  9. [ { value: '0', name: 'disabled' }, { value: 1.hour.seconds, name: '1 hour' }, { value: 2.hours.seconds, name: '2 hours' }, { value: 1.day.seconds, name: '1 day' }, { value: 7.days.seconds, name: '1 week' }, { value: 14.days.seconds, name: '2 weeks' }, { value: 21.days.seconds, name: '3 weeks' }, { value: 28.days.seconds, name: '4 weeks' } ]
  10. end
  11. def update_setting
  12. setting = Setting.find_by(name: 'session_timeout')
  13. setting.options = {
  14. form: [
  15. {
  16. display: 'Default',
  17. null: false,
  18. name: 'default',
  19. tag: 'select',
  20. options: options,
  21. translate: true,
  22. },
  23. {
  24. display: 'admin',
  25. null: false,
  26. name: 'admin',
  27. tag: 'select',
  28. options: options,
  29. translate: true,
  30. },
  31. {
  32. display: 'ticket.agent',
  33. null: false,
  34. name: 'ticket.agent',
  35. tag: 'select',
  36. options: options,
  37. translate: true,
  38. },
  39. {
  40. display: 'ticket.customer',
  41. null: false,
  42. name: 'ticket.customer',
  43. tag: 'select',
  44. options: options,
  45. translate: true,
  46. },
  47. ]
  48. }
  49. setting.save!
  50. end
  51. end