diff options
-rw-r--r-- | app/controllers/admin_general_controller.rb | 62 | ||||
-rw-r--r-- | app/views/admin_general/debug.rhtml | 33 | ||||
-rw-r--r-- | app/views/admin_general/index.rhtml | 77 | ||||
-rw-r--r-- | app/views/admin_general/stats.rhtml | 26 | ||||
-rw-r--r-- | app/views/admin_general/timeline.rhtml | 94 | ||||
-rw-r--r-- | config/routes.rb | 10 |
6 files changed, 297 insertions, 5 deletions
diff --git a/app/controllers/admin_general_controller.rb b/app/controllers/admin_general_controller.rb new file mode 100644 index 000000000..d824f1a6d --- /dev/null +++ b/app/controllers/admin_general_controller.rb @@ -0,0 +1,62 @@ +# app/controllers/admin_controller.rb: +# Controller for main admin pages. +# +# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. +# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: admin_general_controller.rb,v 1.1 2009-01-29 12:28:45 francis Exp $ + +class AdminGeneralController < AdminController + def index + # Overview counts of things + @user_count = User.count + @public_body_count = PublicBody.count + @info_request_count = InfoRequest.count + @track_thing_count = TrackThing.count + @comment_count = Comment.count + + # Tasks to do + @requires_admin_requests = InfoRequest.find(:all, :select => '*, ' + InfoRequest.last_event_time_clause + ' as last_event_time', :conditions => ["described_state = 'requires_admin'"], :order => "last_event_time") + @blank_contacts = PublicBody.find(:all, :conditions => ["request_email = ''"], :order => "updated_at") + @ten_days_old_unclassified = InfoRequest.find(:all, :select => '*, ' + InfoRequest.last_event_time_clause + ' as last_event_time', :conditions => [ "awaiting_description = ? and " + InfoRequest.last_event_time_clause + " < ? and prominence != 'backpage'", true, Time.now() - 10.days ], :order => "last_event_time") + @holding_pen_messages = InfoRequest.holding_pen_request.incoming_messages + end + + def timeline + # Recent events + @events_title = "Events in last two days" + date_back_to = Time.now - 2.days + if params[:week] + @events_title = "Events in last week" + date_back_to = Time.now - 1.week + end + if params[:month] + @events_title = "Events in last month" + date_back_to = Time.now - 1.month + end + if params[:all] + @events_title = "Events, all time" + date_back_to = Time.now - 1000.years + end + @events = InfoRequestEvent.find(:all, :order => "created_at desc, id desc", + :conditions => ["created_at > ? ", date_back_to]) + @public_body_history = PublicBody.versioned_class.find(:all, :order => "updated_at desc, id desc", + :conditions => ["updated_at > ? ", date_back_to]) + for pbh in @public_body_history + pbh.created_at = pbh.updated_at + end + @events += @public_body_history + + @events.sort! { |a,b| b.created_at <=> a.created_at } + end + + def stats + @request_by_state = InfoRequest.count(:group => 'described_state') + @tracks_by_type = TrackThing.count(:group => 'track_type') + end + + def debug + @request_env = request.env + end +end + diff --git a/app/views/admin_general/debug.rhtml b/app/views/admin_general/debug.rhtml new file mode 100644 index 000000000..3229c0bd4 --- /dev/null +++ b/app/views/admin_general/debug.rhtml @@ -0,0 +1,33 @@ +<% @title = "Debug" %> + +<h1><%=@title%></h1> + +<p>You are <%= h @http_auth_user %></p> + +<p><a href="balancer-manager">Apache load balancing configuration</a></p> + +<h2>Version numbers</h2> + +<p>Rails::VERSION::STRING <%=Rails::VERSION::STRING%> +<br> +TMail::VERSION::STRING <%=TMail::VERSION::STRING%> +<br> +Xapian::version_string <%=Xapian::version_string%> +<br> +Spec::VERSION::NAME/STRING <%=Spec::VERSION::NAME%> <%=Spec::VERSION::STRING%> +</p> + +<h2>Environment variables</h2> +<pre> +<%= @request_env.to_yaml %> +</pre> + +<h2>Parameters</h2> +<pre> +<%= params.to_yaml %> +</pre> + +<h2>Session</h2> +<pre> +<%= session.to_yaml %> +</pre> diff --git a/app/views/admin_general/index.rhtml b/app/views/admin_general/index.rhtml new file mode 100644 index 000000000..7dce7373c --- /dev/null +++ b/app/views/admin_general/index.rhtml @@ -0,0 +1,77 @@ +<% @title = "Summary" %> + +<h1><%=@title%></h1> + +<ul> +<li><%=@public_body_count%> public authorities</li> +<li><%=@info_request_count%> requests</li> +<li><%=@user_count%> users</li> +<li><%=@track_thing_count%> tracked things</li> +<li><%=@comment_count%> annotations</li> +</ul> + +<hr> + +<h1>Things to do</h1> + +<% if @holding_pen_messages.size > 0 %> + <h3>Put misdelivered responses with the right request (<%=@holding_pen_messages.size%> total)</h3> + + <ul> + <% for message in @holding_pen_messages %> + <li> + <% if message.get_body_for_quoting.strip.size == 0 %> + <%= link_to "(no body)", "request/show_raw_email/" + message.raw_email_id.to_s %> + <% else %> + <%= link_to excerpt(message.get_body_for_quoting, "", 60), "request/show_raw_email/" + message.raw_email_id.to_s %> + <% end %> + (<%=simple_date(message.sent_at)%>) + </li> + <% end %> + </ul> + +<% end %> + +<% if @ten_days_old_unclassified.size > 0 %> + <h3>Classify responses that are still unclassified ten days after response (<%=@ten_days_old_unclassified.size%> total)</h3> + + <ul> + <% for @request in @ten_days_old_unclassified %> + <li> + <%= request_both_links(@request) %> + – <%=simple_date(@request.get_last_event.created_at)%> + </li> + <% end %> + </ul> +<% end %> + +<% if @requires_admin_requests.size > 0 %> + <h3>Work out what to do with these unusual responses (a new category?) (<%=@requires_admin_requests.size%> total)</h3> + + <ul> + <% for @request in @requires_admin_requests %> + <li> + <%= request_both_links(@request)%> + – <%=simple_date(@request.get_last_event.created_at)%> + </li> + <% end %> + </ul> +<% end %> + +<% if @blank_contacts.size > 0 %> + <h3>Find missing FOI email for these public authorities (try phoning!) (<%=@blank_contacts.size%> total)</h3> + <ul> + <% for @blank_contact in @blank_contacts %> + <li> + <%= public_body_both_links(@blank_contact)%> + – <%=simple_date(@blank_contact.updated_at)%> + </li> + <% end %> + </ul> +<% end %> + +<% if @holding_pen_messages.size == 0 && @ten_days_old_unclassified.size == 0 && @requires_admin_requests.size == 0 && @blank_contacts.size == 0 %> + <p>No pending administration required.</p> +<% end %> + + diff --git a/app/views/admin_general/stats.rhtml b/app/views/admin_general/stats.rhtml new file mode 100644 index 000000000..9aca960d1 --- /dev/null +++ b/app/views/admin_general/stats.rhtml @@ -0,0 +1,26 @@ +<% @title = "Statistics" %> + +<h1>Statistics</h1> + +<h2>Chart of requests (excluding backpaged)</h2> + +<p> + <img src="<%= main_url("/foi-live-creation.png")%>"> +</p> + +<h2>State of requests (includes backpaged)</h2> + +<table> +<% for state, count in @request_by_state %> +<tr> <td><%=state %></td><td><%= count %></td> </tr> +<% end %> +</table> + +<h2>Tracks by type</h2> + +<table> +<% for state, count in @tracks_by_type %> +<tr> <td><%=state %></td><td><%= count %></td> </tr> +<% end %> +</table> + diff --git a/app/views/admin_general/timeline.rhtml b/app/views/admin_general/timeline.rhtml new file mode 100644 index 000000000..25e871232 --- /dev/null +++ b/app/views/admin_general/timeline.rhtml @@ -0,0 +1,94 @@ +<% @title = "Timeline" %> + +<h1><%=h @events_title%></h1> + +<p> +<a href="?">Two days</a> +| <a href="?week=1">Week</a> +| <a href="?month=1">Month</a> +| <a href="?all=1">All time</a></p> + +<% last_date = nil %> +<% for event in @events %> + <% if last_date != event.created_at.to_date %> + <% if last_date.nil? %> + <p> + <% end %> + <h3><%= simple_date(event.created_at) %></h3> + <p> + <% else %> + <br> + <% end %> + <% last_date = event.created_at.to_date %> + + + <% if event.class.to_s == 'InfoRequestEvent' %> + <%= request_both_links(event.info_request) %> + <% if event.event_type == 'edit' %> + was edited by administrator <strong><%=h event.params[:editor] %></strong>. + <% for p in ['title', 'prominence', 'described_state', 'awaiting_description'] + if event.params[p.to_sym] != event.params[('old_'+p).to_sym] + %> Changed <%=p%> from '<%=h event.params[('old_'+p).to_sym]%>' to '<%=h event.params[p.to_sym] %>'. <% + end + end + %> + <% elsif event.event_type == 'edit_outgoing' %> + <% outgoing_messages = OutgoingMessage.find(:all, event.params[:outgoing_message_id].to_i) %> + had outgoing message edited by administrator <strong><%=h event.params[:editor] %></strong>. + <% if outgoing_messages.size > 0 %> + <% outgoing_message = outgoing_messages[0] %> + <% for p in ['body'] + if event.params[p.to_sym] != event.params[('old_'+p).to_sym] + %> Changed <%=p%> from '<%=h event.params[('old_'+p).to_sym]%>' to '<%=h event.params[p.to_sym] %>'. <% + end + end + %> + <% else %> + Missing outgoing message, internal error. + <% end %> + <% elsif event.event_type == 'edit_comment' %> + <% comments = Comment.find(:all, event.params[:comment_id].to_i) %> + had annotation edited by administrator <strong><%=h event.params[:editor] %></strong>. + <% if comments.size > 0 %> + <% comment = comments[0] %> + <% for p in ['body'] + if event.params[p.to_sym] != event.params[('old_'+p).to_sym] + %> Changed <%=p%> from '<%=h event.params[('old_'+p).to_sym]%>' to '<%=h event.params[p.to_sym] %>'. <% + end + end + %> + <% else %> + Missing annotation, internal error. + <% end %> + <% elsif event.event_type == 'destroy_incoming' %> + had incoming message deleted by administrator <strong><%=h event.params[:editor] %></strong>. + <% elsif event.event_type == 'redeliver_incoming' %> + had incoming message redelivered to another request by administrator <strong><%=h event.params[:editor] %></strong>. + <% elsif event.event_type == 'response' %> + <% incoming_message = event.incoming_message %> + received + <%= link_to 'a response', + main_url(show_response_url(:id => incoming_message.info_request.id, :incoming_message_id => incoming_message.id, :only_path => true)) %> + + from <%=h event.info_request.public_body.name %>. + <% elsif event.event_type == 'sent' %> + was initially sent to <%=h event.params[:email]%> at <%=h event.info_request.public_body.name %>. + <% elsif event.event_type == 'resent' %> + had the request resent to <%=h event.params[:email]%> at <%=h event.info_request.public_body.name %>. + <% elsif event.event_type == 'followup_sent' %> + had a follow up message sent to <%=h event.info_request.public_body.name %>. + <% elsif event.event_type == 'comment' %> + had an annotation posted by <%=h event.comment.user.name %>. + <% else %> + had '<%=event.event_type%>' done to it, parameters <%=h event.params_yaml%>. + <% end %> + <% else %> + <%= public_body_both_links(event.public_body) %> + was created/updated by administrator <strong><%=h event.last_edit_editor %></strong> + <% end %> +<% end %> +<% if not @events.empty? %> +</p> +<% end %> + + diff --git a/config/routes.rb b/config/routes.rb index 309b7c72f..5dec2afc4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: routes.rb,v 1.80 2008-11-07 00:47:23 francis Exp $ +# $Id: routes.rb,v 1.81 2009-01-29 12:28:45 francis Exp $ ActionController::Routing::Routes.draw do |map| @@ -89,10 +89,10 @@ ActionController::Routing::Routes.draw do |map| # NB: We don't use routes to *construct* admin URLs, as they need to be relative # paths to work on the live site proxied over HTTPS to secure.mysociety.org - map.connect '/admin/', :controller => 'admin', :action => 'index' - map.connect '/admin/timeline', :controller => 'admin', :action => 'timeline' - map.connect '/admin/debug', :controller => 'admin', :action => 'debug' - map.connect '/admin/stats', :controller => 'admin', :action => 'stats' + map.connect '/admin/', :controller => 'admin_general', :action => 'index' + map.connect '/admin/timeline', :controller => 'admin_general', :action => 'timeline' + map.connect '/admin/debug', :controller => 'admin_general', :action => 'debug' + map.connect '/admin/stats', :controller => 'admin_general', :action => 'stats' map.connect '/admin/body/:action/:id', :controller => 'admin_public_body' map.connect '/admin/request/:action/:id', :controller => 'admin_request' map.connect '/admin/user/:action/:id', :controller => 'admin_user' |