20170727000001_setting_proxy.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. class SettingProxy < ActiveRecord::Migration[4.2]
  2. def up
  3. # return if it's a new setup
  4. return if !Setting.exists?(name: 'system_init_done')
  5. Setting.create_if_not_exists(
  6. title: 'Proxy Settings',
  7. name: 'proxy',
  8. area: 'System::Network',
  9. description: 'Address of the proxy server for http and https resources.',
  10. options: {
  11. form: [
  12. {
  13. display: '',
  14. null: false,
  15. name: 'proxy',
  16. tag: 'input',
  17. placeholder: 'proxy.example.com:3128',
  18. },
  19. ],
  20. },
  21. state: '',
  22. preferences: {
  23. online_service_disable: true,
  24. controller: 'SettingsAreaProxy',
  25. prio: 1,
  26. permission: ['admin.system'],
  27. },
  28. frontend: false
  29. )
  30. Setting.create_if_not_exists(
  31. title: 'Proxy User',
  32. name: 'proxy_username',
  33. area: 'System::Network',
  34. description: 'Username for proxy connection.',
  35. options: {
  36. form: [
  37. {
  38. display: '',
  39. null: false,
  40. name: 'proxy_username',
  41. tag: 'input',
  42. },
  43. ],
  44. },
  45. state: '',
  46. preferences: {
  47. disabled: true,
  48. online_service_disable: true,
  49. prio: 2,
  50. permission: ['admin.system'],
  51. },
  52. frontend: false
  53. )
  54. # fix typo
  55. setting = Setting.find_by(name: 'proxy_password')
  56. if setting
  57. setting.options[:form][0][:name] = 'proxy_password'
  58. setting.save!
  59. else
  60. Setting.create_if_not_exists(
  61. title: 'Proxy Password',
  62. name: 'proxy_password',
  63. area: 'System::Network',
  64. description: 'Password for proxy connection.',
  65. options: {
  66. form: [
  67. {
  68. display: '',
  69. null: false,
  70. name: 'proxy_password',
  71. tag: 'input',
  72. },
  73. ],
  74. },
  75. state: '',
  76. preferences: {
  77. disabled: true,
  78. online_service_disable: true,
  79. prio: 3,
  80. permission: ['admin.system'],
  81. },
  82. frontend: false
  83. )
  84. end
  85. Setting.create_if_not_exists(
  86. title: 'No Proxy',
  87. name: 'proxy_no',
  88. area: 'System::Network',
  89. description: 'No proxy for the following hosts.',
  90. options: {
  91. form: [
  92. {
  93. display: '',
  94. null: false,
  95. name: 'proxy_no',
  96. tag: 'input',
  97. },
  98. ],
  99. },
  100. state: 'localhost,127.0.0.0,::1',
  101. preferences: {
  102. disabled: true,
  103. online_service_disable: true,
  104. prio: 4,
  105. permission: ['admin.system'],
  106. },
  107. frontend: false
  108. )
  109. end
  110. end