20170419000001_ldap_support.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. class LdapSupport < 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.table_exists? 'import_jobs'
  6. create_table :import_jobs do |t|
  7. t.string :name, limit: 250, null: false
  8. t.boolean :dry_run, default: false
  9. t.text :payload, limit: 80_000
  10. t.text :result, limit: 80_000
  11. t.datetime :started_at
  12. t.datetime :finished_at
  13. t.timestamps null: false
  14. end
  15. end
  16. Setting.create_or_update(
  17. title: 'Authentication via %s',
  18. name: 'auth_ldap',
  19. area: 'Security::Authentication',
  20. description: 'Enables user authentication via %s.',
  21. preferences: {
  22. title_i18n: ['LDAP'],
  23. description_i18n: ['LDAP'],
  24. permission: ['admin.security'],
  25. },
  26. state: {
  27. adapter: 'Auth::Ldap',
  28. login_attributes: %w[login email],
  29. },
  30. frontend: false
  31. )
  32. Setting.create_if_not_exists(
  33. title: 'LDAP integration',
  34. name: 'ldap_integration',
  35. area: 'Integration::Switch',
  36. description: 'Defines if LDAP is enabled or not.',
  37. options: {
  38. form: [
  39. {
  40. display: '',
  41. null: true,
  42. name: 'ldap_integration',
  43. tag: 'boolean',
  44. options: {
  45. true => 'yes',
  46. false => 'no',
  47. },
  48. },
  49. ],
  50. },
  51. state: false,
  52. preferences: {
  53. prio: 1,
  54. authentication: true,
  55. permission: ['admin.integration'],
  56. },
  57. frontend: true
  58. )
  59. Setting.create_if_not_exists(
  60. title: 'LDAP config',
  61. name: 'ldap_config',
  62. area: 'Integration::LDAP',
  63. description: 'Defines the LDAP config.',
  64. options: {},
  65. state: {},
  66. preferences: {
  67. prio: 2,
  68. permission: ['admin.integration'],
  69. },
  70. frontend: false,
  71. )
  72. Scheduler.create_or_update(
  73. name: 'Import Jobs',
  74. method: 'ImportJob.start_registered',
  75. period: 1.hour,
  76. prio: 1,
  77. active: true,
  78. updated_by_id: 1,
  79. created_by_id: 1
  80. )
  81. Setting.create_if_not_exists(
  82. title: 'Import Backends',
  83. name: 'import_backends',
  84. area: 'Import',
  85. description: 'A list of active import backends that get scheduled automatically.',
  86. options: {},
  87. state: ['Import::Ldap'],
  88. preferences: {
  89. permission: ['admin'],
  90. },
  91. frontend: false
  92. )
  93. end
  94. end