Commit 2fadc941 authored by Stan Hu's avatar Stan Hu

Merge branch...

Merge branch '241359-nomethoderror-undefined-method-invite_email-for-actionview-outputbuffer-0x00007f0fca8da640' into 'master'

Resolve NoMethodError: undefined method invite_email

Closes #241359

See merge request gitlab-org/gitlab!41587
parents 1ed313c6 f27f14f4
...@@ -76,8 +76,12 @@ class InvitesController < ApplicationController ...@@ -76,8 +76,12 @@ class InvitesController < ApplicationController
notice << "or create an account" if Gitlab::CurrentSettings.allow_signup? notice << "or create an account" if Gitlab::CurrentSettings.allow_signup?
notice = notice.join(' ') + "." notice = notice.join(' ') + "."
initial_member = Member.find_by_invite_token(params[:id])
redirect_params = initial_member ? { invite_email: member.invite_email } : {}
store_location_for :user, request.fullpath store_location_for :user, request.fullpath
redirect_to new_user_session_path(invite_email: member.invite_email), notice: notice
redirect_to new_user_session_path(redirect_params), notice: notice
end end
def invite_details def invite_details
......
...@@ -161,8 +161,8 @@ class Member < ApplicationRecord ...@@ -161,8 +161,8 @@ class Member < ApplicationRecord
where(user_id: user_ids).has_access.pluck(:user_id, :access_level).to_h where(user_id: user_ids).has_access.pluck(:user_id, :access_level).to_h
end end
def find_by_invite_token(invite_token) def find_by_invite_token(raw_invite_token)
invite_token = Devise.token_generator.digest(self, :invite_token, invite_token) invite_token = Devise.token_generator.digest(self, :invite_token, raw_invite_token)
find_by(invite_token: invite_token) find_by(invite_token: invite_token)
end end
......
---
title: 'Resolve NoMethodError: undefined method invite_email'
merge_request: 41587
author:
type: fixed
...@@ -3,23 +3,26 @@ ...@@ -3,23 +3,26 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe InvitesController do RSpec.describe InvitesController do
let(:token) { '123456' }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:member) { create(:project_member, :invited, invite_token: token, invite_email: user.email) } let(:member) { create(:project_member, :invited, invite_email: user.email) }
let(:raw_invite_token) { member.raw_invite_token }
let(:project_members) { member.source.users } let(:project_members) { member.source.users }
let(:md5_member_global_id) { Digest::MD5.hexdigest(member.to_global_id.to_s) } let(:md5_member_global_id) { Digest::MD5.hexdigest(member.to_global_id.to_s) }
let(:params) { { id: raw_invite_token } }
before do before do
stub_application_setting(snowplow_enabled: true, snowplow_collector_hostname: 'localhost') stub_application_setting(snowplow_enabled: true, snowplow_collector_hostname: 'localhost')
controller.instance_variable_set(:@member, member) controller.instance_variable_set(:@member, member)
sign_in(user)
end end
describe 'GET #show' do describe 'GET #show' do
let(:params) { { id: token } }
subject(:request) { get :show, params: params } subject(:request) { get :show, params: params }
context 'when logged in' do
before do
sign_in(user)
end
it 'accepts user if invite email matches signed in user' do it 'accepts user if invite email matches signed in user' do
expect do expect do
request request
...@@ -49,7 +52,7 @@ RSpec.describe InvitesController do ...@@ -49,7 +52,7 @@ RSpec.describe InvitesController do
end end
context 'when new_user_invite is experiment' do context 'when new_user_invite is experiment' do
let(:params) { { id: token, new_user_invite: 'experiment' } } let(:params) { { id: raw_invite_token, new_user_invite: 'experiment' } }
it 'tracks the user as experiment group' do it 'tracks the user as experiment group' do
expect(Gitlab::Tracking).to receive(:event).and_call_original.with( expect(Gitlab::Tracking).to receive(:event).and_call_original.with(
...@@ -70,7 +73,7 @@ RSpec.describe InvitesController do ...@@ -70,7 +73,7 @@ RSpec.describe InvitesController do
end end
context 'when new_user_invite is control' do context 'when new_user_invite is control' do
let(:params) { { id: token, new_user_invite: 'control' } } let(:params) { { id: raw_invite_token, new_user_invite: 'control' } }
it 'tracks the user as control group' do it 'tracks the user as control group' do
expect(Gitlab::Tracking).to receive(:event).and_call_original.with( expect(Gitlab::Tracking).to receive(:event).and_call_original.with(
...@@ -91,8 +94,31 @@ RSpec.describe InvitesController do ...@@ -91,8 +94,31 @@ RSpec.describe InvitesController do
end end
end end
context 'when not logged in' do
context 'when inviter is a member' do
it 'is redirected to a new session with invite email param' do
request
expect(response).to redirect_to(new_user_session_path(invite_email: member.invite_email))
end
end
context 'when inviter is not a member' do
let(:params) { { id: '_bogus_token_' } }
it 'is redirected to a new session' do
request
expect(response).to redirect_to(new_user_session_path)
end
end
end
end
describe 'POST #accept' do describe 'POST #accept' do
let(:params) { { id: token } } before do
sign_in(user)
end
subject(:request) { post :accept, params: params } subject(:request) { post :accept, params: params }
...@@ -105,7 +131,7 @@ RSpec.describe InvitesController do ...@@ -105,7 +131,7 @@ RSpec.describe InvitesController do
end end
context 'when new_user_invite is experiment' do context 'when new_user_invite is experiment' do
let(:params) { { id: token, new_user_invite: 'experiment' } } let(:params) { { id: raw_invite_token, new_user_invite: 'experiment' } }
it 'tracks the user as experiment group' do it 'tracks the user as experiment group' do
expect(Gitlab::Tracking).to receive(:event).and_call_original.with( expect(Gitlab::Tracking).to receive(:event).and_call_original.with(
...@@ -120,7 +146,7 @@ RSpec.describe InvitesController do ...@@ -120,7 +146,7 @@ RSpec.describe InvitesController do
end end
context 'when new_user_invite is control' do context 'when new_user_invite is control' do
let(:params) { { id: token, new_user_invite: 'control' } } let(:params) { { id: raw_invite_token, new_user_invite: 'control' } }
it 'tracks the user as control group' do it 'tracks the user as control group' do
expect(Gitlab::Tracking).to receive(:event).and_call_original.with( expect(Gitlab::Tracking).to receive(:event).and_call_original.with(
......
...@@ -630,6 +630,14 @@ RSpec.describe Member do ...@@ -630,6 +630,14 @@ RSpec.describe Member do
end end
end end
describe '.find_by_invite_token' do
let!(:member) { create(:project_member, invite_email: "user@example.com", user: nil) }
it 'finds the member' do
expect(described_class.find_by_invite_token(member.raw_invite_token)).to eq member
end
end
describe "#invite_to_unknown_user?" do describe "#invite_to_unknown_user?" do
subject { member.invite_to_unknown_user? } subject { member.invite_to_unknown_user? }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment