aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/incoming_message.rb15
-rw-r--r--config/general.yml-example9
-rw-r--r--lib/configuration.rb2
-rw-r--r--lib/tasks/cleanup.rake22
-rw-r--r--spec/models/incoming_message_spec.rb18
5 files changed, 59 insertions, 7 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 6db145348..124db8d4a 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -834,14 +834,15 @@ class IncomingMessage < ActiveRecord::Base
def fully_destroy
ActiveRecord::Base.transaction do
- for o in self.outgoing_message_followups
- o.incoming_message_followup = nil
- o.save!
+ outgoing_message_followups.each do |outgoing_message_followup|
+ outgoing_message_followup.incoming_message_followup = nil
+ outgoing_message_followup.save!
+ end
+ info_request_events.each do |info_request_event|
+ info_request_event.track_things_sent_emails.each { |a| a.destroy }
+ info_request_event.user_info_request_sent_alerts.each { |a| a.destroy }
+ info_request_event.destroy
end
- info_request_event = InfoRequestEvent.find_by_incoming_message_id(self.id)
- info_request_event.track_things_sent_emails.each { |a| a.destroy }
- info_request_event.user_info_request_sent_alerts.each { |a| a.destroy }
- info_request_event.destroy
self.raw_email.destroy_file_representation!
self.destroy
end
diff --git a/config/general.yml-example b/config/general.yml-example
index 6e223406e..1fc0f668d 100644
--- a/config/general.yml-example
+++ b/config/general.yml-example
@@ -172,6 +172,15 @@ VARNISH_HOST: localhost
# Adding a value here will enable Google Analytics on all non-admin pages for non-admin users.
GA_CODE: ''
+# We need to add the WDTK survey variables here, or else the deployment
+# system will cry.
+SURVEY_SECRET: ''
+# Blank this out if the survey host is unavailable - people going to the
+# survey URL will get a message that the survey is unavailable
+SURVEY_URL: ''
+# Set this to false if you don't want survey emails to be sent
+SEND_SURVEY_MAILS: true
+
# If you want to override *all* the public body request emails with your own
# email so that request emails that would normally go to the public body
# go to you, then uncomment below and fill in your email.
diff --git a/lib/configuration.rb b/lib/configuration.rb
index d525bf712..077155026 100644
--- a/lib/configuration.rb
+++ b/lib/configuration.rb
@@ -62,6 +62,8 @@ module AlaveteliConfiguration
:SITE_NAME => 'Alaveteli',
:SKIP_ADMIN_AUTH => false,
:SPECIAL_REPLY_VERY_LATE_AFTER_DAYS => 60,
+ :SURVEY_URL => '',
+ :SEND_SURVEY_MAILS => true,
:THEME_BRANCH => false,
:THEME_URL => "",
:THEME_URLS => [],
diff --git a/lib/tasks/cleanup.rake b/lib/tasks/cleanup.rake
new file mode 100644
index 000000000..c1cc6e003
--- /dev/null
+++ b/lib/tasks/cleanup.rake
@@ -0,0 +1,22 @@
+namespace :cleanup do
+
+ desc 'Clean up old events (> 1 year) from the holding pen to make admin actions there faster'
+ task :holding_pen => :environment do
+ dryrun = ENV['DRYRUN'] != '0'
+ if dryrun
+ STDERR.puts "This is a dryrun - nothing will be deleted"
+ end
+ holding_pen = InfoRequest.find_by_url_title('holding_pen')
+ old_events = holding_pen.info_request_events.find_each(:conditions => ['event_type in (?)
+ AND created_at < ?',
+ ['redeliver_incoming',
+ 'destroy_incoming'],
+ Time.now - 1.year]) do |event|
+ puts event.inspect
+ if ! dryrun
+ event.destroy
+ end
+ end
+ end
+
+end
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index f06dcbeeb..3b6887f76 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -112,6 +112,24 @@ describe IncomingMessage, 'when asked if a user can view it' do
end
+describe 'when destroying a message' do
+
+ before do
+ @incoming_message = FactoryGirl.create(:plain_incoming_message)
+ end
+
+ it 'can destroy a message with more than one info request event' do
+ @info_request = @incoming_message.info_request
+ @info_request.log_event('response',
+ :incoming_message_id => @incoming_message.id)
+ @info_request.log_event('edit_incoming',
+ :incoming_message_id => @incoming_message.id)
+ @incoming_message.fully_destroy
+ IncomingMessage.where(:id => @incoming_message.id).should be_empty
+ end
+
+end
+
describe 'when asked if it is indexed by search' do
before do