diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-05-03 11:00:51 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-05-03 11:00:51 +0000 |
commit | 4291e28af72890ee4f9c0f306ba691ba84c3435d (patch) | |
tree | 980036c1fb0affa984da0c8135d0ffca115baa7c /app/controllers/profiles | |
parent | 0df317f7297b9a72e888edc09aed51f83414f92a (diff) | |
parent | d386bb780864f4fc36490e19ea654f31bf193d0f (diff) | |
download | gitlab-ce-4291e28af72890ee4f9c0f306ba691ba84c3435d.tar.gz |
Merge branch 'change-primary-email' into 'master'
Allow primary email to be set to an email that you've already added.
Fixes gitlab-com/support-forum#106.
When the user sets their primary email to an email that they've already added to their account, this patch makes sure that secondary email record is destroyed, and a new email record is created for the old primary email. This is based on the assumption that in this case no email was meant to be deleted, but the user simply wanted to change which of their emails is primary.
See merge request !591
Diffstat (limited to 'app/controllers/profiles')
-rw-r--r-- | app/controllers/profiles/emails_controller.rb | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/app/controllers/profiles/emails_controller.rb b/app/controllers/profiles/emails_controller.rb index 3e904700de5..0ede9b8e21b 100644 --- a/app/controllers/profiles/emails_controller.rb +++ b/app/controllers/profiles/emails_controller.rb @@ -1,14 +1,17 @@ class Profiles::EmailsController < Profiles::ApplicationController def index @primary = current_user.email - @public_email = current_user.public_email @emails = current_user.emails end def create @email = current_user.emails.new(email_params) - flash[:alert] = @email.errors.full_messages.first unless @email.save + if @email.save + NotificationService.new.new_email(@email) + else + flash[:alert] = @email.errors.full_messages.first + end redirect_to profile_emails_url end @@ -17,9 +20,7 @@ class Profiles::EmailsController < Profiles::ApplicationController @email = current_user.emails.find(params[:id]) @email.destroy - current_user.set_notification_email - current_user.set_public_email - current_user.save if current_user.notification_email_changed? or current_user.public_email_changed? + current_user.update_secondary_emails! respond_to do |format| format.html { redirect_to profile_emails_url } |