Commit 5e933a4d authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '53671-redirect-projects-id-to-project-page' into 'master'

Resolve "Redirect projects/:id to project page"

Closes #53671

See merge request gitlab-org/gitlab-ce!24467
parents ed1da730 f13edec8
...@@ -10,10 +10,10 @@ class ProjectsController < Projects::ApplicationController ...@@ -10,10 +10,10 @@ class ProjectsController < Projects::ApplicationController
prepend_before_action(only: [:show]) { authenticate_sessionless_user!(:rss) } prepend_before_action(only: [:show]) { authenticate_sessionless_user!(:rss) }
before_action :whitelist_query_limiting, only: [:create] before_action :whitelist_query_limiting, only: [:create]
before_action :authenticate_user!, except: [:index, :show, :activity, :refs] before_action :authenticate_user!, except: [:index, :show, :activity, :refs, :resolve]
before_action :redirect_git_extension, only: [:show] before_action :redirect_git_extension, only: [:show]
before_action :project, except: [:index, :new, :create] before_action :project, except: [:index, :new, :create, :resolve]
before_action :repository, except: [:index, :new, :create] before_action :repository, except: [:index, :new, :create, :resolve]
before_action :assign_ref_vars, only: [:show], if: :repo_exists? before_action :assign_ref_vars, only: [:show], if: :repo_exists?
before_action :tree, only: [:show], if: [:repo_exists?, :project_view_files?] before_action :tree, only: [:show], if: [:repo_exists?, :project_view_files?]
before_action :lfs_blob_ids, only: [:show], if: [:repo_exists?, :project_view_files?] before_action :lfs_blob_ids, only: [:show], if: [:repo_exists?, :project_view_files?]
...@@ -442,4 +442,14 @@ class ProjectsController < Projects::ApplicationController ...@@ -442,4 +442,14 @@ class ProjectsController < Projects::ApplicationController
def present_project def present_project
@project = @project.present(current_user: current_user) @project = @project.present(current_user: current_user)
end end
def resolve
@project = Project.find(params[:id])
if can?(current_user, :read_project, @project)
redirect_to @project
else
render_404
end
end
end end
---
title: Redirect GET projects/:id to project page
merge_request: 24467
author:
type: added
...@@ -2,6 +2,8 @@ resources :projects, only: [:index, :new, :create] ...@@ -2,6 +2,8 @@ resources :projects, only: [:index, :new, :create]
draw :git_http draw :git_http
get '/projects/:id' => 'projects#resolve'
constraints(::Constraints::ProjectUrlConstrainer.new) do constraints(::Constraints::ProjectUrlConstrainer.new) do
# If the route has a wildcard segment, the segment has a regex constraint, # If the route has a wildcard segment, the segment has a regex constraint,
# the segment is potentially followed by _another_ wildcard segment, and # the segment is potentially followed by _another_ wildcard segment, and
......
...@@ -163,3 +163,10 @@ machine example.gitlab.com ...@@ -163,3 +163,10 @@ machine example.gitlab.com
login <gitlab_user_name> login <gitlab_user_name>
password <personal_access_token> password <personal_access_token>
``` ```
## Access project page with project ID
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/53671) in GitLab 11.8.
To quickly access a project from the GitLab UI using the project ID,
visit the `/projects/:id` URL in your browser or other tool accessing the project.
...@@ -955,6 +955,59 @@ describe ProjectsController do ...@@ -955,6 +955,59 @@ describe ProjectsController do
end end
end end
describe 'GET resolve' do
shared_examples 'resolvable endpoint' do
it 'redirects to the project page' do
get :resolve, params: { id: project.id }
expect(response).to have_gitlab_http_status(302)
expect(response).to redirect_to(project_path(project))
end
end
context 'with an authenticated user' do
before do
sign_in(user)
end
context 'when user has access to the project' do
before do
project.add_developer(user)
end
it_behaves_like 'resolvable endpoint'
end
context 'when user has no access to the project' do
it 'gives 404 for existing project' do
get :resolve, params: { id: project.id }
expect(response).to have_gitlab_http_status(404)
end
end
it 'gives 404 for non-existing project' do
get :resolve, params: { id: '0' }
expect(response).to have_gitlab_http_status(404)
end
end
context 'non authenticated user' do
context 'with a public project' do
let(:project) { public_project }
it_behaves_like 'resolvable endpoint'
end
it 'gives 404 for private project' do
get :resolve, params: { id: project.id }
expect(response).to have_gitlab_http_status(404)
end
end
end
def project_moved_message(redirect_route, project) def project_moved_message(redirect_route, project)
"Project '#{redirect_route.path}' was moved to '#{project.full_path}'. Please update any links and bookmarks that may still have the old path." "Project '#{redirect_route.path}' was moved to '#{project.full_path}'. Please update any links and bookmarks that may still have the old path."
end end
......
...@@ -122,6 +122,10 @@ describe 'project routing' do ...@@ -122,6 +122,10 @@ describe 'project routing' do
route_to('projects#preview_markdown', namespace_id: 'gitlab', id: 'gitlabhq') route_to('projects#preview_markdown', namespace_id: 'gitlab', id: 'gitlabhq')
) )
end end
it 'to #resolve' do
expect(get('/projects/1')).to route_to('projects#resolve', id: '1')
end
end end
# members_namespace_project_autocomplete_sources_path GET /:project_id/autocomplete_sources/members(.:format) projects/autocomplete_sources#members # members_namespace_project_autocomplete_sources_path GET /:project_id/autocomplete_sources/members(.:format) projects/autocomplete_sources#members
......
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