Skip to content

Commit

Permalink
fix first migration for migrate users to redmine_2fa SMS
Browse files Browse the repository at this point in the history
  • Loading branch information
arturtr committed Sep 23, 2016
1 parent d9dd4d8 commit 7efb7fc
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions db/migrate/001_add_sms_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@ def up
end

def down
AuthSource.where(type: 'AuthSourceSms').destroy_all

if Redmine::Plugin.installed?(:redmine_2fa)
Redmine2FA::AuthSourceSms.create name: 'SMS', onthefly_register: false, tls: false
old_auth_source = AuthSource.where(type: 'AuthSourceSms').first
old_auth_source_id = if old_auth_source
old_auth_source.id
else
(User.all.pluck(:auth_source_id).compact.uniq - AuthSource.pluck(:id)).first
end

AuthSource.where(type: 'AuthSourceSms').destroy_all

new_auth_source = Redmine2FA::AuthSourceSms.create name: 'SMS', onthefly_register: false, tls: false

if old_auth_source_id
User.where(auth_source_id: old_auth_source_id).update_all(auth_source_id: new_auth_source.id)
end
else
AuthSource.where(type: 'AuthSourceSms').destroy_all
end
end
end

0 comments on commit 7efb7fc

Please sign in to comment.