Commit 676529b2 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'copy-project-homepage-default-view-for-anonoymous-users' into 'master'

Copy project homepage default view for anonoymous users

See merge request gitlab-org/gitlab!44606
parents 81bae8c1 95ea8bdf
......@@ -65,14 +65,14 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
if can?(current_user, :download_code, project)
user_view
elsif user_view == "activity"
"activity"
elsif can?(current_user, :read_wiki, project)
"wiki"
elsif feature_available?(:issues, current_user)
"projects/issues/issues"
elsif user_view == 'activity'
'activity'
elsif project.wiki_repository_exists? && can?(current_user, :read_wiki, project)
'wiki'
elsif can?(current_user, :read_issue, project)
'projects/issues/issues'
else
"customize_workflow"
'activity'
end
end
......@@ -407,6 +407,10 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
def anonymous_project_view
if !project.empty_repo? && can?(current_user, :download_code, project)
'files'
elsif project.wiki_repository_exists? && can?(current_user, :read_wiki, project)
'wiki'
elsif can?(current_user, :read_issue, project)
'projects/issues/issues'
else
'activity'
end
......
---
title: Copy project homepage default view for anonymous users
merge_request: 44606
author: George Tsiolis
type: changed
......@@ -213,13 +213,13 @@ RSpec.describe ProjectsController do
expect(assigns(:issuable_meta_data)).not_to be_nil
end
it 'shows customize workflow page if wiki and issues are disabled' do
it 'shows activity page if wiki and issues are disabled' do
project.project_feature.update_attribute(:wiki_access_level, ProjectFeature::DISABLED)
project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED)
get :show, params: { namespace_id: project.namespace, id: project }
expect(response).to render_template("projects/_customize_workflow")
expect(response).to render_template("projects/_activity")
end
it 'shows activity if enabled by user' do
......
......@@ -201,7 +201,7 @@ RSpec.describe 'Edit Project Settings' do
visit project_path(project)
expect(page).to have_content "Customize your workflow!"
expect(page).to have_content "joined project"
end
it "hides project activity tabs" do
......
......@@ -128,6 +128,59 @@ RSpec.describe 'Projects > User sees sidebar' do
end
end
context 'as anonymous' do
let(:project) { create(:project, :public) }
let!(:issue) { create(:issue, :opened, project: project, author: user) }
describe 'project landing page' do
before do
project.project_feature.update!(
builds_access_level: ProjectFeature::DISABLED,
merge_requests_access_level: ProjectFeature::DISABLED,
repository_access_level: ProjectFeature::DISABLED,
issues_access_level: ProjectFeature::DISABLED,
wiki_access_level: ProjectFeature::DISABLED
)
end
it 'does not show the project file list landing page, but the activity' do
visit project_path(project)
expect(page).not_to have_selector '.project-stats'
expect(page).not_to have_selector '.project-last-commit'
expect(page).not_to have_selector '.project-show-files'
expect(page).to have_selector '.project-show-activity'
end
it 'shows the wiki when enabled' do
project.project_feature.update!(wiki_access_level: ProjectFeature::ENABLED)
visit project_path(project)
expect(page).to have_selector '.project-show-wiki'
end
it 'shows the issues when enabled' do
project.project_feature.update!(issues_access_level: ProjectFeature::ENABLED)
visit project_path(project)
expect(page).to have_selector '.issues-list'
end
it 'shows the wiki when wiki and issues are enabled' do
project.project_feature.update!(
issues_access_level: ProjectFeature::ENABLED,
wiki_access_level: ProjectFeature::ENABLED
)
visit project_path(project)
expect(page).to have_selector '.project-show-wiki'
end
end
end
context 'as guest' do
let(:guest) { create(:user) }
let!(:issue) { create(:issue, :opened, project: project, author: guest) }
......@@ -194,13 +247,13 @@ RSpec.describe 'Projects > User sees sidebar' do
expect(page).not_to have_selector '.project-stats'
expect(page).not_to have_selector '.project-last-commit'
expect(page).not_to have_selector '.project-show-files'
expect(page).to have_selector '.project-show-customize_workflow'
expect(page).to have_selector '.project-show-activity'
end
it 'shows the customize workflow when issues and wiki are disabled' do
it 'shows the project activity when issues and wiki are disabled' do
visit project_path(project)
expect(page).to have_selector '.project-show-customize_workflow'
expect(page).to have_selector '.project-show-activity'
end
it 'shows the wiki when enabled' do
......
......@@ -38,14 +38,33 @@ RSpec.describe ProjectPresenter do
context 'when repository is empty' do
let_it_be(:project) { create(:project_empty_repo, :public) }
it 'returns activity if user has repository access' do
it 'returns wiki if user has repository access and can read wiki, which exists' do
allow(project).to receive(:wiki_repository_exists?).and_return(true)
allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(true)
allow(presenter).to receive(:can?).with(nil, :read_wiki, project).and_return(true)
allow(presenter).to receive(:can?).with(nil, :read_issue, project).and_return(false)
expect(presenter.default_view).to eq('wiki')
end
it 'returns activity if user has repository access and can read wiki, which does not exist' do
allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(true)
allow(presenter).to receive(:can?).with(nil, :read_wiki, project).and_return(true)
allow(presenter).to receive(:can?).with(nil, :read_issue, project).and_return(false)
expect(presenter.default_view).to eq('activity')
end
it 'returns activity if user does not have repository access' do
allow(project).to receive(:can?).with(nil, :download_code, project).and_return(false)
it 'returns issues if user does not have repository access, but can read issues' do
allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(false)
allow(presenter).to receive(:can?).with(nil, :read_issue, project).and_call_original
expect(presenter.default_view).to eq('projects/issues/issues')
end
it 'returns activity if user can read neither wiki nor issues' do
allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(false)
allow(presenter).to receive(:can?).with(nil, :read_issue, project).and_return(false)
expect(presenter.default_view).to eq('activity')
end
......@@ -61,8 +80,18 @@ RSpec.describe ProjectPresenter do
expect(presenter.default_view).to eq('files')
end
it 'returns activity if user does not have repository access' do
it 'returns wiki if user does not have repository access and can read wiki, which exists' do
allow(project).to receive(:wiki_repository_exists?).and_return(true)
allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(false)
allow(presenter).to receive(:can?).with(nil, :read_wiki, project).and_return(true)
expect(presenter.default_view).to eq('wiki')
end
it 'returns activity if user does not have repository or wiki access' do
allow(presenter).to receive(:can?).with(nil, :download_code, project).and_return(false)
allow(presenter).to receive(:can?).with(nil, :read_issue, project).and_return(false)
allow(presenter).to receive(:can?).with(nil, :read_wiki, project).and_return(false)
expect(presenter.default_view).to eq('activity')
end
......@@ -96,22 +125,25 @@ RSpec.describe ProjectPresenter do
allow(presenter).to receive(:can?).with(user, :download_code, project).and_return(false)
end
it 'returns wiki if the user has the right policy' do
it 'returns wiki if the user has the right policy and the wiki exists' do
allow(project).to receive(:wiki_repository_exists?).and_return(true)
allow(presenter).to receive(:can?).with(user, :read_wiki, project).and_return(true)
expect(presenter.default_view).to eq('wiki')
end
it 'returns customize_workflow if the user does not have the right policy' do
it 'returns activity if the user does not have the right policy' do
allow(presenter).to receive(:can?).with(user, :read_wiki, project).and_return(false)
allow(presenter).to receive(:can?).with(user, :read_issue, project).and_return(false)
expect(presenter.default_view).to eq('customize_workflow')
expect(presenter.default_view).to eq('activity')
end
end
context 'with issues as a feature available' do
it 'return issues' do
allow(presenter).to receive(:can?).with(user, :download_code, project).and_return(false)
allow(presenter).to receive(:can?).with(user, :read_issue, project).and_return(true)
allow(presenter).to receive(:can?).with(user, :read_wiki, project).and_return(false)
expect(presenter.default_view).to eq('projects/issues/issues')
......@@ -119,12 +151,13 @@ RSpec.describe ProjectPresenter do
end
context 'with no activity, no wikies and no issues' do
it 'returns customize_workflow as default' do
it 'returns activity as default' do
project.project_feature.update_attribute(:issues_access_level, 0)
allow(presenter).to receive(:can?).with(user, :download_code, project).and_return(false)
allow(presenter).to receive(:can?).with(user, :read_wiki, project).and_return(false)
allow(presenter).to receive(:can?).with(user, :read_issue, project).and_return(false)
expect(presenter.default_view).to eq('customize_workflow')
expect(presenter.default_view).to eq('activity')
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