Commit 4f17791f authored by Giorgenes Gelatti's avatar Giorgenes Gelatti

Refactor unauthorized_user_project helper

Move helper to packages/basic_auth_helpers
and refactor so find_project() is called
only once.
parent b898ff1d
......@@ -15,12 +15,20 @@ module API
find_personal_access_token_from_http_basic_auth
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
@authorized_user_project ||= authorized_project_find!(params[:id])
@authorized_user_project ||= authorized_project_find!
end
def authorized_project_find!(id)
project = find_project(id)
def authorized_project_find!
project = unauthorized_user_project
unless project && can?(current_user, :read_project, project)
return unauthorized_or! { not_found! }
......
......@@ -43,10 +43,6 @@ module API
packages
end
def unauthorized_user_project
@unauthorized_user_project ||= find_project(params[:id]) || not_found!
end
end
before do
......@@ -59,7 +55,7 @@ module API
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
before do
authorize_packages_feature!(unauthorized_user_project)
authorize_packages_feature!(unauthorized_user_project!)
end
namespace ':id/packages/pypi' do
......@@ -73,7 +69,7 @@ module API
end
get 'files/:sha256/*file_identifier' do
project = unauthorized_user_project
project = unauthorized_user_project!
filename = "#{params[:file_identifier]}.#{params[:format]}"
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