diff options
author | francis <francis> | 2008-05-05 22:38:04 +0000 |
---|---|---|
committer | francis <francis> | 2008-05-05 22:38:04 +0000 |
commit | d93aadb057c1a281cfde996d70009ee7e26660ae (patch) | |
tree | a0ad063ba1f547845569e6dafac187169f0be551 | |
parent | 31e4f03d798d51d28519b9123b34def0ba1843d3 (diff) |
Button to destroy incoming messages.
-rw-r--r-- | app/controllers/admin_request_controller.rb | 24 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 6 | ||||
-rw-r--r-- | app/views/admin/timeline.rhtml | 4 | ||||
-rw-r--r-- | app/views/admin_request/show.rhtml | 10 |
4 files changed, 41 insertions, 3 deletions
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb index 3620b019c..be40e17f4 100644 --- a/app/controllers/admin_request_controller.rb +++ b/app/controllers/admin_request_controller.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: admin_request_controller.rb,v 1.10 2008-04-14 10:02:55 francis Exp $ +# $Id: admin_request_controller.rb,v 1.11 2008-05-05 22:38:04 francis Exp $ class AdminRequestController < ApplicationController layout "admin" @@ -99,6 +99,28 @@ class AdminRequestController < ApplicationController end end + def destroy_incoming + @incoming_message = IncomingMessage.find(params[:incoming_message_id]) + @info_request_event = InfoRequestEvent.find_by_incoming_message_id(@incoming_message.id) + @info_request = @incoming_message.info_request + + raw_data = @incoming_message + incoming_message_id = @incoming_message.id + + ActiveRecord::Base.transaction do + @info_request_event.track_things_sent_emails.each { |a| a.destroy } + @info_request_event.user_info_request_sent_alerts.each { |a| a.destroy } + @info_request_event.destroy + @incoming_message.destroy + end + + @incoming_message.info_request.log_event("destroy_incoming", + { :editor => admin_http_auth_user(), :raw_data => raw_data }) + + flash[:notice] = 'Incoming message successfully destroyed.' + redirect_to request_admin_url(@info_request) + end + private end diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 6b4de75ab..ce94f4f1b 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -20,7 +20,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request_event.rb,v 1.41 2008-04-29 16:23:31 francis Exp $ +# $Id: info_request_event.rb,v 1.42 2008-05-05 22:38:04 francis Exp $ class InfoRequestEvent < ActiveRecord::Base belongs_to :info_request @@ -29,6 +29,9 @@ class InfoRequestEvent < ActiveRecord::Base belongs_to :outgoing_message belongs_to :incoming_message + has_many :user_info_request_sent_alerts + has_many :track_things_sent_emails + validates_presence_of :event_type validates_inclusion_of :event_type, :in => [ 'sent', @@ -36,6 +39,7 @@ class InfoRequestEvent < ActiveRecord::Base 'followup_sent', 'edit', # title etc. edited in admin interface 'edit_outgoing', # outgoing message edited in admin interface + 'destroy_incoming', # deleted an incoming message 'manual', # you did something in the db by hand 'response' ] diff --git a/app/views/admin/timeline.rhtml b/app/views/admin/timeline.rhtml index cf5b3762e..d7680b994 100644 --- a/app/views/admin/timeline.rhtml +++ b/app/views/admin/timeline.rhtml @@ -47,7 +47,9 @@ <% else %> Missing outgoing message, internal error. <% end %> - <% elsif event.event_type == 'response' %> + <% elsif event.event_type == 'destroy_incoming' %> + had incoming message deleted by administrator <strong><%=h event.params[:editor] %></strong>. + <% elsif event.event_type == 'response' %> <% incoming_message = event.incoming_message %> received <%= link_to 'a response', diff --git a/app/views/admin_request/show.rhtml b/app/views/admin_request/show.rhtml index 423e6d19a..0c9ed1fe9 100644 --- a/app/views/admin_request/show.rhtml +++ b/app/views/admin_request/show.rhtml @@ -75,6 +75,7 @@ <% for column in IncomingMessage.content_columns %> <th><%= column.human_name %></th> <% end %> + <th>Actions</th> </tr> <% for incoming_message in @info_request.incoming_messages.find(:all, :order => 'created_at') %> @@ -83,6 +84,15 @@ <% for column in IncomingMessage.content_columns.map { |c| c.name } %> <td><%=h incoming_message.send(column) %></td> <% end %> + <td> + <% form_tag '../destroy_incoming' do %> + <div> + <%= hidden_field_tag 'incoming_message_id', incoming_message.id %> + <%= submit_tag "Destroy" %> + </div> + <% end %> + + </td> </tr> <% end %> </table> |