20210528000000_update_session_timeout_dropdown.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class UpdateSessionTimeoutDropdown < ActiveRecord::Migration[5.2]
  3. def change
  4. return if !Setting.exists?(name: 'system_init_done')
  5. change_column :settings, :options, :text, null: true
  6. Setting.reset_column_information
  7. update_setting
  8. end
  9. def options
  10. [ { 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' } ]
  11. end
  12. def update_setting
  13. setting = Setting.find_by(name: 'session_timeout')
  14. setting.options = {
  15. form: [
  16. {
  17. display: 'Default',
  18. null: false,
  19. name: 'default',
  20. tag: 'select',
  21. options: options,
  22. translate: true,
  23. },
  24. {
  25. display: 'admin',
  26. null: false,
  27. name: 'admin',
  28. tag: 'select',
  29. options: options,
  30. translate: true,
  31. },
  32. {
  33. display: 'ticket.agent',
  34. null: false,
  35. name: 'ticket.agent',
  36. tag: 'select',
  37. options: options,
  38. translate: true,
  39. },
  40. {
  41. display: 'ticket.customer',
  42. null: false,
  43. name: 'ticket.customer',
  44. tag: 'select',
  45. options: options,
  46. translate: true,
  47. },
  48. ]
  49. }
  50. setting.save!
  51. end
  52. end