These attributes are not required for common uses case (eg. updating an object). They can be requested in the reponse using the 'include' parameter. Example GET /issues/1.xml?include=journals. The list of attributes that can be included in responses will be documented in the wiki.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4486
e93f8b46-1217-0410-a6f0-
8f06a7374b81
def favicon
"<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />"
end
+
+ # Returns true if arg is expected in the API response
+ def include_in_api_response?(arg)
+ unless @included_in_api_response
+ param = params[:include]
+ @included_in_api_response = param.is_a?(Array) ? param.collect(&:to_s) : param.to_s.split(',')
+ @included_in_api_response.collect!(&:strip)
+ end
+ @included_in_api_response.include?(arg.to_s)
+ end
private
api.created_on @issue.created_on
api.updated_on @issue.updated_on
- render_api_issue_children(@issue, api)
+ render_api_issue_children(@issue, api) if include_in_api_response?('children')
api.array :relations do
@issue.relations.select {|r| r.other_issue(@issue).visible? }.each do |relation|
api.relation(:id => relation.id, :issue_id => relation.other_issue(@issue).id, :relation_type => relation.relation_type_for(@issue), :delay => relation.delay)
end
- end
+ end if include_in_api_response?('relations')
api.array :changesets do
@issue.changesets.each do |changeset|
api.committed_on changeset.committed_on
end
end
- end if User.current.allowed_to?(:view_changesets, @project) && @issue.changesets.any?
+ end if include_in_api_response?('changesets') && User.current.allowed_to?(:view_changesets, @project)
api.array :journals do
@issue.journals.each do |journal|
end
end
end
- end unless @issue.journals.empty?
+ end if include_in_api_response?('journals')
end
@project.trackers.each do |tracker|
api.tracker(:id => tracker.id, :name => tracker.name)
end
- end
+ end if include_in_api_response?('trackers')
end
end
end if membership.project
end
- end if @memberships.present?
+ end if include_in_api_response?('memberships') && @memberships
end
context "with journals" do
context ".xml" do
should "display journals" do
- get '/issues/1.xml'
+ get '/issues/1.xml?include=journals'
assert_tag :tag => 'issue',
:child => {
context ".xml" do
should "display children" do
- get '/issues/1.xml'
+ get '/issues/1.xml?include=children'
assert_tag :tag => 'issue',
:child => {
context ".json" do
should "display children" do
- get '/issues/1.json'
+ get '/issues/1.json?include=children'
json = ActiveSupport::JSON.decode(response.body)
assert_equal([