aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/incoming_message.rb6
-rw-r--r--app/models/info_request.rb13
-rw-r--r--app/models/public_body.rb41
-rw-r--r--app/models/request_mailer.rb37
-rw-r--r--app/models/track_thing.rb7
5 files changed, 84 insertions, 20 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 367909f57..48fbfe73a 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -347,12 +347,10 @@ class IncomingMessage < ActiveRecord::Base
text.gsub!(/^\s?#{name}[^\n]+\n([^\n]+\n)?\s?Sent by:[^\n]+\n.*/ims, "\n\n" + replacement)
# Some other sort of forwarding quoting
- # http://www.whatdotheyknow.com/request/224/response/326
- text.gsub!(/^#{name}[^\n]+\n[0-9\/:\s]+\s+To\s+FOI requests at.*/ims, "\n\n" + replacement)
+ text.gsub!(/^\s?#{name}\s+To\s+FOI requests at.*/ims, "\n\n" + replacement)
- # http://www.whatdotheyknow.com/request/how_do_the_pct_deal_with_retirin_33#incoming-930
# http://www.whatdotheyknow.com/request/229/response/809
- text.gsub!(/^From: [^\n]+\nSent: [^\n]+\nTo:\s+['"?]#{name}['"]?\nSubject:.*/ims, "\n\n" + replacement)
+ text.gsub!(/^\s?From: [^\n]+\n\s?Sent: [^\n]+\n\s?To:\s+['"]?#{name}['"]?\n\s?Subject:.*/ims, "\n\n" + replacement)
return text
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 74a67b9d9..47424e573 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -584,12 +584,11 @@ public
# waiting_classification
# waiting_response_overdue
# waiting_response_very_overdue
- def calculate_status
- if @@custom_states_loaded
- return self.theme_calculate_status
- else
- self.base_calculate_status
+ def calculate_status(cached_value_ok=false)
+ if cached_value_ok && @cached_calculated_status
+ return @cached_calculated_status
end
+ @cached_calculated_status = @@custom_states_loaded ? self.theme_calculate_status : self.base_calculate_status
end
def base_calculate_status
@@ -871,8 +870,8 @@ public
end
end
- def display_status
- InfoRequest.get_status_description(self.calculate_status)
+ def display_status(cached_value_ok=false)
+ InfoRequest.get_status_description(self.calculate_status(cached_value_ok))
end
# Completely delete this request and all objects depending on it
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index c3bc060a4..57fe27767 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -413,7 +413,7 @@ class PublicBody < ActiveRecord::Base
next
end
- field_list = ['name', 'short_name', 'request_email', 'notes', 'publication_scheme', 'home_page', 'tag_string']
+ field_list = ['name', 'short_name', 'request_email', 'notes', 'publication_scheme', 'disclosure_log', 'home_page', 'tag_string']
if public_body = bodies_by_name[name] # Existing public body
available_locales.each do |locale|
@@ -500,6 +500,45 @@ class PublicBody < ActiveRecord::Base
return [errors, notes]
end
+ # Returns all public bodies (except for the internal admin authority) as csv
+ def self.export_csv
+ public_bodies = PublicBody.visible.find(:all, :order => 'url_name',
+ :include => [:translations, :tags])
+ FasterCSV.generate() do |csv|
+ csv << [
+ 'Name',
+ 'Short name',
+ # deliberately not including 'Request email'
+ 'URL name',
+ 'Tags',
+ 'Home page',
+ 'Publication scheme',
+ 'Disclosure log',
+ 'Notes',
+ 'Created at',
+ 'Updated at',
+ 'Version',
+ ]
+ public_bodies.each do |public_body|
+ csv << [
+ public_body.name,
+ public_body.short_name,
+ # DO NOT include request_email (we don't want to make it
+ # easy to spam all authorities with requests)
+ public_body.url_name,
+ public_body.tag_string,
+ public_body.calculated_home_page,
+ public_body.publication_scheme,
+ public_body.disclosure_log,
+ public_body.notes,
+ public_body.created_at,
+ public_body.updated_at,
+ public_body.version,
+ ]
+ end
+ end
+ end
+
# Does this user have the power of FOI officer for this body?
def is_foi_officer?(user)
user_domain = user.email_domain
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb
index 413e93e25..90c4c6b53 100644
--- a/app/models/request_mailer.rb
+++ b/app/models/request_mailer.rb
@@ -256,24 +256,47 @@ class RequestMailer < ApplicationMailer
def self.alert_overdue_requests()
info_requests = InfoRequest.find(:all,
:conditions => [
- "described_state = 'waiting_response' and awaiting_description = ? and user_id is not null", false
+ "described_state = 'waiting_response'
+ AND awaiting_description = ?
+ AND user_id is not null
+ AND (SELECT id
+ FROM user_info_request_sent_alerts
+ WHERE alert_type = 'very_overdue_1'
+ AND info_request_id = info_requests.id
+ AND user_id = info_requests.user_id
+ AND info_request_event_id = (SELECT max(id)
+ FROM info_request_events
+ WHERE event_type in ('sent',
+ 'followup_sent',
+ 'resent',
+ 'followup_resent')
+ AND info_request_id = info_requests.id)
+ ) IS NULL", false
],
:include => [ :user ]
)
for info_request in info_requests
alert_event_id = info_request.last_event_forming_initial_request.id
# Only overdue requests
- if ['waiting_response_overdue', 'waiting_response_very_overdue'].include?(info_request.calculate_status)
- if info_request.calculate_status == 'waiting_response_overdue'
+ calculated_status = info_request.calculate_status
+ if ['waiting_response_overdue', 'waiting_response_very_overdue'].include?(calculated_status)
+ if calculated_status == 'waiting_response_overdue'
alert_type = 'overdue_1'
- elsif info_request.calculate_status == 'waiting_response_very_overdue'
+ elsif calculated_status == 'waiting_response_very_overdue'
alert_type = 'very_overdue_1'
else
raise "unknown request status"
end
# For now, just to the user who created the request
- sent_already = UserInfoRequestSentAlert.find(:first, :conditions => [ "alert_type = ? and user_id = ? and info_request_id = ? and info_request_event_id = ?", alert_type, info_request.user_id, info_request.id, alert_event_id])
+ sent_already = UserInfoRequestSentAlert.find(:first, :conditions => [ "alert_type = ?
+ AND user_id = ?
+ AND info_request_id = ?
+ AND info_request_event_id = ?",
+ alert_type,
+ info_request.user_id,
+ info_request.id,
+ alert_event_id])
if sent_already.nil?
# Alert not yet sent for this user, so send it
store_sent = UserInfoRequestSentAlert.new
@@ -284,9 +307,9 @@ class RequestMailer < ApplicationMailer
# Only send the alert if the user can act on it by making a followup
# (otherwise they are banned, and there is no point sending it)
if info_request.user.can_make_followup?
- if info_request.calculate_status == 'waiting_response_overdue'
+ if calculated_status == 'waiting_response_overdue'
RequestMailer.deliver_overdue_alert(info_request, info_request.user)
- elsif info_request.calculate_status == 'waiting_response_very_overdue'
+ elsif calculated_status == 'waiting_response_very_overdue'
RequestMailer.deliver_very_overdue_alert(info_request, info_request.user)
else
raise "unknown request status"
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb
index d1cef4d4d..2a61eb858 100644
--- a/app/models/track_thing.rb
+++ b/app/models/track_thing.rb
@@ -107,7 +107,12 @@ class TrackThing < ActiveRecord::Base
end
descriptions = []
if varieties.include? _("requests")
- descriptions << _("requests which are {{list_of_statuses}}", :list_of_statuses => Array(statuses).sort.join(_(' or ')))
+ if statuses.empty?
+ # HACK: Relies on the 'descriptions.sort' below to luckily put this first
+ descriptions << _("all requests")
+ else
+ descriptions << _("requests which are {{list_of_statuses}}", :list_of_statuses => Array(statuses).sort.join(_(' or ')))
+ end
varieties -= [_("requests")]
end
if descriptions.empty? and varieties.empty?