aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/api_controller.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 6c0788d49..f54f7dcf8 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -105,6 +105,10 @@ class ApiController < ApplicationController
errors << "You cannot attach files to messages in the 'request' direction"
end
+ if new_state && !InfoRequest.allowed_incoming_states.include?(new_state)
+ errors << "'#{new_state}' is not a valid request state"
+ end
+
if !errors.empty?
render :json => { "errors" => errors }, :status => 500
return
@@ -147,7 +151,14 @@ class ApiController < ApplicationController
@request.receive(mail, mail.encoded, true)
- if new_state && InfoRequest.enumerate_states.include?(new_state)
+ if new_state
+ # we've already checked above that the status is valid
+ # so no need to check a second time
+ event = @request.log_event("status_update",
+ { :script => "#{@public_body.name} via API",
+ :old_described_state => @request.described_state,
+ :described_state => new_state,
+ })
@request.set_described_state(new_state)
end
end
@@ -159,8 +170,6 @@ class ApiController < ApplicationController
def update_state
new_state = params["state"]
- errors = []
-
if InfoRequest.allowed_incoming_states.include?(new_state)
ActiveRecord::Base.transaction do
event = @request.log_event("status_update",