Skip to content

Commit

Permalink
Always let backend respond for request to source/:project_name
Browse files Browse the repository at this point in the history
Right now we use the presence of the `deleted` query parameter
as a workaround in order to force the request being passed
directly to the backend and returning results based on the
backend data over returning results based on frontend database data.

This workaround currently leads to inconsistant results being returned
by the API.

Instead of using this workaround we better should always
let the backend handle the request and return the data based on
it's info.

Fixes openSUSE#16911
  • Loading branch information
krauselukas committed Oct 14, 2024
1 parent dab669b commit fdcf3ff
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions src/api/app/controllers/source_project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ class SourceProjectController < SourceController
# GET /source/:project
def show
project_name = params[:project]
if params.key?(:deleted)

if params[:deleted] == '1'
unless Project.find_by_name(project_name) || Project.is_remote_project?(project_name)
# project is deleted or not accessible
validate_visibility_of_deleted_project(project_name)
end
pass_to_backend
return
end

if Project.is_remote_project?(project_name)
# not a local project, hand over to backend
unless params.key?(:view)
pass_to_backend
return
end
Expand All @@ -23,39 +21,29 @@ def show
raise Project::UnknownObjectError, "Project not found: #{project_name}" unless @project

# we let the backend list the packages after we verified the project is visible
if params.key?(:view)
case params[:view]
when 'verboseproductlist'
@products = Product.all_products(@project, params[:expand])
render 'source/verboseproductlist', formats: [:xml]
return
when 'productlist'
@products = Product.all_products(@project, params[:expand])
render 'source/productlist', formats: [:xml]
return
when 'issues'
render_project_issues
when 'info'
pass_to_backend
else
raise InvalidParameterError, "'#{params[:view]}' is not a valid 'view' parameter value."
end
case params[:view]
when 'verboseproductlist'
@products = Product.all_products(@project, params[:expand])
render 'source/verboseproductlist', formats: [:xml]
return
when 'productlist'
@products = Product.all_products(@project, params[:expand])
render 'source/productlist', formats: [:xml]
return
when 'issues'
render_project_issues
when 'info'
pass_to_backend
else
raise InvalidParameterError, "'#{params[:view]}' is not a valid 'view' parameter value."
end

render_project_packages
end

def render_project_issues
set_issues_defaults
render partial: 'source/project_issues', formats: [:xml]
end

def render_project_packages
@packages = params.key?(:expand) ? @project.expand_all_packages : @project.packages.pluck(:name)
render locals: { expand: params.key?(:expand) }, formats: [:xml]
end

# DELETE /source/:project
def delete
project = Project.get_by_name(params[:project])
Expand Down

0 comments on commit fdcf3ff

Please sign in to comment.