aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/censor_rule.rb33
-rw-r--r--app/models/incoming_message.rb25
-rw-r--r--app/models/info_request.rb3
3 files changed, 53 insertions, 8 deletions
diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb
new file mode 100644
index 000000000..acc4349e6
--- /dev/null
+++ b/app/models/censor_rule.rb
@@ -0,0 +1,33 @@
+# models/censor_rule.rb:
+# Stores alterations to remove specific data from requests.
+#
+# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
+# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
+#
+# $Id: censor_rule.rb,v 1.1 2008-10-27 18:18:30 francis Exp $
+
+class CensorRule < ActiveRecord::Base
+ belongs_to :info_request
+ belongs_to :user
+ belongs_to :public_body
+
+ def apply_to_text(text)
+ text.gsub!(self.text, self.replacement)
+ return text
+ end
+ def apply_to_binary(binary)
+ replacement = self.text.gsub(/./, 'x')
+ binary.gsub!(self.text, replacement)
+ return binary
+ end
+
+
+ def validate
+ if self.info_request.nil? && self.user.nil? && self.public_body.nil?
+ errors.add("Censor must apply to an info request a user or a body; ")
+ end
+ end
+end
+
+
+
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index a6ca692c8..eb63ee6fa 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -19,7 +19,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: incoming_message.rb,v 1.154 2008-10-17 20:43:25 francis Exp $
+# $Id: incoming_message.rb,v 1.155 2008-10-27 18:18:30 francis Exp $
# TODO
# Move some of the (e.g. quoting) functions here into rblib, as they feel
@@ -288,7 +288,8 @@ class IncomingMessage < ActiveRecord::Base
end
# Replaces all email addresses in (possibly binary data) with equal length alternative ones.
- def IncomingMessage.binary_mask_all_emails(text)
+ # Also replaces censor items
+ def binary_mask_stuff(text)
orig_size = text.size
# Replace ASCII email addresses...
@@ -311,7 +312,12 @@ class IncomingMessage < ActiveRecord::Base
text.gsub!(email, mask)
end
- raise "internal error in binary_mask_all_emails" if text.size != orig_size
+ # Replace censor items
+ for censor_rule in self.info_request.censor_rules
+ text = censor_rule.apply_to_binary(text)
+ end
+
+ raise "internal error in binary_mask_stuff" if text.size != orig_size
return text
end
@@ -337,7 +343,7 @@ class IncomingMessage < ActiveRecord::Base
end
# Remove emails, mobile phones and other details FOI officers ask us to remove.
- def self.remove_privacy_sensitive_things(text)
+ def remove_privacy_sensitive_things(text)
text = text.dup
# Remove any email addresses - we don't want bounce messages to leak out
@@ -362,6 +368,11 @@ class IncomingMessage < ActiveRecord::Base
# Remove WhatDoTheyKnow signup links
text.gsub!(/http:\/\/www.whatdotheyknow.com\/c\/[^\s]+/, "[WDTK login link]")
+ # Remove things from censor rules
+ for censor_rule in self.info_request.censor_rules
+ text = censor_rule.apply_to_text(text)
+ end
+
return text
end
@@ -704,7 +715,7 @@ class IncomingMessage < ActiveRecord::Base
# Find the body text and remove emails for privacy/anti-spam reasons
text = get_main_body_text
text = self.mask_special_emails(text)
- text = IncomingMessage.remove_privacy_sensitive_things(text)
+ text = self.remove_privacy_sensitive_things(text)
# Remove quoted sections, adding HTML. XXX The FOLDED_QUOTED_SECTION is
# a nasty hack so we can escape other HTML before adding the unfold
@@ -745,7 +756,7 @@ class IncomingMessage < ActiveRecord::Base
# Find the body text and remove emails for privacy/anti-spam reasons
text = get_main_body_text
text = self.mask_special_emails(text)
- text = IncomingMessage.remove_privacy_sensitive_things(text)
+ text = self.remove_privacy_sensitive_things(text)
# Remove existing quoted sections
text = self.remove_lotus_quoting(text, '')
@@ -763,7 +774,7 @@ class IncomingMessage < ActiveRecord::Base
# Remove any privacy things
text = self.cached_attachment_text
text = self.mask_special_emails(text)
- text = IncomingMessage.remove_privacy_sensitive_things(text)
+ text = self.remove_privacy_sensitive_things(text)
return text
end
def IncomingMessage.get_attachment_text_internal_one_file(content_type, body)
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 0c99dadbf..ebf06913c 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.146 2008-10-14 12:48:49 francis Exp $
+# $Id: info_request.rb,v 1.147 2008-10-27 18:18:30 francis Exp $
require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
@@ -44,6 +44,7 @@ class InfoRequest < ActiveRecord::Base
has_many :user_info_request_sent_alerts
has_many :track_things, :order => 'created_at desc'
has_many :comments, :order => 'created_at'
+ has_many :censor_rules, :order => 'created_at desc'
# user described state (also update in info_request_event, admin_request/edit.rhtml)
validates_inclusion_of :described_state, :in => [