From 39d7c598161b6b1577ef6d18de7d13e68fa5706f Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 3 Nov 2014 10:24:40 +0000 Subject: Only mark email_subject_request as HTML safe when used in email subject. It's also used in the web interface and needs to be escaped there. --- app/models/info_request.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index d0052603a..dcd16878b 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -292,13 +292,18 @@ public end # Subject lines for emails about the request - def email_subject_request - _('{{law_used_full}} request - {{title}}',:law_used_full=>self.law_used_full,:title=>self.title.html_safe) + def email_subject_request(opts = {}) + html = opts.fetch(:html, true) + _('{{law_used_full}} request - {{title}}', + :law_used_full => self.law_used_full, + :title => (html ? title : title.html_safe)) end - def email_subject_followup(incoming_message = nil) + def email_subject_followup(opts = {}) + incoming_message = opts.fetch(:incoming_message, nil) + html = opts.fetch(:html, true) if incoming_message.nil? || !incoming_message.valid_to_reply_to? || !incoming_message.subject - 'Re: ' + self.email_subject_request + 'Re: ' + self.email_subject_request(:html => html) else if incoming_message.subject.match(/^Re:/i) incoming_message.subject -- cgit v1.2.3 From 224725e202d581d956e8958c521abb00de9935b1 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Thu, 27 Nov 2014 10:20:37 +0000 Subject: Refactor the application of masks and censor rules to messages. Seems more logical to make this one method that figures out what to do based on file type. Plus, incoming message does so many things, it seemed like having these related methods be separate would make them easier to read and understand. Also, email, mobile and login substitution texts weren't being translated. Finally, I think passing the censor rules and masks as arguments is a first step in some more decoupling of models. --- app/models/info_request.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index dcd16878b..20b7ef9af 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1153,6 +1153,22 @@ public return binary end + # Masks we apply to text associated with this request convert email addresses + # we know about into textual descriptions of them + def masks + masks = [{ :to_replace => incoming_email, + :replacement => _('[FOI #{{request}} email]', + :request => id.to_s) }, + { :to_replace => AlaveteliConfiguration::contact_email, + :replacement => _("[{{site_name}} contact email]", + :site_name => AlaveteliConfiguration::site_name)} ] + if public_body.is_followupable? + masks << { :to_replace => public_body.request_email, + :replacement => _("[{{public_body}} request email]", + :public_body => public_body.short_or_long_name) } + end + end + def is_owning_user?(user) !user.nil? && (user.id == user_id || user.owns_every_request?) end -- cgit v1.2.3 From 01625ed1baef70c23499124afe090642665a6157 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 1 Oct 2014 14:02:40 +0100 Subject: Improve InfoRequest.find_in_state SQL --- app/models/info_request.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index d0052603a..74c245e56 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1345,9 +1345,9 @@ public end def InfoRequest.find_in_state(state) - find(:all, :select => '*, ' + last_event_time_clause + ' as last_event_time', - :conditions => ["described_state = ?", state], - :order => "last_event_time") + select("*, #{ last_event_time_clause } as last_event_time"). + where(:described_state => state). + order('last_event_time') end private -- cgit v1.2.3 From cfbd214983e70226f107352bc8ff145253a6beb0 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 12 Jan 2015 12:23:06 +0000 Subject: Remove duplicate method. --- app/models/info_request.rb | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 2b60e13d8..8d455e488 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -210,16 +210,6 @@ class InfoRequest < ActiveRecord::Base OLD_AGE_IN_DAYS = 21.days - def after_initialize - if self.described_state.nil? - self.described_state = 'waiting_response' - end - # FOI or EIR? - if !self.public_body.nil? && self.public_body.eir_only? - self.law_used = 'eir' - end - end - def visible_comments self.comments.find(:all, :conditions => 'visible') end -- cgit v1.2.3 From 7f591266bfde68a7484beb6535281d404f3c32cb Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 9 Feb 2015 10:23:37 +0000 Subject: Remove unused line --- app/models/info_request.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 8d455e488..814057ef4 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -748,7 +748,6 @@ public # This is a long stop - even with UK public interest test extensions, 40 # days is a very long time. def date_very_overdue_after - last_sent = last_event_forming_initial_request if self.public_body.is_school? # schools have 60 working days maximum (even over a long holiday) Holiday.due_date_from(self.date_initial_request_last_sent_at, AlaveteliConfiguration::special_reply_very_late_after_days, AlaveteliConfiguration::working_or_calendar_days) -- cgit v1.2.3 From 3fec0fe90c8f208a8ce997c09282b34af4b3621f Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Mon, 9 Feb 2015 17:11:57 +0000 Subject: Allow custom states to be tested. Since https://github.com/mysociety/alaveteli/commit/80ad2d4c31075ffc994e8c48ea25e6e3c486c364 no themes have been loaded by tests unless explicitly specified, so I think it's safe to remove the code added in https://github.com/mysociety/alaveteli/commit/3dfc53f6b82b3c5da79a4c710d45b859f61f4f5f --- app/models/info_request.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 814057ef4..fd42ccd9c 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -187,11 +187,9 @@ class InfoRequest < ActiveRecord::Base @@custom_states_loaded = false begin - if !Rails.env.test? - require 'customstates' - include InfoRequestCustomStates - @@custom_states_loaded = true - end + require 'customstates' + include InfoRequestCustomStates + @@custom_states_loaded = true rescue MissingSourceFile, NameError end -- cgit v1.2.3