20181030000001_setting_add_placetel1.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. class SettingAddPlacetel1 < ActiveRecord::Migration[5.1]
  2. def change
  3. # return if it's a new setup
  4. return if !Setting.find_by(name: 'system_init_done')
  5. Setting.create_if_not_exists(
  6. title: 'Placetel integration',
  7. name: 'placetel_integration',
  8. area: 'Integration::Switch',
  9. description: 'Defines if Placetel (http://www.placetel.de) is enabled or not.',
  10. options: {
  11. form: [
  12. {
  13. display: '',
  14. null: true,
  15. name: 'placetel_integration',
  16. tag: 'boolean',
  17. options: {
  18. true => 'yes',
  19. false => 'no',
  20. },
  21. },
  22. ],
  23. },
  24. state: false,
  25. preferences: {
  26. prio: 1,
  27. trigger: ['menu:render', 'cti:reload'],
  28. authentication: true,
  29. permission: ['admin.integration'],
  30. },
  31. frontend: true
  32. )
  33. placetel_config = Setting.find_by(name: 'placetel_config')
  34. if !placetel_config
  35. Setting.create!(
  36. title: 'Placetel config',
  37. name: 'placetel_config',
  38. area: 'Integration::Placetel',
  39. description: 'Defines the Placetel config.',
  40. options: {},
  41. state: { 'outbound' => { 'routing_table' => [], 'default_caller_id' => '' }, 'inbound' => { 'block_caller_ids' => [] } },
  42. preferences: {
  43. prio: 2,
  44. permission: ['admin.integration'],
  45. cache: ['placetelGetVoipUsers'],
  46. },
  47. frontend: false,
  48. )
  49. else
  50. placetel_config.preferences[:cache] = ['placetelGetVoipUsers']
  51. placetel_config.save!
  52. end
  53. Setting.create_if_not_exists(
  54. title: 'PLACETEL Token',
  55. name: 'placetel_token',
  56. area: 'Integration::Placetel',
  57. description: 'Token for placetel.',
  58. options: {
  59. form: [
  60. {
  61. display: '',
  62. null: false,
  63. name: 'placetel_token',
  64. tag: 'input',
  65. },
  66. ],
  67. },
  68. state: ENV['PLACETEL_TOKEN'] || SecureRandom.urlsafe_base64(20),
  69. preferences: {
  70. permission: ['admin.integration'],
  71. },
  72. frontend: false
  73. )
  74. end
  75. end