notifications broken during email address change before email confirmed
Summary
When a user tries to change their email address from the profile page it currently is set as both the unconfirmed_email
and the notification_email
in the database which breaks notifications. If the user had a typo in the email address this results in them receiving no email notifications.
Steps to reproduce
- Update email address in profile to have typo
- Login to rails:
sudo gitlab-rails console
- Run
User.where(email: "originalemailaddress")
replacingoriginalemailaddress
with the address you used before your change
Notice that unconfirmed_email
and notification_email
are set to the new proposed email address and now notifications will not work
Expected behavior
I expect notifications to be delivered to the old address until the new one is confirmed and for notification_email
to not change until then. Additionally I expect /profile/notifications
to correctly show where my notifications are being sent.
Actual behavior
notification_email
is changed before confirmation. /profile/notifications
incorrectly shows that notifications are being sent to original email address but original email address gets no notifications.
Output of checks
Results of GitLab application Check
Good
Results of GitLab environment info
System information
System:
Current User: git
Using RVM: no
Ruby Version: 2.3.1p112
Gem Version: 2.6.6
Bundler Version:2.3.0
Rake Version: 10.5.0
Sidekiq Version:4.1.4
GitLab information
Version: 8.11.2
Revision: e618ce2
Directory: /opt/gitlab/embedded/service/gitlab-rails
DB Adapter: postgresql
URL: https://company.com
HTTP Clone URL: https://company.com/some-group/some-project.git
SSH Clone URL: git@company.com:some-group/some-project.git
Using LDAP: no
Using Omniauth: yes
Omniauth Providers: saml
GitLab Shell
Version: 3.4.0
Repository storage paths:
- default: /app/gitlab/git-data/repositories
Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks/
Git: /opt/gitlab/embedded/bin/git
Possible fixes
Related files:
- https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/controllers/profiles/notifications_controller.rb
- https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/models/user.rb
- https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/views/profiles/notifications/show.html.haml
Originally reported at https://gitlab.com/gitlab-org/gitlab-ce/issues/2322
Fix yourself
If you accidently change your email to an invalid address you can fix this issue and undo the change email request using the following until bug fixed:
# start rails console, for omnibus it is the next line
sudo gitlab-rails console
# correct user record
User.where.not(unconfirmed_email: nil).each do |user|
user.unconfirmed_email = nil
user.notification_email = user.email
user.save
end