Commit b1eb425e authored by charlie ablett's avatar charlie ablett

Merge branch 'refactor-unauthorized-user-project' into 'master'

Refactor unauthorized_user_project

See merge request gitlab-org/gitlab!30675
parents dc37eee0 4f17791f
...@@ -15,12 +15,20 @@ module API ...@@ -15,12 +15,20 @@ module API
find_personal_access_token_from_http_basic_auth find_personal_access_token_from_http_basic_auth
end end
def unauthorized_user_project
@unauthorized_user_project ||= find_project(params[:id])
end
def unauthorized_user_project!
unauthorized_user_project || not_found!
end
def authorized_user_project def authorized_user_project
@authorized_user_project ||= authorized_project_find!(params[:id]) @authorized_user_project ||= authorized_project_find!
end end
def authorized_project_find!(id) def authorized_project_find!
project = find_project(id) project = unauthorized_user_project
unless project && can?(current_user, :read_project, project) unless project && can?(current_user, :read_project, project)
return unauthorized_or! { not_found! } return unauthorized_or! { not_found! }
......
...@@ -43,10 +43,6 @@ module API ...@@ -43,10 +43,6 @@ module API
packages packages
end end
def unauthorized_user_project
@unauthorized_user_project ||= find_project(params[:id]) || not_found!
end
end end
before do before do
...@@ -59,7 +55,7 @@ module API ...@@ -59,7 +55,7 @@ module API
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
before do before do
authorize_packages_feature!(unauthorized_user_project) authorize_packages_feature!(unauthorized_user_project!)
end end
namespace ':id/packages/pypi' do namespace ':id/packages/pypi' do
...@@ -73,7 +69,7 @@ module API ...@@ -73,7 +69,7 @@ module API
end end
get 'files/:sha256/*file_identifier' do get 'files/:sha256/*file_identifier' do
project = unauthorized_user_project project = unauthorized_user_project!
filename = "#{params[:file_identifier]}.#{params[:format]}" filename = "#{params[:file_identifier]}.#{params[:format]}"
package = packages_finder(project).by_file_name_and_sha256(filename, params[:sha256]) package = packages_finder(project).by_file_name_and_sha256(filename, params[:sha256])
......
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