aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/comment.rb (renamed from app/models/comments.rb)6
-rw-r--r--app/models/info_request.rb25
-rw-r--r--app/models/info_request_event.rb45
3 files changed, 35 insertions, 41 deletions
diff --git a/app/models/comments.rb b/app/models/comment.rb
index 00e58df55..c82bb64ce 100644
--- a/app/models/comments.rb
+++ b/app/models/comment.rb
@@ -19,11 +19,11 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: comments.rb,v 1.1 2008-08-09 15:19:01 francis Exp $
+# $Id: comment.rb,v 1.1 2008-08-13 01:39:41 francis Exp $
-class Comments < ActiveRecord::Base
+class Comment < ActiveRecord::Base
belongs_to :user
- validates_presence_of :user
+ #validates_presence_of :user # breaks during construction of new ones :(
validates_inclusion_of :comment_type, :in => [ 'request' ]
belongs_to :info_request
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index da82f8ab4..78b9655d0 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -23,7 +23,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: info_request.rb,v 1.126 2008-08-09 15:19:01 francis Exp $
+# $Id: info_request.rb,v 1.127 2008-08-13 01:39:41 francis Exp $
require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
@@ -43,6 +43,7 @@ class InfoRequest < ActiveRecord::Base
has_many :info_request_events, :order => 'created_at'
has_many :user_info_request_sent_alerts
has_many :track_things, :order => 'created_at desc'
+ has_many :comments, :order => 'created_at'
# user described state (also update in info_request_event, admin_request/edit.rhtml)
validates_inclusion_of :described_state, :in => [
@@ -259,6 +260,22 @@ public
RequestMailer.deliver_new_response(self, incoming_message)
end
+ # An annotation (comment) is made
+ def add_comment(body, user)
+ comment = Comment.new
+
+ ActiveRecord::Base.transaction do
+ comment.body = body
+ comment.user = user
+ comment.comment_type = 'request'
+ comment.info_request = self
+ comment.save!
+
+ self.log_event("comment", { :comment_id => comment.id })
+ self.save!
+ end
+ end
+
# The "holding pen" is a special request which stores incoming emails whose
# destination request is unknown.
def InfoRequest.holding_pen_request
@@ -275,8 +292,8 @@ public
om = OutgoingMessage.new({
:status => 'ready',
:message_type => 'initial_request',
- :body => 'This is the holding pen request. It shows responses that were sent to invalid addresses, and need moving to the correct request by an adminstrator.',
- :last_sent_at => Time.now()
+ :body => 'this is the holding pen request. it shows responses that were sent to invalid addresses, and need moving to the correct request by an adminstrator.',
+ :last_sent_at => time.now()
})
ir.outgoing_messages << om
om.info_request = ir
@@ -287,7 +304,7 @@ public
return ir
end
- # Change status, including for last event for later historical purposes
+ # change status, including for last event for later historical purposes
def set_described_state(new_state)
ActiveRecord::Base.transaction do
self.awaiting_description = false
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 4eff38554..eb1cb98d8 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.50 2008-08-09 15:19:01 francis Exp $
+# $Id: info_request_event.rb,v 1.51 2008-08-13 01:39:41 francis Exp $
class InfoRequestEvent < ActiveRecord::Base
belongs_to :info_request
@@ -28,6 +28,7 @@ class InfoRequestEvent < ActiveRecord::Base
belongs_to :outgoing_message
belongs_to :incoming_message
+ belongs_to :comment
has_many :user_info_request_sent_alerts
has_many :track_things_sent_emails
@@ -41,7 +42,8 @@ class InfoRequestEvent < ActiveRecord::Base
'edit_outgoing', # outgoing message edited in admin interface
'destroy_incoming', # deleted an incoming message
'manual', # you did something in the db by hand
- 'response'
+ 'response',
+ 'comment'
]
# user described state (also update in info_request)
@@ -69,7 +71,7 @@ class InfoRequestEvent < ActiveRecord::Base
[ :variety, 'V', "variety" ]
],
:if => :indexed_by_search,
- :eager_load => [ :incoming_message, :outgoing_message, { :info_request => [ :user, :public_body ] } ]
+ :eager_load => [ :incoming_message, :outgoing_message, :comment, { :info_request => [ :user, :public_body ] } ]
def requested_by
self.info_request.user.url_name
@@ -99,6 +101,8 @@ class InfoRequestEvent < ActiveRecord::Base
text = text + self.outgoing_message.body_without_salutation + "\n\n"
elsif self.event_type == 'response'
text = text + self.incoming_message.get_text_for_indexing + "\n\n"
+ elsif self.event_type == 'comment'
+ text = text + self.comment.body + "\n\n"
else
# nothing
end
@@ -111,7 +115,7 @@ class InfoRequestEvent < ActiveRecord::Base
return ''
end
def indexed_by_search
- if ['sent', 'followup_sent', 'response'].include?(self.event_type)
+ if ['sent', 'followup_sent', 'response', 'comment'].include?(self.event_type)
if info_request.prominence == 'backpage'
return false
end
@@ -134,42 +138,15 @@ class InfoRequestEvent < ActiveRecord::Base
if not params[:outgoing_message_id].nil?
self.outgoing_message_id = params[:outgoing_message_id]
end
+ if not params[:comment_id].nil?
+ self.comment_id = params[:comment_id]
+ end
self.params_yaml = params.to_yaml
end
def params
YAML.load(self.params_yaml)
end
- # Find related incoming message
- # XXX search for the find below and call this function more instead
- # XXX deprecated, remove it
- def incoming_message_via_params
- if not ['response'].include?(self.event_type)
- return nil
- end
-
- if not self.params[:incoming_message_id]
- raise "internal error, no incoming message id for response event"
- end
-
- return IncomingMessage.find(self.params[:incoming_message_id].to_i)
- end
-
- # Find related outgoing message
- # XXX search for the find below and call this function more instead
- # XXX deprecated, remove it
- def outgoing_message_via_params
- if not [ 'edit_outgoing', 'sent', 'resent', 'followup_sent' ].include?(self.event_type)
- return nil
- end
-
- if not self.params[:outgoing_message_id]
- raise "internal error, no outgoing message id for event type which expected one"
- end
-
- return OutgoingMessage.find(self.params[:outgoing_message_id].to_i)
- end
-
# Display version of status
def display_status
if incoming_message.nil?