2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-08-16 06:49:32 +00:00
|
|
|
|
|
|
|
class MoveAuthBackendsToDatabase < ActiveRecord::Migration[6.0]
|
|
|
|
def change
|
|
|
|
|
|
|
|
# return if it's a new setup
|
|
|
|
return if !Setting.exists?(name: 'system_init_done')
|
|
|
|
|
|
|
|
Setting.create_if_not_exists(
|
|
|
|
title: 'Authentication via %s',
|
|
|
|
name: 'auth_internal',
|
|
|
|
area: 'Security::Authentication',
|
|
|
|
description: 'Enables user authentication via %s.',
|
|
|
|
preferences: {
|
|
|
|
title_i18n: ['internal database'],
|
|
|
|
description_i18n: ['internal database'],
|
|
|
|
permission: ['admin.security'],
|
|
|
|
},
|
|
|
|
state: {
|
|
|
|
priority: 1,
|
2021-08-24 08:35:55 +00:00
|
|
|
adapter: 'Auth::Backend::Internal',
|
2021-08-16 06:49:32 +00:00
|
|
|
},
|
|
|
|
frontend: false
|
|
|
|
)
|
|
|
|
Setting.create_if_not_exists(
|
|
|
|
title: 'Authentication via %s',
|
|
|
|
name: 'auth_developer',
|
|
|
|
area: 'Security::Authentication',
|
|
|
|
description: 'Enables user authentication via %s.',
|
|
|
|
preferences: {
|
|
|
|
title_i18n: ['developer password'],
|
|
|
|
description_i18n: ['developer password'],
|
|
|
|
permission: ['admin.security'],
|
|
|
|
},
|
|
|
|
state: {
|
|
|
|
priority: 2,
|
2021-08-24 08:35:55 +00:00
|
|
|
adapter: 'Auth::Backend::Developer',
|
2021-08-16 06:49:32 +00:00
|
|
|
},
|
|
|
|
frontend: false
|
|
|
|
)
|
|
|
|
|
2021-08-24 08:35:55 +00:00
|
|
|
update_auth_ldap
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_auth_ldap # rubocop:disable Metrics/AbcSize
|
|
|
|
|
2021-08-16 06:49:32 +00:00
|
|
|
begin
|
|
|
|
auth_ldap = Setting.find_by(name: 'auth_ldap')
|
|
|
|
|
|
|
|
auth_ldap.state_initial[:value][:priority] = 3
|
2021-08-24 08:35:55 +00:00
|
|
|
auth_ldap.state_initial[:value][:adapter] = 'Auth::Backend::Ldap'
|
2021-08-16 06:49:32 +00:00
|
|
|
auth_ldap.state_current[:value][:priority] = 3
|
2021-08-24 08:35:55 +00:00
|
|
|
auth_ldap.state_current[:value][:adapter] = 'Auth::Backend::Ldap'
|
2021-08-16 06:49:32 +00:00
|
|
|
|
|
|
|
auth_ldap.save!
|
|
|
|
rescue => e
|
2021-08-24 08:35:55 +00:00
|
|
|
Rails.logger.error "Error while updating 'auth_ldap' Setting priority and adapter"
|
2021-08-16 06:49:32 +00:00
|
|
|
Rails.logger.error e
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|