Skip to content

Commit

Permalink
[api] fix and test product listings via project link expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschroeter committed Feb 14, 2014
1 parent fbc0dcc commit 9fca4d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/api/app/models/project.rb
Expand Up @@ -924,8 +924,8 @@ def expand_all_projects

# return array of [:name, :project_id] tuples
def expand_all_packages
packages = self.packages.pluck([:name,:project_id])
p_map = Hash.new
packages = self.packages.pluck([:name,:project_id])
packages.each { |name, prjid| p_map[name] = 1 } # existing packages map
# second path, all packages from indirect linked projects
self.linkedprojects.each do |lp|
Expand All @@ -946,15 +946,16 @@ def expand_all_packages

# return array of [:name, :package_id] tuples for all products
# this function is making the products uniq
def expand_all_products( p_map = Hash.new )
def expand_all_products
p_map = Hash.new
products = Product.joins(:package).where("packages.project_id = ? and packages.name = '_product'", self.id).pluck(:name, :cpe, :package_id)
products.each { |name, cpe, package_id| p_map[cpe] = 1 } # existing packages map
# second path, all packages from indirect linked projects
self.linkedprojects.each do |lp|
if lp.linked_db_project.nil?
# FIXME: this is a remote project
else
lp.linked_db_project.expand_all_products(p_map).each do |name, cpe, package_id|
lp.linked_db_project.expand_all_products.each do |name, cpe, package_id|
unless p_map[cpe]
products << [name, cpe, package_id]
p_map[cpe] = 1
Expand Down
15 changes: 15 additions & 0 deletions src/api/test/functional/product_test.rb
Expand Up @@ -16,6 +16,12 @@ def test_simple_product_file
<person userid="adrian" role="maintainer" />
</package>'
assert_response :success
put "/source/home:tom:temporary:link/_meta",
'<project name="home:tom:temporary:link"> <title/> <description/>
<link project="home:tom:temporary" />
<repository name="me" />
</project>'
assert_response :success

# everything works even when the project is not owner by me?
login_adrian
Expand All @@ -36,6 +42,15 @@ def test_simple_product_file
assert_xml_tag :tag => "product",
:attributes => { :name => "simple", :cpe => "cpe:/a:OBS_Fuzzies:simple:11.2", :originproject => "home:tom:temporary" }

# product views via project links
get "/source/home:tom:temporary:link?view=productlist"
assert_response :success
assert_no_xml_tag :tag => "product"
get "/source/home:tom:temporary:link?view=productlist&expand=1"
assert_response :success
assert_xml_tag :tag => "product",
:attributes => { :name => "simple", :cpe => "cpe:/a:OBS_Fuzzies:simple:11.2", :originproject => "home:tom:temporary" }

# product views in a package
get "/source/home:tom:temporary/_product?view=issues"
assert_response :success
Expand Down

0 comments on commit 9fca4d5

Please sign in to comment.