aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/request_controller.rb19
-rw-r--r--app/models/outgoing_message.rb38
-rw-r--r--todo.txt3
3 files changed, 43 insertions, 17 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index ad809f716..98924cde2 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/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: request_controller.rb,v 1.36 2008-01-10 01:13:27 francis Exp $
+# $Id: request_controller.rb,v 1.37 2008-01-10 18:12:10 francis Exp $
class RequestController < ApplicationController
@@ -80,6 +80,17 @@ class RequestController < ApplicationController
@collapse_quotes = params[:unfold] ? false : true
@is_owning_user = !authenticated_user.nil? && authenticated_user.id == @info_request.user_id
+ params_outgoing_message = params[:outgoing_message]
+ if params_outgoing_message.nil?
+ params_outgoing_message = {}
+ end
+ params_outgoing_message.merge!({
+ :status => 'ready',
+ :message_type => 'followup',
+ :incoming_message_followup => @incoming_message
+ })
+ @outgoing_message = OutgoingMessage.new(params_outgoing_message)
+
if @incoming_message.info_request_id != params[:id].to_i
raise sprintf("Incoming message %d does not belong to request %d", @incoming_message.info_request_id, params[:id])
end
@@ -110,13 +121,8 @@ class RequestController < ApplicationController
return
elsif !params[:submitted_followup].nil?
# Send a follow up message
- @outgoing_message = OutgoingMessage.new(params[:outgoing_message].merge({
- :status => 'ready',
- :message_type => 'followup'
- }))
@info_request.outgoing_messages << @outgoing_message
@outgoing_message.info_request = @info_request
- @outgoing_message.incoming_message_followup = @incoming_message
# See if values were valid or not
if !@info_request.valid?
@@ -135,7 +141,6 @@ class RequestController < ApplicationController
# do nothing - as "authenticated?" has done the redirect to signin page for us
end
else
- @outgoing_message = OutgoingMessage.new(params[:outgoing_message])
# render default show_response template
end
end
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index a8d9425c5..a9244c652 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -21,33 +21,55 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: outgoing_message.rb,v 1.19 2008-01-10 01:13:28 francis Exp $
+# $Id: outgoing_message.rb,v 1.20 2008-01-10 18:12:10 francis Exp $
class OutgoingMessage < ActiveRecord::Base
belongs_to :info_request
validates_presence_of :info_request
- validates_presence_of :body, :message => "^Please enter your letter requesting information"
-
validates_inclusion_of :status, :in => ['ready', 'sent', 'failed']
validates_inclusion_of :message_type, :in => ['initial_request', 'followup' ] #, 'complaint']
belongs_to :incoming_message_followup, :foreign_key => 'incoming_message_followup_id', :class_name => 'IncomingMessage'
+ # How the default letter starts and ends
+ def get_salutation
+ ret = "Dear "
+ if self.message_type == 'followup' && !self.incoming_message_followup.nil? && !self.incoming_message_followup.safe_mail_from.nil?
+ ret = ret + self.incoming_message_followup.safe_mail_from
+ else
+ ret = ret + "Sir or Madam"
+ end
+ return ret + ","
+ end
+ def get_signoff
+ if self.message_type == 'followup'
+ return "Yours sincerely,"
+ else
+ return "Yours faithfully,"
+ end
+ end
+
# Set default letter
def after_initialize
if self.body.nil?
- self.body = "Dear Sir or Madam,\n\n\n\nYours faithfully,\n\n"
+ self.body = get_salutation + "\n\n\n\n" + get_signoff + "\n\n"
end
end
# Check have edited letter
def validate
- if self.body =~ /\ADear Sir or Madam,\s+Yours faithfully,\s+/
- errors.add(:body, "^Please enter your letter requesting information")
+ if self.body.empty? || self.body =~ /\A#{get_salutation}\s+#{get_signoff}\s+/
+ if self.message_type == 'followup'
+ errors.add(:body, "^Please enter your follow up message")
+ elsif
+ errors.add(:body, "^Please enter your letter requesting information")
+ else
+ raise "Message id #{self.id} has type '#{self.message_type}' which validate can't handle"
+ end
end
- if self.body =~ /Yours faithfully,\s+\Z/
- errors.add(:body, '^Please sign at the bottom with your name, or alter the "Yours faithfully" signature')
+ if self.body =~ /#{get_signoff}\s+\Z/
+ errors.add(:body, '^Please sign at the bottom with your name, or alter the "' + get_signoff + '" signature')
end
end
diff --git a/todo.txt b/todo.txt
index b4995ba50..762155cc1 100644
--- a/todo.txt
+++ b/todo.txt
@@ -20,10 +20,9 @@ Next
====
Let requester send follow-ups - but to which email address???!! aargh
- - fix error text on form for followup, and default values
- link to the follow up form, or embed in bottom of main request page
- don't show classify link on /response/ page
- - add test code for followups
+ - add spec test code for followups
- should we quote the message we're replying to? hmmm
Alert somewhere if working days table not up to date