commit
fe37f1acfe
2 changed files with 14 additions and 9 deletions
|
@ -9,11 +9,11 @@ module Users
|
||||||
|
|
||||||
def update_email
|
def update_email
|
||||||
requested_user = User.find_by(email: requested_email)
|
requested_user = User.find_by(email: requested_email)
|
||||||
if requested_user.present? && current_user.ask_for_merge(requested_user)
|
if requested_user.present?
|
||||||
current_user.update(unconfirmed_email: nil)
|
current_user.ask_for_merge(requested_user)
|
||||||
|
|
||||||
flash.notice = t('devise.registrations.update_needs_confirmation')
|
flash.notice = t('devise.registrations.update_needs_confirmation')
|
||||||
elsif current_user.update(update_email_params)
|
elsif update_with_lock(update_email_params)
|
||||||
current_user.update(requested_merge_into: nil)
|
current_user.update(requested_merge_into: nil)
|
||||||
|
|
||||||
flash.notice = t('devise.registrations.update_needs_confirmation')
|
flash.notice = t('devise.registrations.update_needs_confirmation')
|
||||||
|
@ -22,6 +22,15 @@ module Users
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to profil_path
|
redirect_to profil_path
|
||||||
|
rescue ActiveRecord::RecordInvalid => e
|
||||||
|
flash.alert = e.record.errors.full_messages
|
||||||
|
redirect_to profil_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_with_lock(params)
|
||||||
|
current_user.with_lock do
|
||||||
|
current_user.update!(params)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def transfer_all_dossiers
|
def transfer_all_dossiers
|
||||||
|
|
|
@ -257,12 +257,8 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def ask_for_merge(requested_user)
|
def ask_for_merge(requested_user)
|
||||||
if update(requested_merge_into: requested_user)
|
update!(requested_merge_into: requested_user, unconfirmed_email: nil)
|
||||||
UserMailer.ask_for_merge(self, requested_user.email).deliver_later
|
UserMailer.ask_for_merge(self, requested_user.email).deliver_later
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_devise_notification(notification, *args)
|
def send_devise_notification(notification, *args)
|
||||||
|
|
Loading…
Reference in a new issue