Commit c099074fcc96304d948cc028ff7ae5913b561ed3
1 parent
23d180f5
Exists in
master
and in
4 other branches
Fix 404 on project page for unauthenticated user
Eliminate a 404 error when user is not logged in and attempts to visit a project page. The 404 page will still show up when user is logged in and the project doesn’t exist or the user doesn’t have access.
Showing
7 changed files
with
71 additions
and
6 deletions
Show diff stats
CHANGELOG
| ... | ... | @@ -8,6 +8,7 @@ v 6.4.0 |
| 8 | 8 | - Internal projects (Jason Hollingsworth) |
| 9 | 9 | - Allow removal of avatar (Drew Blessing) |
| 10 | 10 | - Project web hooks now support issues and merge request events |
| 11 | + - Visiting project page while not logged in will redirect to sign-in instead of 404 (Jason Hollingsworth) | |
| 11 | 12 | |
| 12 | 13 | v 6.3.0 |
| 13 | 14 | - API for adding gitlab-ci service | ... | ... |
app/controllers/application_controller.rb
| ... | ... | @@ -81,6 +81,9 @@ class ApplicationController < ActionController::Base |
| 81 | 81 | |
| 82 | 82 | if @project and can?(current_user, :read_project, @project) |
| 83 | 83 | @project |
| 84 | + elsif current_user.nil? | |
| 85 | + @project = nil | |
| 86 | + authenticate_user! | |
| 84 | 87 | else |
| 85 | 88 | @project = nil |
| 86 | 89 | render_404 and return | ... | ... |
| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | +Feature: Project Redirects | |
| 2 | + Background: | |
| 3 | + Given public project "Community" | |
| 4 | + And private project "Enterprise" | |
| 5 | + | |
| 6 | + Scenario: I visit public project page | |
| 7 | + When I visit project "Community" page | |
| 8 | + Then I should see project "Community" home page | |
| 9 | + | |
| 10 | + Scenario: I visit private project page | |
| 11 | + When I visit project "Enterprise" page | |
| 12 | + Then I should be redirected to sign in page | |
| 13 | + | |
| 14 | + Scenario: I visit a non-existent project page | |
| 15 | + When I visit project "CommunityDoesNotExist" page | |
| 16 | + Then I should be redirected to sign in page | |
| 17 | + | |
| 18 | + Scenario: I visit a non-existent project page as user | |
| 19 | + Given I sign in as a user | |
| 20 | + When I visit project "CommunityDoesNotExist" page | |
| 21 | + Then page status code should be 404 | |
| 22 | + | |
| 23 | + Scenario: I visit unauthorized project page as user | |
| 24 | + Given I sign in as a user | |
| 25 | + When I visit project "Enterprise" page | |
| 26 | + Then page status code should be 404 | ... | ... |
features/public/public_projects.feature
| ... | ... | @@ -16,11 +16,11 @@ Feature: Public Projects Feature |
| 16 | 16 | |
| 17 | 17 | Scenario: I visit internal project page |
| 18 | 18 | When I visit project "Internal" page |
| 19 | - Then page status code should be 404 | |
| 19 | + Then I should be redirected to sign in page | |
| 20 | 20 | |
| 21 | 21 | Scenario: I visit private project page |
| 22 | 22 | When I visit project "Enterprise" page |
| 23 | - Then page status code should be 404 | |
| 23 | + Then I should be redirected to sign in page | |
| 24 | 24 | |
| 25 | 25 | Scenario: I visit an empty public project page |
| 26 | 26 | Given public empty project "Empty Public Project" | ... | ... |
features/steps/profile/profile.rb
| ... | ... | @@ -88,10 +88,6 @@ class Profile < Spinach::FeatureSteps |
| 88 | 88 | page.should have_content "Password doesn't match confirmation" |
| 89 | 89 | end |
| 90 | 90 | |
| 91 | - step 'I should be redirected to sign in page' do | |
| 92 | - current_path.should == new_user_session_path | |
| 93 | - end | |
| 94 | - | |
| 95 | 91 | step 'I reset my token' do |
| 96 | 92 | within '.update-token' do |
| 97 | 93 | @old_token = @user.private_token | ... | ... |
| ... | ... | @@ -0,0 +1,35 @@ |
| 1 | +class Spinach::Features::ProjectRedirects < Spinach::FeatureSteps | |
| 2 | + include SharedAuthentication | |
| 3 | + include SharedPaths | |
| 4 | + include SharedProject | |
| 5 | + | |
| 6 | + step 'public project "Community"' do | |
| 7 | + create :project_with_code, name: 'Community', visibility_level: Gitlab::VisibilityLevel::PUBLIC | |
| 8 | + end | |
| 9 | + | |
| 10 | + step 'private project "Enterprise"' do | |
| 11 | + create :project, name: 'Enterprise' | |
| 12 | + end | |
| 13 | + | |
| 14 | + step 'I visit project "Community" page' do | |
| 15 | + project = Project.find_by_name('Community') | |
| 16 | + visit project_path(project) | |
| 17 | + end | |
| 18 | + | |
| 19 | + step 'I should see project "Community" home page' do | |
| 20 | + within '.project-home-title' do | |
| 21 | + page.should have_content 'Community' | |
| 22 | + end | |
| 23 | + end | |
| 24 | + | |
| 25 | + step 'I visit project "Enterprise" page' do | |
| 26 | + project = Project.find_by_name('Enterprise') | |
| 27 | + visit project_path(project) | |
| 28 | + end | |
| 29 | + | |
| 30 | + step 'I visit project "CommunityDoesNotExist" page' do | |
| 31 | + project = Project.find_by_name('Community') | |
| 32 | + visit project_path(project) + 'DoesNotExist' | |
| 33 | + end | |
| 34 | +end | |
| 35 | + | ... | ... |
features/steps/shared/authentication.rb