@@ -90,7 +90,9 class IssuesController < ApplicationController | |||
|
90 | 90 | |
|
91 | 91 | respond_to do |format| |
|
92 | 92 | format.html { render :template => 'issues/index.rhtml', :layout => !request.xhr? } |
|
93 | format.api | |
|
93 | format.api { | |
|
94 | Issue.load_relations(@issues) if include_in_api_response?('relations') | |
|
95 | } | |
|
94 | 96 | format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") } |
|
95 | 97 | format.csv { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') } |
|
96 | 98 | format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') } |
@@ -508,7 +508,17 class Issue < ActiveRecord::Base | |||
|
508 | 508 | end |
|
509 | 509 | |
|
510 | 510 | def relations |
|
511 | (relations_from + relations_to).sort | |
|
511 | @relations ||= (relations_from + relations_to).sort | |
|
512 | end | |
|
513 | ||
|
514 | # Preloads relations for a collection of issues | |
|
515 | def self.load_relations(issues) | |
|
516 | if issues.any? | |
|
517 | relations = IssueRelation.all(:conditions => ["issue_from_id IN (:ids) OR issue_to_id IN (:ids)", {:ids => issues.map(&:id)}]) | |
|
518 | issues.each do |issue| | |
|
519 | issue.instance_variable_set "@relations", relations.select {|r| r.issue_from_id == issue.id || r.issue_to_id == issue.id} | |
|
520 | end | |
|
521 | end | |
|
512 | 522 | end |
|
513 | 523 | |
|
514 | 524 | # Finds an issue relation given its id. |
@@ -23,6 +23,12 api.array :issues, api_meta(:total_count => @issue_count, :offset => @offset, :l | |||
|
23 | 23 | |
|
24 | 24 | api.created_on issue.created_on |
|
25 | 25 | api.updated_on issue.updated_on |
|
26 | ||
|
27 | api.array :relations do | |
|
28 | issue.relations.each do |relation| | |
|
29 | api.relation(:id => relation.id, :issue_id => relation.issue_from_id, :issue_to_id => relation.issue_to_id, :relation_type => relation.relation_type, :delay => relation.delay) | |
|
30 | end | |
|
31 | end if include_in_api_response?('relations') | |
|
26 | 32 | end |
|
27 | 33 | end |
|
28 | 34 | end |
@@ -47,7 +47,7 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||
|
47 | 47 | Setting.rest_api_enabled = '1' |
|
48 | 48 | end |
|
49 | 49 | |
|
50 |
context "/i |
|
|
50 | context "/issues" do | |
|
51 | 51 | # Use a private project to make sure auth is really working and not just |
|
52 | 52 | # only showing public issues. |
|
53 | 53 | should_allow_api_authentication(:get, "/projects/private-child/issues.xml") |
@@ -102,6 +102,25 class ApiTest::IssuesTest < ActionController::IntegrationTest | |||
|
102 | 102 | end |
|
103 | 103 | end |
|
104 | 104 | |
|
105 | context "with relations" do | |
|
106 | should "display relations" do | |
|
107 | get '/issues.xml?include=relations' | |
|
108 | ||
|
109 | assert_response :success | |
|
110 | assert_equal 'application/xml', @response.content_type | |
|
111 | assert_tag 'relations', | |
|
112 | :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '3'}}, | |
|
113 | :children => {:count => 1}, | |
|
114 | :child => { | |
|
115 | :tag => 'relation', | |
|
116 | :attributes => {:id => '2', :issue_id => '2', :issue_to_id => '3', :relation_type => 'relates'} | |
|
117 | } | |
|
118 | assert_tag 'relations', | |
|
119 | :parent => {:tag => 'issue', :child => {:tag => 'id', :content => '1'}}, | |
|
120 | :children => {:count => 0} | |
|
121 | end | |
|
122 | end | |
|
123 | ||
|
105 | 124 | context "with invalid query params" do |
|
106 | 125 | should "return errors" do |
|
107 | 126 | get '/issues.xml', {:f => ['start_date'], :op => {:start_date => '='}} |
General Comments 0
You need to be logged in to leave comments.
Login now