diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/info_request.rb | 30 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 31 |
2 files changed, 40 insertions, 21 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 6b9e7b674..f35ef7f7d 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -958,13 +958,11 @@ public return info_request end - def json_for_api - return { + def json_for_api(deep) + ret = { :id => self.id, :url_title => self.url_title, :title => self.title, - :user => self.user.json_for_api, - :public_body => self.public_body.json_for_api, :created_at => self.created_at, :updated_at => self.updated_at, :described_state => self.described_state, @@ -976,24 +974,14 @@ public # not sure we need to make these, mainly anti-spam, admin params public # allow_new_responses_from # handle_rejected_responses - - :info_request_events => self.info_request_events.map { |e| { - # XXX this code is partly duplicated with the track controller - :id => e.id, - :event_type => e.event_type, - # params_yaml has possibly sensitive data in it, don't include it - :created_at => e.created_at, - :described_state => e.described_state, - :calculated_state => e.calculated_state, - :last_described_at => e.last_described_at, - :incoming_message_id => e.incoming_message_id, - :outgoing_message_id => e.outgoing_message_id, - :comment_id => e.comment_id, - # XXX would be nice to add links here, but alas the - # code to make them is in views only. See views/request/details.rhtml - } } - } + + if deep + ret[:user] = self.user.json_for_api + ret[:public_body] = self.public_body.json_for_api + ret[:info_request_events] = self.info_request_events.map { |e| e.json_for_api(false) } + end + return ret end end diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index ab7844a4d..a6ef2b58c 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -370,6 +370,37 @@ class InfoRequestEvent < ActiveRecord::Base return league_table end + def json_for_api(deep, snippet_highlight_proc = nil) + ret = { + :id => self.id, + :event_type => self.event_type, + # params_yaml has possibly sensitive data in it, don't include it + :created_at => self.created_at, + :described_state => self.described_state, + :calculated_state => self.calculated_state, + :last_described_at => self.last_described_at, + :incoming_message_id => self.incoming_message_id, + :outgoing_message_id => self.outgoing_message_id, + :comment_id => self.comment_id, + + # XXX would be nice to add links here, but alas the + # code to make them is in views only. See views/request/details.rhtml + # perhaps can call with @template somehow + } + + if !snippet_highlight_proc.nil? + ret[:snippet] = snippet_highlight_proc.call(self.search_text_main(true)) + end + + if deep + ret[:info_request] = self.info_request.json_for_api(false) + ret[:public_body] = self.info_request.public_body.json_for_api + ret[:user] = self.info_request.user.json_for_api + end + + return ret + end + end |