diff options
author | lizconlan <liz@mysociety.org> | 2014-06-23 13:18:00 +0100 |
---|---|---|
committer | lizconlan <liz@mysociety.org> | 2014-07-28 11:47:32 +0100 |
commit | f3abf87add310d8b446472da2a31eeb05feb31b8 (patch) | |
tree | d6053c45356b467bae7230df9f675b311fab9a11 /app/controllers/api_controller.rb | |
parent | 213b029c3ae93b02b72263b3bb6c908355111237 (diff) |
Extend add_correspondence API method to optionally accept a state param
Diffstat (limited to 'app/controllers/api_controller.rb')
-rw-r--r-- | app/controllers/api_controller.rb | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index f826f65d1..355584288 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -89,6 +89,7 @@ class ApiController < ApplicationController direction = json["direction"] body = json["body"] sent_at = json["sent_at"] + new_state = params["state"] errors = [] @@ -157,6 +158,10 @@ class ApiController < ApplicationController mail = RequestMailer.external_response(request, body, sent_at, attachment_hashes) request.receive(mail, mail.encoded, true) + + if new_state && InfoRequest.enumerate_states.include?(new_state) + request.set_described_state(new_state) + end end render :json => { 'url' => make_url("request", request.url_title), @@ -166,7 +171,10 @@ class ApiController < ApplicationController def update_state request = InfoRequest.find_by_id(params[:id]) if request.nil? - render :json => { "errors" => ["Could not find request #{params[:id]}"] }, :status => 404 + render :json => { + "errors" => ["Could not find request #{params[:id]}"] + }, + :status => 404 return end new_state = params["state"] @@ -174,22 +182,29 @@ class ApiController < ApplicationController errors = [] if !request.is_external? - render :json => { "errors" => ["Request #{params[:id]} cannot be updated using the API"] }, :status => 500 + render :json => { + "errors" => ["Request #{params[:id]} cannot be updated using the API"] + }, + :status => 500 return end if request.public_body_id != @public_body.id - render :json => { "errors" => ["You do not own request #{params[:id]}"] }, :status => 500 + render :json => { + "errors" => ["You do not own request #{params[:id]}"] + }, + :status => 500 return end if InfoRequest.enumerate_states.include?(new_state) request.set_described_state(new_state) else - render :json => {"errors" => [ - "'#{new_state}' is not a valid request state" ] }, - :status => 500 - return + render :json => { + "errors" => ["'#{new_state}' is not a valid request state" ] + }, + :status => 500 + return end render :json => { |