Commit 11b68bfe authored by Doug Stull's avatar Doug Stull

Clarify edge case accept and decline for invites

- when ldap or social sign in is used after an invite is sent,
  it is possible to have unaccepted invites out there.
parent 7eac9815
...@@ -7,15 +7,12 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do ...@@ -7,15 +7,12 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
let_it_be(:group) { create(:group, name: 'Owned') } let_it_be(:group) { create(:group, name: 'Owned') }
let_it_be(:project) { create(:project, :repository, namespace: group) } let_it_be(:project) { create(:project, :repository, namespace: group) }
let(:user) { create(:user, email: 'user@example.com') }
let(:group_invite) { group.group_members.invite.last } let(:group_invite) { group.group_members.invite.last }
before do before do
stub_application_setting(require_admin_approval_after_user_signup: false) stub_application_setting(require_admin_approval_after_user_signup: false)
project.add_maintainer(owner) project.add_maintainer(owner)
group.add_owner(owner) group.add_owner(owner)
group.add_developer('user@example.com', owner)
group_invite.generate_invite_token!
end end
def confirm_email(new_user) def confirm_email(new_user)
...@@ -45,45 +42,128 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do ...@@ -45,45 +42,128 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
click_button 'Get started!' click_button 'Get started!'
end end
context 'when signed out' do context 'when inviting a registered user' do
let(:invite_email) { 'user@example.com' }
before do before do
visit invite_path(group_invite.raw_invite_token) group.add_developer(invite_email, owner)
group_invite.generate_invite_token!
end end
it 'renders sign up page with sign up notice' do context 'when signed out' do
expect(current_path).to eq(new_user_registration_path) context 'when analyzing the redirects and forms from invite link click' do
expect(page).to have_content('To accept this invitation, create an account or sign in') before do
end visit invite_path(group_invite.raw_invite_token)
end
it 'pre-fills the "Username or email" field on the sign in box with the invite_email from the invite' do it 'renders sign up page with sign up notice' do
click_link 'Sign in' expect(current_path).to eq(new_user_registration_path)
expect(page).to have_content('To accept this invitation, create an account or sign in')
end
expect(find_field('Username or email').value).to eq(group_invite.invite_email) it 'pre-fills the "Username or email" field on the sign in box with the invite_email from the invite' do
end click_link 'Sign in'
it 'pre-fills the Email field on the sign up box with the invite_email from the invite' do expect(find_field('Username or email').value).to eq(group_invite.invite_email)
expect(find_field('Email').value).to eq(group_invite.invite_email) end
end
it 'sign in, grants access and redirects to group activity page' do it 'pre-fills the Email field on the sign up box with the invite_email from the invite' do
click_link 'Sign in' expect(find_field('Email').value).to eq(group_invite.invite_email)
end
end
fill_in_sign_in_form(user) context 'when invite is sent before account is created - ldap or social sign in for manual acceptance edge case' do
let(:user) { create(:user, email: 'user@example.com') }
expect(current_path).to eq(activity_group_path(group)) context 'when invite clicked and not signed in' do
end before do
end visit invite_path(group_invite.raw_invite_token)
end
context 'when signed in as an existing member' do it 'sign in, grants access and redirects to group activity page' do
before do click_link 'Sign in'
sign_in(owner)
end
it 'shows message user already a member' do fill_in_sign_in_form(user)
visit invite_path(group_invite.raw_invite_token)
expect(page).to have_link(owner.name, href: user_url(owner)) expect(current_path).to eq(activity_group_path(group))
expect(page).to have_content('However, you are already a member of this group.') end
end
context 'when signed in and an invite link is clicked' do
context 'when an invite email is a secondary email for the user' do
let(:invite_email) { 'user_secondary@example.com' }
before do
sign_in(user)
visit invite_path(group_invite.raw_invite_token)
end
it 'sends user to the invite url and allows them to decline' do
expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
expect(page).to have_content("Note that this invitation was sent to #{invite_email}")
expect(page).to have_content("but you are signed in as #{user.to_reference} with email #{user.email}")
click_link('Decline')
expect(page).to have_content('You have declined the invitation')
expect(current_path).to eq(dashboard_projects_path)
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
it 'sends uer to the invite url and allows them to accept' do
expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
expect(page).to have_content("Note that this invitation was sent to #{invite_email}")
expect(page).to have_content("but you are signed in as #{user.to_reference} with email #{user.email}")
click_link('Accept invitation')
expect(page).to have_content('You have been granted')
expect(current_path).to eq(activity_group_path(group))
end
end
context 'when user is an existing member' do
before do
sign_in(owner)
visit invite_path(group_invite.raw_invite_token)
end
it 'shows message user already a member' do
expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
expect(page).to have_link(owner.name, href: user_url(owner))
expect(page).to have_content('However, you are already a member of this group.')
end
end
end
context 'when declining the invitation from invitation reminder email' do
context 'when signed in' do
before do
sign_in(user)
visit decline_invite_path(group_invite.raw_invite_token)
end
it 'declines application and redirects to dashboard' do
expect(current_path).to eq(dashboard_projects_path)
expect(page).to have_content('You have declined the invitation to join group Owned.')
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
context 'when signed out with signup onboarding' do
before do
visit decline_invite_path(group_invite.raw_invite_token)
end
it 'declines application and redirects to sign in page' do
expect(current_path).to eq(decline_invite_path(group_invite.raw_invite_token))
expect(page).not_to have_content('You have declined the invitation to join')
expect(page).to have_content('You successfully declined the invitation')
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
end
end
end end
end end
...@@ -243,63 +323,13 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do ...@@ -243,63 +323,13 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
end end
end end
context 'when declining the invitation' do context 'when declining the invitation from invitation reminder email' do
context 'as an existing user' do it 'declines application and shows a decline page' do
let(:group_invite) { create(:group_member, user: user, group: group, created_by: owner) } visit decline_invite_path(group_invite.raw_invite_token)
context 'when signed in' do
before do
sign_in(user)
visit decline_invite_path(group_invite.raw_invite_token)
end
it 'declines application and redirects to dashboard' do
expect(current_path).to eq(dashboard_projects_path)
expect(page).to have_content('You have declined the invitation to join group Owned.')
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
context 'when signed out' do
before do
visit decline_invite_path(group_invite.raw_invite_token)
end
it 'declines application and redirects to sign in page' do
expect(current_path).to eq(new_user_session_path)
expect(page).to have_content('You have declined the invitation to join group Owned.')
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
end
context 'as a non-existing user' do
before do
visit decline_invite_path(group_invite.raw_invite_token)
end
it 'declines application and shows a decline page' do
expect(current_path).to eq(decline_invite_path(group_invite.raw_invite_token))
expect(page).to have_content('You successfully declined the invitation')
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
end
context 'when accepting the invitation as an existing user' do
before do
sign_in(user)
visit invite_path(group_invite.raw_invite_token)
end
it 'grants access and redirects to the group activity page' do
expect(group.users.include?(user)).to be false
page.click_link 'Accept invitation'
expect(current_path).to eq(activity_group_path(group)) expect(current_path).to eq(decline_invite_path(group_invite.raw_invite_token))
expect(page).to have_content('You have been granted Owner access to group Owned.') expect(page).to have_content('You successfully declined the invitation')
expect(group.users.include?(user)).to be true expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end end
end end
end end
......
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