Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[api] support request collection views for groups as well

Conflicts:
	src/api/app/models/group.rb
  • Loading branch information...
commit 98b25c11ec1334abb9b7b4150cb1370cc776abe4 1 parent 0936b28
@adrianschroeter adrianschroeter authored
View
39 src/api/app/controllers/request_controller.rb
@@ -155,6 +155,45 @@ def index
end
end
+ if params[:group]
+ inner_or = []
+ group = Group.get_by_title(params[:group])
+
+ # find requests where group is maintainer in target project
+ if roles.count == 0 or roles.include? "maintainer"
+ names = group.involved_projects.map { |p| p.name }
+ inner_or << "bs_request_actions.target_project in ('" + names.join("','") + "')"
+
+ ## find request where group is maintainer in target package, except we have to project already
+ group.involved_packages.each do |ip|
+ inner_or << "(bs_request_actions.target_project='#{ip.db_project.name}' and bs_request_actions.target_package='#{ip.name}')"
+ end
+ end
+
+ if roles.count == 0 or roles.include? "reviewer"
+ review_states.each do |r|
+
+ # requests where the user is reviewer or own requests that are in review by someone else
+ or_in_and = [ "reviews.by_group='#{group.title}'" ]
+
+ # find requests where group is maintainer in target project
+ groupprojects = group.involved_projects.select("db_projects.name").map { |p| "'#{p.name}'" }
+ or_in_and << "reviews.by_project in (#{groupprojects.join(',')})" unless groupprojects.blank?
+
+ ## find request where user is maintainer in target package, except we have to project already
+ group.involved_packages.select("name,db_project_id").includes(:db_project).each do |ip|
+ or_in_and << "(reviews.by_project='#{ip.db_project.name}' and reviews.by_package='#{ip.name}')"
+ end
+
+ inner_or << "(reviews.state='#{r}' and (#{or_in_and.join(" or ")}))"
+ end
+ end
+
+ unless inner_or.empty?
+ rel = rel.where(inner_or.join(" or "))
+ end
+ end
+
# Pagination: Discard 'offset' most recent requests (useful with 'count')
if params[:offset]
# TODO: Backend XPath engine needs better range support
View
29 src/api/app/models/group.rb
@@ -69,4 +69,33 @@ def render_axml
xml
end
+ def involved_projects_ids
+ # just for maintainer for now.
+ role = Role.rolecache["maintainer"]
+
+ ### all projects where user is maintainer
+ projects = ProjectGroupRoleRelationship.where(bs_group_id: id, role_id: role.id).select(:db_project_id).all.map {|ur| ur.db_project_id }
+
+ projects.uniq
+ end
+ protected :involved_projects_ids
+
+ def involved_projects
+ # now filter the projects that are not visible
+ return DbProject.where(id: involved_projects_ids)
+ end
+
+ # lists packages maintained by this user and are not in maintained projects
+ def involved_packages
+ # just for maintainer for now.
+ role = Role.rolecache["maintainer"]
+
+ projects = involved_projects_ids
+ projects << -1 if projects.empty?
+
+ # all packages where group is maintainer
+ packages = PackageGroupRoleRelationship.where(bs_group_id: id, role_id: role.id).joins(:db_package).where("db_packages.db_project_id not in (?)", projects).select(:db_package_id).all.map {|ur| ur.db_package_id}
+
+ return DbPackage.where(id: packages).where("db_project_id not in (?)", projects)
+ end
end
View
3  src/api/test/functional/request_controller_test.rb
@@ -513,6 +513,9 @@ def test_search_and_involved_requests
assert_xml_tag( :tag => 'collection', :child => {:tag => 'request' } )
assert_xml_tag( :tag => "source", :attributes => { :project => "HiddenProject", :package => "pack"} )
end
+ get "/request?view=collection&group=test_group&states=new,review"
+ assert_response :success
+ assert_xml_tag( :tag => 'collection', :child => {:tag => 'request' } )
# collection for given package
get "/request?view=collection&project=kde4&package=wpa_supplicant&states=new,review"
Please sign in to comment.
Something went wrong with that request. Please try again.