diff --git a/src/api/lib/xpath_engine.rb b/src/api/lib/xpath_engine.rb index 7916d6a7737..193b3664687 100644 --- a/src/api/lib/xpath_engine.rb +++ b/src/api/lib/xpath_engine.rb @@ -134,6 +134,38 @@ def initialize 'LEFT JOIN attrib_types ON attribs.attrib_type_id = attrib_types.id', 'LEFT JOIN attrib_namespaces ON attrib_types.attrib_namespace_id = attrib_namespaces.id']}, }, + 'repositories' => { + '@project' => {cpart: 'pr.name', + joins: 'LEFT JOIN projects AS pr ON repositories.db_project_id=pr.id' }, + '@name' => {cpart: 'repositories.name'}, + 'path/@project' => {:cpart => 'pathrepoprj.name', :joins => [ + 'LEFT join path_elements pep on pep.parent_id=repositories.id', + 'LEFT join repositories pathrepop on pep.repository_id=pathrepop.id', + 'LEFT join projects pathrepoprj on pathrepop.db_project_id=pathrepoprj.id']}, + 'path/@repository' => {:cpart => 'pathrepo.name', :joins => [ + 'LEFT join path_elements pe on pe.parent_id=repositories.id', + 'LEFT join repositories pathrepo on pe.repository_id=pathrepo.id ']}, + 'targetproduct/@project' => {:cpart => 'tpprj.name', :joins => [ + 'LEFT join product_update_repositories tpr on tpr.repository_id=repositories.id', + 'LEFT join products tpn on tpn.id=tpr.product_id ', + 'LEFT join packages tppkg on tppkg.id=tpn.package_id ', + 'LEFT join projects tpprj on tpprj.id=tppkg.project_id ']}, + 'targetproduct/@arch' => {:cpart => 'tppa.name', :joins => [ + 'LEFT join product_update_repositories pnuar on pnuar.repository_id=repositories.id', + 'LEFT join architectures tppa on tppa.id=pnuar.arch_filter_id ']}, + 'targetproduct/@name' => {:cpart => 'tppn.name', :joins => [ + 'LEFT join product_update_repositories pnur on pnur.repository_id=repositories.id', + 'LEFT join products tppn on tppn.id=pnur.product_id ']}, + 'targetproduct/@baseversion' => {:cpart => 'tppnb.baseversion', :joins => [ + 'LEFT join product_update_repositories pnurb on pnurb.repository_id=repositories.id', + 'LEFT join products tppnb on tppnb.id=pnurb.product_id ']}, + 'targetproduct/@patchlevel' => {:cpart => 'tppnp.patchlevel', :joins => [ + 'LEFT join product_update_repositories pnurp on pnurp.repository_id=repositories.id', + 'LEFT join products tppnp on tppnp.id=pnurp.product_id ']}, + 'targetproduct/@version' => {:cpart => 'tppnv.version', :joins => [ + 'LEFT join product_update_repositories pnurv on pnurv.repository_id=repositories.id', + 'LEFT join products tppnv on tppnv.id=pnurv.product_id ']}, + }, 'binaries' => { '@name' => {:cpart => 'binary_name'}, '@version' => {:cpart => 'binary_version'}, @@ -335,7 +367,7 @@ def find(xpath) when 'projects' relation = Project.all when 'repositories' - relation = Repository.where("db_project_id not in (?)", Relationship.forbidden_project_ids) + relation = Repository.where("repositories.db_project_id not in (?)", Relationship.forbidden_project_ids) when 'requests' relation = BsRequest.all attrib = AttribType.find_by_namespace_and_name('OBS', 'IncidentPriority') diff --git a/src/api/test/functional/channel_maintenance_test.rb b/src/api/test/functional/channel_maintenance_test.rb index 15ecf5d2638..cbc501f29bc 100644 --- a/src/api/test/functional/channel_maintenance_test.rb +++ b/src/api/test/functional/channel_maintenance_test.rb @@ -308,6 +308,7 @@ def test_large_channel_test assert_response :success # added by branching the channel package container assert_xml_tag :tag => "repository", :attributes => {name: "BaseDistro3Channel"} + # cleanup delete "/source/home:maintenance_coord:branches:My:Maintenance:0" assert_response :success @@ -422,6 +423,16 @@ def test_large_channel_test get "/source/#{incidentProject}/BaseDistro2.0.Channel/_meta" assert_response :success assert_xml_tag :tag => 'enable', :attributes => {repository: "BaseDistro2.0_LinkedUpdateProject"} + # check repository search by product + get "/search/repository/id?match=targetproduct/@name='simple'" #+and+target/product/@version='10.2'" + assert_response :success + assert_xml_tag tag: 'collection', :children => {count: 1} + assert_xml_tag tag: 'repository', :attributes => { project: 'BaseDistro2.0:LinkedUpdateProject', name: 'BaseDistro2LinkedUpdateProject_repo' } + get "/search/repository/id?match=targetproduct/[@name='simple'+and+@version='13.1']+and+@project='BaseDistro2.0:LinkedUpdateProject'" + assert_response :success + assert_xml_tag tag: 'collection', :children => {count: 1} + assert_xml_tag tag: 'repository', :attributes => { project: 'BaseDistro2.0:LinkedUpdateProject', name: 'BaseDistro2LinkedUpdateProject_repo' } + login_king delete "/source/BaseDistro2.0/_product" assert_response :success diff --git a/src/api/test/functional/search_controller_test.rb b/src/api/test/functional/search_controller_test.rb index 5aafe87281c..16ac1f6fd06 100644 --- a/src/api/test/functional/search_controller_test.rb +++ b/src/api/test/functional/search_controller_test.rb @@ -293,7 +293,7 @@ def test_search_issues assert_xml_tag :parent => { tag: 'issue'}, tag: 'label', :content => "bnc#123456" end - def test_search_repository_id + def test_search_repository login_Iggy get "/search/repository/id" assert_response :success @@ -309,6 +309,25 @@ def test_search_repository_id repos = get_repos assert repos.include?('home:Iggy/10.2') assert repos.include?('HiddenProject/nada'), "HiddenProject repos public" + + get "/source/home:Iggy/_meta" + get "/search/repository/id?match=@project='home:Iggy'+and+@name='10.2'" + assert_response :success + assert_xml_tag tag: 'collection' + assert_xml_tag tag: 'repository', :attributes => { project: 'home:Iggy', name: '10.2' } + assert repos.count, 1 + + get "/search/repository/id?match=path/@repository='BaseDistro_repo'" + assert_response :success + assert_xml_tag tag: 'collection' + assert_xml_tag tag: 'repository', :attributes => { project: 'home:Iggy', name: '10.2' } + assert repos.count, 1 + + get "/search/repository/id?match=path/[@project='BaseDistro'+and+@repository='BaseDistro_repo']" + assert_response :success + assert_xml_tag tag: 'collection' + assert_xml_tag tag: 'repository', :attributes => { project: 'home:Iggy', name: '10.2' } + assert repos.count, 1 end def test_osc_search_devel_package_after_request_accept