Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Always use backend response for requests to source/:project_name #16955

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions src/api/app/controllers/source_project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ class SourceProjectController < SourceController
# GET /source/:project
def show
project_name = params[:project]
if params.key?(:deleted)
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

if params[:deleted] == '1' && !(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)
# We have to pass it to the backend at this point, because the rest
# of the method expects an existing project
pass_to_backend
return
end
Expand All @@ -19,43 +20,43 @@ def show
return
end

# This implicitly also checks if the user can access the project (for hidden projects).
# We have to make sure to initialize the project already at this
# point, even we dont need the object in most cases because of that fact.
# TODO: Don't implicitly use the finder logic to authorize!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@project = Project.find_by_name(project_name)
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
unless params.key?(:view)
pass_to_backend
return
end

render_project_packages
raise InvalidParameterError, "'#{params[:view]}' is not a valid 'view' parameter value." unless params[:view].in?(%w[verboseproductlist productlist issues info])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we show this message?


# rubocop:disable Style/RedundantReturn
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
end
# rubocop:enable Style/RedundantReturn
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the expand parameter can be handled by the backend as well

render locals: { expand: params.key?(:expand) }, formats: [:xml]
end

# DELETE /source/:project
def delete
project = Project.get_by_name(params[:project])
Expand Down
6 changes: 3 additions & 3 deletions src/api/test/functional/channel_maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def test_large_channel_test
assert_xml_tag tag: 'entry', attributes: { name: 'pack2.BaseDistro2.0_LinkedUpdateProject' }
assert_xml_tag tag: 'entry', attributes: { name: 'pack2.linked.BaseDistro2.0_LinkedUpdateProject' }
assert_xml_tag tag: 'entry', attributes: { name: 'patchinfo' }
assert_xml_tag tag: 'directory', attributes: { count: '4' }
assert_xml_tag tag: 'directory'
# cleanup
delete "/source/#{maintenance_yet_another_project}"
assert_response :success
Expand Down Expand Up @@ -899,7 +899,7 @@ def test_large_channel_test
assert_xml_tag(tag: 'entry', attributes: { name: 'BaseDistro2.Channel' })
assert_xml_tag(tag: 'entry', attributes: { name: 'BaseDistro2SDK.Channel' })
assert_xml_tag(tag: 'entry', attributes: { name: 'patchinfo' })
assert_xml_tag(tag: 'directory', attributes: { count: '5' }) # and nothing else
assert_xml_tag(tag: 'directory') # and nothing else

# validate cleanup
get '/source/home:tom:branches:OBS_Maintained:pack2/pack2.BaseDistro2.0_LinkedUpdateProject'
Expand Down Expand Up @@ -928,7 +928,7 @@ def test_large_channel_test
get '/source/TEST'
assert_response :success
# ensure that we did not got the incident number extension, but the local linked package
assert_xml_tag(tag: 'directory', attributes: { count: '2' })
assert_xml_tag(tag: 'directory')
assert_xml_tag(tag: 'entry', attributes: { name: 'pack2' })
assert_xml_tag(tag: 'entry', attributes: { name: 'pack2.linked' })
delete '/source/TEST'
Expand Down
4 changes: 2 additions & 2 deletions src/api/test/functional/interconnect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ def test_read_and_command_tests
assert_response :success
get "/source/#{project}"
assert_response :success
assert_xml_tag(tag: 'directory', attributes: { count: '0' })
assert_xml_tag(tag: 'directory')
get "/source/#{project}?expand=1"
assert_response :success
next unless @ENABLE_BROKEN_TEST

# FIXME2.4: remote packages get not added yet.
assert_xml_tag(tag: 'directory', attributes: { count: '1' })
assert_xml_tag(tag: 'directory')
assert_xml_tag(tag: 'entry', attributes: { name: 'pack1', originproject: 'BaseDistro2.0' })
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/test/functional/kgraft_maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_kgraft_update_setup
# validate sources
get '/source/' + incident_project
assert_response :success
assert_xml_tag tag: 'directory', attributes: { count: 4 }
assert_xml_tag tag: 'directory'
assert_xml_tag tag: 'entry', attributes: { name: 'BaseDistro2.Channel' }
assert_xml_tag tag: 'entry', attributes: { name: 'kgraft-GA.BaseDistro2.0' }
assert_xml_tag tag: 'entry', attributes: { name: 'kgraft-incident-0.My_Maintenance_0' }
Expand Down
9 changes: 6 additions & 3 deletions src/api/test/functional/maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ def test_mbranch_and_maintenance_entire_project_request

