From 32c1fe80dc3fefc85d27a8465b67084fbd4fe60e Mon Sep 17 00:00:00 2001 From: francis Date: Tue, 18 Aug 2009 20:51:25 +0000 Subject: Don't allow duplicate followup messages to the same request. Prevent requests, followups and annotations which have all capitals or all lowercase letters. --- app/models/info_request.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index dfa66102e..13d5c8a2e 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -24,7 +24,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.198 2009-07-03 11:43:37 francis Exp $ +# $Id: info_request.rb,v 1.199 2009-08-18 20:51:26 francis Exp $ require 'digest/sha1' require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian') @@ -279,6 +279,17 @@ public end end + def find_existing_outgoing_message(body) + # XXX can add other databases here which have regexp_replace + if ActiveRecord::Base.connection.adapter_name == "PostgreSQL" + # Exclude spaces from the body comparison using regexp_replace + return self.outgoing_messages.find(:first, :conditions => [ "regexp_replace(outgoing_messages.body, '[[:space:]]', '', 'g') = regexp_replace(?, '[[:space:]]', '', 'g')", body ]) + else + # For other databases (e.g. SQLite) not the end of the world being space-sensitive for this check + return self.outgoing_messages.find(:first, :conditions => [ "outgoing_messages.body = ?", body ]) + end + end + # A new incoming email to this request def receive(email, raw_email_data, override_stop_new_responses = false) if !override_stop_new_responses -- cgit v1.2.3