Commit 5f5e13f8 authored by Jackie Fraser's avatar Jackie Fraser

Redirect new invited members to activity page

Redirects to the group or project activity page
when completing the welcome form after signing up
after visiting an invitation accept link, or when
they had a previous invitation before signing up.
parent ed19a0bd
......@@ -26,8 +26,7 @@ class InvitesController < ApplicationController
experiment('members/invite_email', actor: member).track(:accepted) if initial_invite_email?
session.delete(:invite_type)
redirect_to invite_details[:path], notice: _("You have been granted %{member_human_access} access to %{title} %{name}.") %
{ member_human_access: member.human_access, title: invite_details[:title], name: invite_details[:name] }
redirect_to invite_details[:path], notice: helpers.invite_accepted_notice(member)
else
redirect_back_or_default(options: { alert: _("The invitation could not be accepted.") })
end
......@@ -91,7 +90,7 @@ class InvitesController < ApplicationController
def authenticate_user!
return if current_user
store_location_for :user, request.fullpath
store_location_for(:user, invite_landing_url) if member
if user_sign_up?
redirect_to new_user_registration_path(invite_email: member.invite_email), notice: _("To accept this invitation, create an account or sign in.")
......@@ -116,6 +115,10 @@ class InvitesController < ApplicationController
end
end
def invite_landing_url
root_url + invite_details[:path]
end
def invite_details
@invite_details ||= case member.source
when Project
......@@ -123,14 +126,14 @@ class InvitesController < ApplicationController
name: member.source.full_name,
url: project_url(member.source),
title: _("project"),
path: project_path(member.source)
path: activity_project_path(member.source)
}
when Group
{
name: member.source.name,
url: group_url(member.source),
title: _("group"),
path: group_path(member.source)
path: activity_group_path(member.source)
}
end
end
......
......@@ -18,7 +18,11 @@ module Registrations
if result[:status] == :success
return redirect_to new_users_sign_up_group_path if show_signup_onboarding?
redirect_to path_for_signed_in_user(current_user)
if current_user.members.count == 1
redirect_to path_for_signed_in_user(current_user), notice: helpers.invite_accepted_notice(current_user.members.last)
else
redirect_to path_for_signed_in_user(current_user)
end
else
render :show
end
......@@ -48,7 +52,20 @@ module Registrations
def path_for_signed_in_user(user)
return users_almost_there_path if requires_confirmation?(user)
stored_location_for(user) || dashboard_projects_path
stored_location_for(user) || members_activity_path(user)
end
def members_activity_path(user)
return dashboard_projects_path unless user.members.count >= 1
case user.members.last.source
when Project
activity_project_path(user.members.last.source)
when Group
activity_group_path(user.members.last.source)
else
dashboard_projects_path
end
end
def show_signup_onboarding?
......
......@@ -46,6 +46,17 @@ module InviteMembersHelper
end
end
def invite_accepted_notice(member)
case member.source
when Project
_("You have been granted %{member_human_access} access to project %{name}.") %
{ member_human_access: member.human_access, name: member.source.name }
when Group
_("You have been granted %{member_human_access} access to group %{name}.") %
{ member_human_access: member.human_access, name: member.source.name }
end
end
private
def invite_members_url(form_model)
......
---
title: Redirect to activity page when accepting invitation
merge_request: 56695
author:
type: changed
......@@ -36159,7 +36159,10 @@ msgstr ""
msgid "You have been granted %{access_level} access to the %{source_name} %{source_type}."
msgstr ""
msgid "You have been granted %{member_human_access} access to %{title} %{name}."
msgid "You have been granted %{member_human_access} access to group %{name}."
msgstr ""
msgid "You have been granted %{member_human_access} access to project %{name}."
msgstr ""
msgid "You have been invited"
......
......@@ -64,13 +64,12 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
expect(find_field('Email').value).to eq(group_invite.invite_email)
end
it 'sign in, grants access and redirects to group page' do
it 'sign in, grants access and redirects to group activity page' do
click_link 'Sign in'
fill_in_sign_in_form(user)
expect(current_path).to eq(group_path(group))
expect(page).to have_content('You have been granted Developer access to group Owned.')
expect(current_path).to eq(activity_group_path(group))
end
end
......@@ -117,26 +116,28 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
context 'email confirmation disabled' do
let(:send_email_confirmation) { false }
it 'signs up and redirects to the dashboard page with all the projects/groups invitations automatically accepted' do
it 'signs up and redirects to the most recent membership activity page with all the projects/groups invitations automatically accepted' do
fill_in_sign_up_form(new_user)
fill_in_welcome_form
expect(current_path).to eq(dashboard_projects_path)
expect(page).to have_content(project.full_name)
expect(current_path).to eq(activity_group_path(group))
expect(page).to have_content('You have been granted Owner access to group Owned.')
visit group_path(group)
expect(page).to have_content(group.full_name)
visit project_path(project)
expect(page).to have_content(project.name)
end
context 'the user sign-up using a different email address' do
let(:invite_email) { build_stubbed(:user).email }
it 'signs up and redirects to the invitation page' do
it 'signs up and redirects to the activity page' do
fill_in_sign_up_form(new_user)
fill_in_welcome_form
expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
expect(current_path).to eq(activity_group_path(group))
end
end
end
......@@ -207,7 +208,7 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
fill_in_sign_in_form(new_user)
fill_in_welcome_form
expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
expect(current_path).to eq(activity_group_path(group))
end
end
......@@ -221,7 +222,7 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
fill_in_sign_up_form(new_user)
fill_in_welcome_form
expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
expect(current_path).to eq(activity_group_path(group))
end
end
end
......@@ -273,7 +274,7 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
end
end
context 'when accepting the invitation' do
context 'when accepting the invitation as an existing user' do
let(:send_email_confirmation) { true }
before do
......@@ -286,7 +287,7 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
page.click_link 'Accept invitation'
expect(current_path).to eq(group_path(group))
expect(current_path).to eq(activity_group_path(group))
expect(page).to have_content('You have been granted Owner access to group Owned.')
expect(group.users.include?(user)).to be true
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