get "/source/#{incident_project}"
assert_response :success
assert_xml_tag(tag: 'directory', attributes: { count: '3' })
assert_xml_tag(tag: 'directory')

get "/source/#{incident_project}/pack2.BaseDistro_Update/_meta"
assert_response :success
Expand Down Expand Up @@ -962,7 +962,7 @@ def test_create_maintenance_project_and_release_packages
assert_xml_tag(tag: 'link', attributes: { project: 'BaseDistro2.0:LinkedUpdateProject', package: 'pack2' })
get "/source/#{incident_project}"
assert_response :success
assert_xml_tag(tag: 'directory', attributes: { count: '3' })
assert_xml_tag(tag: 'directory')
assert_xml_tag(tag: 'entry', attributes: { name: 'pack2.BaseDistro2.0_LinkedUpdateProject' })
assert_xml_tag(tag: 'entry', attributes: { name: 'pack2.linked.BaseDistro2.0_LinkedUpdateProject' })
assert_xml_tag(tag: 'entry', attributes: { name: 'pack2.BaseDistro3' })
Expand Down Expand Up @@ -1743,6 +1743,9 @@ def test_create_maintenance_project_and_release_packages
assert_xml_tag tag: 'directory', attributes: { vrev: '42.1' } # X.Y scheme
delete '/source/BaseDistro2.0:ServicePack1/packNEW'
assert_response :success
# clean up
delete '/source/BaseDistro2.0:LinkedUpdateProject/packNEW'
ncounter marked this conversation as resolved.
Show resolved Hide resolved
assert_response :success

# create a new package instance via submit request the right way
delete '/source/BaseDistro2.0:ServicePack1/pack2.linked'
Expand Down Expand Up @@ -2307,7 +2310,7 @@ def test_copy_project_for_release
assert_response :success
get '/source/CopyOfBaseDistro'
assert_response :success
assert_xml_tag(tag: 'directory', attributes: { count: '6' })
assert_xml_tag(tag: 'directory')
assert_xml_tag(tag: 'entry', attributes: { name: '_product' })
assert_xml_tag(tag: 'entry', attributes: { name: '_product:fixed-release' })
assert_xml_tag(tag: 'entry', attributes: { name: 'patchinfo' })
Expand Down
4 changes: 2 additions & 2 deletions src/api/test/functional/product_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,13 @@ def test_sle11_product_file
login_tom
get '/source/home:tom:temporary:link'
assert_response :success
assert_xml_tag tag: 'directory', attributes: { count: '0' }
assert_xml_tag tag: 'directory'
post '/source/home:tom:temporary/_product:sle-obs-cd-cd-i586_x86_64?cmd=release'
assert_response :success
get '/source/home:tom:temporary:link'
assert_response :success
assert_xml_tag tag: 'entry', attributes: { name: '_product:sle-obs-cd-cd-i586_x86_64' },
parent: { tag: 'directory', attributes: { count: '1' } }
parent: { tag: 'directory' }
# FIXME: add tests for release number handling with various products, requires product binaries and trees

# remove product and check that _product: get removed as well.
Expand Down
4 changes: 2 additions & 2 deletions src/api/test/functional/source_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2330,10 +2330,10 @@ def test_linked_project_operations
# listings
get '/source/BaseDistro2.0:LinkedUpdateProject'
assert_response :success
assert_xml_tag(tag: 'directory', attributes: { count: '1' })
assert_xml_tag(tag: 'directory')
get '/source/BaseDistro2.0:LinkedUpdateProject?expand=1'
assert_response :success
assert_xml_tag(tag: 'directory', attributes: { count: '3' })
assert_xml_tag(tag: 'directory')
assert_xml_tag(tag: 'entry', attributes: { name: 'pack2', originproject: 'BaseDistro2.0' })
assert_xml_tag(tag: 'entry', attributes: { name: 'pack2.linked', originproject: 'BaseDistro2.0' })

Expand Down
3 changes: 3 additions & 0 deletions src/api/test/test_consistency_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def resubmit_all_fixtures
assert_response :success
packages = Xmlhash.parse(@response.body)
packages.elements('entry') do |p|
# skip multibuild flavors
next if p['name'].include?(':')
Comment on lines 37 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to use functional approaches when possible. It moves out the complexity from inside each iteration:

Suggested change
packages.elements('entry') do |p|
# skip multibuild flavors
next if p['name'].include?(':')
packages.elements('entry').reject {|p| p['name'].include?(':') }.each do |p|


get "/source/#{name}/#{p['name']}/_meta"
assert_response :success
r = @response.body
Expand Down