aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2008-09-13 18:01:27 +0000
committerfrancis <francis>2008-09-13 18:01:27 +0000
commit32df5644d574e92fd9c056cbc2b73c38c0920e1f (patch)
treeeb70740e616413fcc81d85d6c179c6eb56e6bb34
parent904e3bbed9ad8e28de46ac298ec39f65ecf4c893 (diff)
Edit annotations.
-rw-r--r--app/controllers/admin_request_controller.rb23
-rw-r--r--app/models/info_request_event.rb3
-rw-r--r--app/views/admin/timeline.rhtml14
-rw-r--r--app/views/admin_request/edit_comment.rhtml17
-rw-r--r--app/views/admin_request/show.rhtml5
-rw-r--r--spec/fixtures/public_bodies.yml2
6 files changed, 61 insertions, 3 deletions
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index 99da8eb53..dae07aa8a 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.17 2008-09-02 17:44:14 francis Exp $
+# $Id: admin_request_controller.rb,v 1.18 2008-09-13 18:01:27 francis Exp $
class AdminRequestController < ApplicationController
layout "admin"
@@ -102,6 +102,27 @@ class AdminRequestController < ApplicationController
end
end
+ def edit_comment
+ @comment = Comment.find(params[:id])
+ end
+
+ def update_comment
+ @comment = Comment.find(params[:id])
+
+ old_body = @comment.body
+
+ if @comment.update_attributes(params[:comment])
+ @comment.info_request.log_event("edit_comment",
+ { :comment_if => @comment.id, :editor => admin_http_auth_user(),
+ :old_body => old_body, :body => @comment.body })
+ flash[:notice] = 'Comment successfully updated.'
+ redirect_to request_admin_url(@comment.info_request)
+ else
+ render :action => 'edit_comment'
+ end
+ end
+
+
def destroy_incoming
@incoming_message = IncomingMessage.find(params[:incoming_message_id])
@info_request = @incoming_message.info_request
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 4faeb0bdd..109a71b84 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -21,7 +21,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.56 2008-09-08 11:33:11 francis Exp $
+# $Id: info_request_event.rb,v 1.57 2008-09-13 18:01:27 francis Exp $
class InfoRequestEvent < ActiveRecord::Base
belongs_to :info_request
@@ -42,6 +42,7 @@ class InfoRequestEvent < ActiveRecord::Base
'followup_resent',
'edit', # title etc. edited in admin interface
'edit_outgoing', # outgoing message edited in admin interface
+ 'edit_comment', # comment 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 3b77b5821..4c4aa4f36 100644
--- a/app/views/admin/timeline.rhtml
+++ b/app/views/admin/timeline.rhtml
@@ -46,6 +46,20 @@
<% 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 == 'response' %>
diff --git a/app/views/admin_request/edit_comment.rhtml b/app/views/admin_request/edit_comment.rhtml
new file mode 100644
index 000000000..d8d7de276
--- /dev/null
+++ b/app/views/admin_request/edit_comment.rhtml
@@ -0,0 +1,17 @@
+<h1>Edit annotation</h1>
+
+<%= error_messages_for 'comment' %>
+
+<% form_tag '../update_comment/' + @comment.id.to_s do %>
+
+ <p><label for="comment_body">Body of annotation</label><br/>
+ <%= text_area 'comment', 'body', :rows => 10, :cols => 60 %></p>
+
+ <p><%= submit_tag 'Save', :accesskey => 's' %></p>
+<% end %>
+
+<p>
+<%= link_to 'Show', '../show/' + @comment.info_request.id.to_s %> |
+<%= link_to 'List all', '../list' %>
+</p>
+
diff --git a/app/views/admin_request/show.rhtml b/app/views/admin_request/show.rhtml
index 29989933b..fb8eb2f79 100644
--- a/app/views/admin_request/show.rhtml
+++ b/app/views/admin_request/show.rhtml
@@ -122,7 +122,7 @@
<% for column in Comment.content_columns %>
<th><%= column.human_name %></th>
<% end %>
- <!--<th>Actions</th>-->
+ <th>Actions</th>
</tr>
<% for comment in @info_request.comments.find(:all, :order => 'created_at') %>
@@ -132,6 +132,9 @@
<% for column in Comment.content_columns.map { |c| c.name } %>
<td><%=h comment.send(column) %></td>
<% end %>
+ <td>
+ <%= link_to "Edit", '../edit_comment/' + comment.id.to_s %>
+ </td>
</tr>
<% end %>
</table>
diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml
index 88c19484b..3d6a4ccc6 100644
--- a/spec/fixtures/public_bodies.yml
+++ b/spec/fixtures/public_bodies.yml
@@ -1,5 +1,6 @@
geraldine_public_body:
name: The Geraldine Quango
+ first_letter: T
updated_at: 2007-10-24 10:51:01.161639
last_edit_comment: Mark named this stupid quango.
request_email: geraldine-requests@localhost
@@ -11,6 +12,7 @@ geraldine_public_body:
created_at: 2007-10-24 10:51:01.161639
humpadink_public_body:
name: "Department for Humpadinking"
+ first_letter: D
updated_at: 2007-10-25 10:51:01.161639
last_edit_comment: Not sure what this new department does.
request_email: humpadink-requests@localhost