diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/api_controller.rb | 42 | ||||
-rw-r--r-- | app/views/admin_general/index.html.erb | 2 | ||||
-rw-r--r-- | app/views/request/_sidebar_request_listing.html.erb | 2 |
3 files changed, 28 insertions, 18 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 4473139d1..6f83d89d6 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -191,10 +191,17 @@ class ApiController < ApplicationController raise PermissionDenied.new("#{@public_body.id} != #{params[:id]}") if @public_body.id != params[:id].to_i since_date_str = params[:since_date] + since_event_id = params[:since_event_id] + event_type_clause = "event_type in ('sent', 'followup_sent', 'resent', 'followup_resent')" - if since_date_str.nil? - where_params = event_type_clause - else + + @events = InfoRequestEvent.where(event_type_clause) \ + .joins(:info_request) \ + .where("public_body_id = ?", @public_body.id) \ + .includes([{:info_request => :user}, :outgoing_message]) \ + .order('info_request_events.created_at DESC') + + if since_date_str begin since_date = Date.strptime(since_date_str, "%Y-%m-%d") rescue ArgumentError @@ -203,26 +210,29 @@ class ApiController < ApplicationController :status => 500 return end - event_type_clause << " AND info_request_events.created_at >= ?" - where_params = [event_type_clause, since_date] + @events = @events.where("info_request_events.created_at >= ?", since_date) + end + + # We take a "since" parameter that allows the client + # to restrict to events more recent than a certain other event + if since_event_id + begin + event = InfoRequestEvent.find(since_event_id) + rescue ActiveRecord::RecordNotFound + render :json => {"errors" => [ + "Event ID #{since_event_id} not found" ] }, + :status => 500 + return + end + @events = @events.where("info_request_events.created_at > ?", event.created_at) end - @events = InfoRequestEvent.where(where_params) \ - .joins(:info_request) \ - .where("public_body_id = ?", @public_body.id) \ - .includes([{:info_request => :user}, :outgoing_message]) \ - .order('info_request_events.created_at DESC') + if feed_type == "atom" render :template => "api/request_events", :formats => ['atom'], :layout => false elsif feed_type == "json" - # For the JSON feed, we take a "since" parameter that allows the client - # to restrict to events more recent than a certain other event - if params[:since_event_id] - @since_event_id = params[:since_event_id].to_i - end @event_data = [] @events.each do |event| - break if event.id == @since_event_id request = event.info_request this_event = { diff --git a/app/views/admin_general/index.html.erb b/app/views/admin_general/index.html.erb index 2202663be..f29258162 100644 --- a/app/views/admin_general/index.html.erb +++ b/app/views/admin_general/index.html.erb @@ -39,7 +39,7 @@ <% if message.get_body_for_quoting.strip.size == 0 %> <%= link_to "(no body)", admin_request_show_raw_email_path(message.raw_email_id) %> <% else %> - <%= link_to excerpt(message.get_body_for_quoting, "", 60), admin_request_show_raw_email_path(message.raw_email_id) %> + <%= link_to excerpt(message.get_body_for_quoting, "", :radius => 60), admin_request_show_raw_email_path(message.raw_email_id) %> <% end %> </td> <td class="span2"> diff --git a/app/views/request/_sidebar_request_listing.html.erb b/app/views/request/_sidebar_request_listing.html.erb index ec5a5813d..64fe39341 100644 --- a/app/views/request/_sidebar_request_listing.html.erb +++ b/app/views/request/_sidebar_request_listing.html.erb @@ -4,7 +4,7 @@ <%= request_link(info_request) %> </span> <span class="desc"> - <%=h excerpt(info_request.initial_request_text, "", 100) %> + <%=h excerpt(info_request.initial_request_text, "", :radius => 100) %> </span> <span class="bottomline"> <strong> |