summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-25 04:10:51 -0700
committerStan Hu <stanhu@gmail.com>2018-07-25 05:06:02 -0700
commitf3056ac31562f119a6f1989802b1d59f6c5eb635 (patch)
treed73579e9b0768636cf6a38b36dccf50de5b0cee0
parent6cb30f83255f0982646fea688f2fe275a3b22cc7 (diff)
downloadgitlab-ce-sh-fix-email-confirmations.tar.gz
Fix e-mail verification returning a 500 Errorsh-fix-email-confirmations
When a user goes to confirm an e-mail address, he/she is met with an ugly 500 error: ``` NoMethodError (undefined method `accept_pending_invitations!' for #<Email:0x00007fae8df17578>): app/controllers/concerns/accepts_pending_invitations.rb:7:in `accept_pending_invitations' app/controllers/confirmations_controller.rb:16:in `after_confirmation_path_for' ``` This fixes a regression introduced by !17634. Closes #49252
-rw-r--r--app/controllers/confirmations_controller.rb3
-rw-r--r--changelogs/unreleased/sh-fix-email-confirmations.yml5
-rw-r--r--spec/controllers/confirmations_controller_spec.rb46
-rw-r--r--spec/support/helpers/devise_helpers.rb4
4 files changed, 54 insertions, 4 deletions
diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb
index 7bc46a6ccc0..a7200b63b7e 100644
--- a/app/controllers/confirmations_controller.rb
+++ b/app/controllers/confirmations_controller.rb
@@ -13,10 +13,9 @@ class ConfirmationsController < Devise::ConfirmationsController
end
def after_confirmation_path_for(resource_name, resource)
- accept_pending_invitations
-
# incoming resource can either be a :user or an :email
if signed_in?(:user)
+ accept_pending_invitations
after_sign_in(resource)
else
Gitlab::AppLogger.info("Email Confirmed: username=#{resource.username} email=#{resource.email} ip=#{request.remote_ip}")
diff --git a/changelogs/unreleased/sh-fix-email-confirmations.yml b/changelogs/unreleased/sh-fix-email-confirmations.yml
new file mode 100644
index 00000000000..6472dbc4479
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-email-confirmations.yml
@@ -0,0 +1,5 @@
+---
+title: Fix e-mail verification returning a 500 Error
+merge_request: 20838
+author:
+type: fixed
diff --git a/spec/controllers/confirmations_controller_spec.rb b/spec/controllers/confirmations_controller_spec.rb
new file mode 100644
index 00000000000..e530b7d6dc5
--- /dev/null
+++ b/spec/controllers/confirmations_controller_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe ConfirmationsController do
+ include DeviseHelpers
+
+ describe 'GET #show' do
+ context 'with user' do
+ let(:token) { '123456' }
+ let(:user) { create(:user, confirmation_token: token, unconfirmed_email: 'test@example.com', confirmation_sent_at: Time.now, confirmed_at: nil) }
+
+ before do
+ set_devise_mapping(context: @request)
+ end
+
+ it 'confirms user' do
+ expect(user.confirmed?).to be_falsey
+
+ get :show, confirmation_token: token
+
+ expect(user.reload.confirmed?).to be_truthy
+ expect(response).to have_http_status(302)
+ end
+ end
+
+ context 'with e-mail' do
+ let(:token) { '987654' }
+ let(:user) { create(:user) }
+ let(:email) { create(:email, user: user, confirmation_token: token, confirmation_sent_at: Time.now, confirmed_at: nil) }
+
+ before do
+ set_devise_mapping(context: @request, resource: :email)
+ end
+
+ it 'confirms email' do
+ expect(email.confirmed?).to be_falsey
+
+ get :show, confirmation_token: token
+
+ expect(email.reload.confirmed?).to be_truthy
+ expect(response).to have_http_status(302)
+ end
+ end
+ end
+end
diff --git a/spec/support/helpers/devise_helpers.rb b/spec/support/helpers/devise_helpers.rb
index 66874e10f38..f321e68fb7e 100644
--- a/spec/support/helpers/devise_helpers.rb
+++ b/spec/support/helpers/devise_helpers.rb
@@ -1,10 +1,10 @@
module DeviseHelpers
# explicitly tells Devise which mapping to use
# this is needed when we are testing a Devise controller bypassing the router
- def set_devise_mapping(context:)
+ def set_devise_mapping(context:, resource: :user)
env = env_from_context(context)
- env['devise.mapping'] = Devise.mappings[:user] if env
+ env['devise.mapping'] = Devise.mappings[resource] if env
end
def env_from_context(context)