Commit b73edc5e authored by Douwe Maan's avatar Douwe Maan Committed by Rémy Coutable

Merge branch '23990-project-show-error-when-empty-repo' into 'master'

500 error on project show when user is not logged in and project is still empty

## What does this MR do?

Aims to fix the 500 error when the project is empty and the user is not logged in and tries to access project#show

## Screenshots (if relevant)
When the project is empty and the user is not logged in we default to the empty project partial instead of readme.

![Screen_Shot_2016-11-11_at_22.54.21](/uploads/3d87e65195376c85d3e515e6d5a9a850/Screen_Shot_2016-11-11_at_22.54.21.png)

## Does this MR meet the acceptance criteria?

- [x] [Changelog entry](https://docs.gitlab.com/ce/development/changelog.html) added
- [x] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [x] API support added
- Tests
  - [x] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if it does - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?

Closes #23990

See merge request !7376
parent 4ed4b1b9
...@@ -50,7 +50,7 @@ module PreferencesHelper ...@@ -50,7 +50,7 @@ module PreferencesHelper
end end
def default_project_view def default_project_view
return 'readme' unless current_user return anonymous_project_view unless current_user
user_view = current_user.project_view user_view = current_user.project_view
...@@ -66,4 +66,8 @@ module PreferencesHelper ...@@ -66,4 +66,8 @@ module PreferencesHelper
"customize_workflow" "customize_workflow"
end end
end end
def anonymous_project_view
@project.empty_repo? || !can?(current_user, :download_code, @project) ? 'activity' : 'readme'
end
end end
---
title: fixes 500 error on project show when user is not logged in and project is still empty
merge_request: 7376
author:
...@@ -85,4 +85,45 @@ describe PreferencesHelper do ...@@ -85,4 +85,45 @@ describe PreferencesHelper do
and_return(double('user', messages)) and_return(double('user', messages))
end end
end end
describe '#default_project_view' do
context 'user not signed in' do
before do
helper.instance_variable_set(:@project, project)
stub_user
end
context 'when repository is empty' do
let(:project) { create(:project_empty_repo, :public) }
it 'returns activity if user has repository access' do
allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(true)
expect(helper.default_project_view).to eq('activity')
end
it 'returns activity if user does not have repository access' do
allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(false)
expect(helper.default_project_view).to eq('activity')
end
end
context 'when repository is not empty' do
let(:project) { create(:project, :public) }
it 'returns readme if user has repository access' do
allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(true)
expect(helper.default_project_view).to eq('readme')
end
it 'returns activity if user does not have repository access' do
allow(helper).to receive(:can?).with(nil, :download_code, project).and_return(false)
expect(helper.default_project_view).to eq('activity')
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