Commit 3a696abf authored by Jackie Fraser's avatar Jackie Fraser Committed by Stan Hu

Refactor activity_path into separate model methods

parent 06c9f530
......@@ -125,14 +125,14 @@ class InvitesController < ApplicationController
name: member.source.full_name,
url: project_url(member.source),
title: _("project"),
path: activity_project_path(member.source)
path: member.source.activity_path
}
when Group
{
name: member.source.name,
url: group_url(member.source),
title: _("group"),
path: activity_group_path(member.source)
path: member.source.activity_path
}
end
end
......
......@@ -18,8 +18,10 @@ module Registrations
if result[:status] == :success
return redirect_to new_users_sign_up_group_path if show_signup_onboarding?
if current_user.members.count == 1
redirect_to path_for_signed_in_user(current_user), notice: helpers.invite_accepted_notice(current_user.members.last)
members = current_user.members
if members.count == 1 && members.last.source.present?
redirect_to members_activity_path(members), notice: helpers.invite_accepted_notice(members.last)
else
redirect_to path_for_signed_in_user(current_user)
end
......@@ -52,20 +54,14 @@ module Registrations
def path_for_signed_in_user(user)
return users_almost_there_path if requires_confirmation?(user)
stored_location_for(user) || members_activity_path(user)
stored_location_for(user) || members_activity_path(user.members)
end
def members_activity_path(user)
return dashboard_projects_path unless user.members.count >= 1
def members_activity_path(members)
return dashboard_projects_path unless members.any?
return dashboard_projects_path unless members.last.source.present?
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
members.last.source.activity_path
end
def show_signup_onboarding?
......
......@@ -708,6 +708,10 @@ class Group < Namespace
model_name.singular
end
def activity_path
Gitlab::Routing.url_helpers.activity_group_path(self)
end
private
def update_two_factor_requirement
......
......@@ -2570,6 +2570,10 @@ class Project < ApplicationRecord
Feature.enabled?(:inherited_issuable_templates, self, default_enabled: :yaml)
end
def activity_path
Gitlab::Routing.url_helpers.activity_project_path(self)
end
private
def set_container_registry_access_level
......
......@@ -77,6 +77,30 @@ RSpec.describe Registrations::WelcomeController do
it { is_expected.to redirect_to(dashboard_projects_path)}
context 'when the new user already has any accepted group membership' do
let!(:member1) { create(:group_member, user: user) }
it 'redirects to the group activity page' do
expect(subject).to redirect_to(activity_group_path(member1.source))
end
context 'when the new user already has more than 1 accepted group membership' do
it 'redirects to the most recent membership group activty page' do
member2 = create(:group_member, user: user)
expect(subject).to redirect_to(activity_group_path(member2.source))
end
end
context 'when the member has an orphaned source at the time of the welcome' do
it 'redirects to the project dashboard page' do
member1.source.delete
expect(subject).to redirect_to(dashboard_projects_path)
end
end
end
context 'when the user opted in' do
let(:email_opted_in) { '1' }
......
......@@ -2398,4 +2398,12 @@ RSpec.describe Group do
expect(group.to_ability_name).to eq('group')
end
end
describe '#activity_path' do
it 'returns the group activity_path' do
expected_path = "/groups/#{group.name}/-/activity"
expect(group.activity_path).to eq(expected_path)
end
end
end
......@@ -6890,6 +6890,14 @@ RSpec.describe Project, factory_default: :keep do
end
end
end
describe '#activity_path' do
it 'returns the project activity_path' do
expected_path = "/#{project.namespace.path}/#{project.name}/activity"
expect(project.activity_path).to eq(expected_path)
end
end
end
describe '#default_branch_or_main' do
......
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