Skip to content

Commit

Permalink
[api] fix request schema
Browse files Browse the repository at this point in the history
grouped can appear more than once, but it always has one id

This left unnoticed, as request/show did not validate due to the usage of
send_data, which is now fixed. Also avoiding double render errors if an
exception happens
  • Loading branch information
coolo committed Nov 18, 2013
1 parent badeb7e commit 3e5d3b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
10 changes: 5 additions & 5 deletions docs/api/api/request.rng
Expand Up @@ -125,14 +125,14 @@
</element>
</optional>
<optional>
<element name="grouped"> <!-- and this refers to the infame request groups -->
<oneOrMore>
<oneOrMore>
<element name="grouped"> <!-- and this refers to the famous request groups -->
<attribute name="id">
<data type="string" />
</attribute>
</oneOrMore>
<empty/>
</element>
<empty/>
</element>
</oneOrMore>
</optional>
<optional>
<element name="options">
Expand Down
2 changes: 2 additions & 0 deletions src/api/app/controllers/application_controller.rb
Expand Up @@ -543,6 +543,8 @@ def render_error( opt = {} )
request.body.size if request.body.respond_to? 'size'
end

# avoid double render error
self.response_body = nil
gather_exception_defaults(opt)

response.headers['X-Opensuse-Errorcode'] = @errorcode
Expand Down
18 changes: 9 additions & 9 deletions src/api/app/controllers/request_controller.rb
Expand Up @@ -52,15 +52,15 @@ def render_request_collection
xml.add_node(r.render_xml)
end
xml.set_attribute('matches', matches.to_s)
render :text => xml.dump_xml, :content_type => 'text/xml'
render xml: xml.dump_xml
end

# GET /request/:id
def show
required_parameters :id

req = BsRequest.find(params[:id])
send_data(req.render_xml, :type => 'text/xml')
render xml: req.render_xml
end

# POST /request?cmd=create
Expand Down Expand Up @@ -124,7 +124,7 @@ def update
notify = oldrequest.notify_parameters
Event::RequestChange.create notify

send_data(req.render_xml, :type => 'text/xml')
render xml: req.render_xml
end
end

Expand Down Expand Up @@ -165,7 +165,7 @@ def request_create

body = request.raw_post.to_s

BsRequest.transaction do
xml = BsRequest.transaction do
@req = BsRequest.new_from_xml(body)

# overwrite stuff
Expand Down Expand Up @@ -228,16 +228,16 @@ def request_create
review.create_notification_event(notify.dup)
end

xml = @req.render_xml
Suse::Validator.validate(:request, xml)
xml
end

# cache the diff (in the backend)
@req.bs_request_actions.each do |a|
a.delay.webui_infos
end

xml = @req.render_xml
Suse::Validator.validate(:request, xml)

render xml: xml
end

Expand Down Expand Up @@ -271,9 +271,9 @@ def request_command_diff

if xml_request
xml_request.set_attribute('actions', action_counter.to_s)
send_data(xml_request.dump_xml, :type => 'text/xml')
render xml: xml_request.dump_xml
else
send_data(diff_text, :type => 'text/plain')
render text: diff_text
end
end

Expand Down

0 comments on commit 3e5d3b1

Please sign in to comment.