diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/info_request.rb | 16 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 58 | ||||
-rw-r--r-- | app/models/public_body.rb | 2 | ||||
-rw-r--r-- | app/models/request_mailer.rb | 16 | ||||
-rw-r--r-- | app/models/track_mailer.rb | 4 | ||||
-rw-r--r-- | app/models/track_thing.rb | 107 | ||||
-rw-r--r-- | app/models/user.rb | 9 | ||||
-rw-r--r-- | app/models/user_mailer.rb | 2 |
8 files changed, 148 insertions, 66 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index c667e1499..88a02cc2c 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -117,13 +117,13 @@ class InfoRequest < ActiveRecord::Base # only check on create, so existing models with mixed case are allowed def validate_on_create if !self.title.nil? && !MySociety::Validate.uses_mixed_capitals(self.title, 10) - errors.add(:title, N_('Please write the summary using a mixture of capital and lower case letters. This makes it easier for others to read.')) + errors.add(:title, _('Please write the summary using a mixture of capital and lower case letters. This makes it easier for others to read.')) end if !self.title.nil? && title.size > 200 - errors.add(:title, N_('Please keep the summary short, like in the subject of an email. You can use a phrase, rather than a full sentence.')) + errors.add(:title, _('Please keep the summary short, like in the subject of an email. You can use a phrase, rather than a full sentence.')) end if !self.title.nil? && self.title =~ /^(FOI|Freedom of Information)\s*requests?$/i - errors.add(:title, N_('Please describe more what the request is about in the subject. There is no need to say it is an FOI request, we add that on anyway.')) + errors.add(:title, _('Please describe more what the request is about in the subject. There is no need to say it is an FOI request, we add that on anyway.')) end end @@ -451,7 +451,7 @@ public self.log_event("response", params) self.save! end - + self.info_request_events.each { |event| event.xapian_mark_needs_index } # for the "waiting_classification" index RequestMailer.deliver_new_response(self, incoming_message) end @@ -564,6 +564,7 @@ public def calculate_event_states curr_state = nil for event in self.info_request_events.reverse + event.xapian_mark_needs_index # we need to reindex all events in order to update their latest_* terms if curr_state.nil? if !event.described_state.nil? curr_state = event.described_state @@ -779,8 +780,7 @@ public # Display version of status - def display_status - status = self.calculate_status + def InfoRequest.get_status_description(status) if status == 'waiting_classification' _("Awaiting classification.") elsif status == 'waiting_response' @@ -818,6 +818,10 @@ public end end + def display_status + InfoRequest.get_status_description(self.calculate_status) + end + # Completely delete this request and all objects depending on it def fully_destroy self.track_things.each do |track_thing| diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 1550a4bf5..4ea89bf81 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -94,7 +94,7 @@ class InfoRequestEvent < ActiveRecord::Base [ :created_at_numeric, 1, "created_at", :number ], # for sorting [ :described_at_numeric, 2, "described_at", :number ], # XXX using :number for lack of :datetime support in Xapian values [ :request, 3, "request_collapse", :string ], - [ :request_title_collapse, 4, "request_title_collapse", :string ] + [ :request_title_collapse, 4, "request_title_collapse", :string ], ], :terms => [ [ :calculated_state, 'S', "status" ], [ :requested_by, 'B', "requested_by" ], @@ -102,6 +102,9 @@ class InfoRequestEvent < ActiveRecord::Base [ :commented_by, 'C', "commented_by" ], [ :request, 'R', "request" ], [ :variety, 'V', "variety" ], + [ :latest_variety, 'K', "latest_variety" ], + [ :latest_status, 'L', "latest_status" ], + [ :waiting_classification, 'W', "waiting_classification" ], [ :filetype, 'T', "filetype" ], [ :tags, 'U', "tag" ] ], @@ -129,6 +132,27 @@ class InfoRequestEvent < ActiveRecord::Base def request self.info_request.url_title end + + def latest_variety + for event in self.info_request.info_request_events.reverse + if !event.variety.nil? and !event.variety.empty? + return event.variety + end + end + end + + def latest_status + for event in self.info_request.info_request_events.reverse + if !event.calculated_state.nil? and !event.calculated_state.empty? + return event.calculated_state + end + end + end + + def waiting_classification + self.info_request.awaiting_description == true ? "yes" : "no" + end + def request_title_collapse url_title = self.info_request.url_title # remove numeric section from the end, use this to group lots @@ -279,37 +303,7 @@ class InfoRequestEvent < ActiveRecord::Base def display_status if is_incoming_message? status = self.calculated_state - if !status.nil? - if status == 'waiting_response' - return _("Acknowledgement") - elsif status == 'waiting_clarification' - return _("Clarification required") - elsif status == 'gone_postal' - return _("Handled by post") - elsif status == 'deadline_extended' - return _("Deadline Extended") - elsif status == 'wrong_response' - return _("Wrong Response") - elsif status == 'not_held' - return _("Information not held") - elsif status == 'rejected' - return _("Refused") - elsif status == 'partially_successful' - return _("Some information sent") - elsif status == 'successful' - return _("All information sent") - elsif status == 'internal_review' - return _("Internal review acknowledgement") - elsif status == 'user_withdrawn' - return _("Withdrawn by requester") - elsif status == 'error_message' - return _("Delivery error") - elsif status == 'requires_admin' - return _("Unusual response") - end - raise "unknown status " + status - end - return "Response" + return status.nil? ? _("Response") : InfoRequest.get_status_description(status) end if is_outgoing_message? diff --git a/app/models/public_body.rb b/app/models/public_body.rb index c19433704..81149e3c2 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -206,7 +206,7 @@ class PublicBody < ActiveRecord::Base return self.created_at.strftime("%Y%m%d%H%M%S") end def variety - "authority" + return "authority" end # if the URL name has changed, then all requested_from: queries diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index 7bf70ab08..f46ce33c5 100644 --- a/app/models/request_mailer.rb +++ b/app/models/request_mailer.rb @@ -62,7 +62,7 @@ class RequestMailer < ApplicationMailer @from = contact_from_name_and_email headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # not much we can do if the user's email is broken 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF' # http://social.technet.microsoft.com/forums/en-US/exchangesvrdevelopment/thread/7e4af3fb-4ceb-4df6-9ed3-665ccdd157d2#fe60eeb3-b0ab-4443-9e54-3da490f25cbf + 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email @subject = "New response to your FOI request - " + info_request.title @body = { :incoming_message => incoming_message, :info_request => info_request, :url => url } @@ -81,7 +81,7 @@ class RequestMailer < ApplicationMailer @from = contact_from_name_and_email headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # not much we can do if the user's email is broken 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF' # http://social.technet.microsoft.com/forums/en-US/exchangesvrdevelopment/thread/7e4af3fb-4ceb-4df6-9ed3-665ccdd157d2#fe60eeb3-b0ab-4443-9e54-3da490f25cbf + 'X-Auto-Response-Suppress' => 'OOF' @recipients = user.name_and_email @subject = "Delayed response to your FOI request - " + info_request.title @body = { :info_request => info_request, :url => url } @@ -100,7 +100,7 @@ class RequestMailer < ApplicationMailer @from = contact_from_name_and_email headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # not much we can do if the user's email is broken 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF' # http://social.technet.microsoft.com/forums/en-US/exchangesvrdevelopment/thread/7e4af3fb-4ceb-4df6-9ed3-665ccdd157d2#fe60eeb3-b0ab-4443-9e54-3da490f25cbf + 'X-Auto-Response-Suppress' => 'OOF' @recipients = user.name_and_email @subject = "You're long overdue a response to your FOI request - " + info_request.title @body = { :info_request => info_request, :url => url } @@ -120,7 +120,7 @@ class RequestMailer < ApplicationMailer @from = contact_from_name_and_email headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # not much we can do if the user's email is broken 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF' # http://social.technet.microsoft.com/forums/en-US/exchangesvrdevelopment/thread/7e4af3fb-4ceb-4df6-9ed3-665ccdd157d2#fe60eeb3-b0ab-4443-9e54-3da490f25cbf + 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email @subject = "Was the response you got to your FOI request any good?" @body = { :incoming_message => incoming_message, :info_request => info_request, :url => url } @@ -131,7 +131,7 @@ class RequestMailer < ApplicationMailer @from = contact_from_name_and_email headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # not much we can do if the user's email is broken 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF' # http://social.technet.microsoft.com/forums/en-US/exchangesvrdevelopment/thread/7e4af3fb-4ceb-4df6-9ed3-665ccdd157d2#fe60eeb3-b0ab-4443-9e54-3da490f25cbf + 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email @subject = "Someone has updated the status of your request" url = main_url(request_url(info_request)) @@ -152,7 +152,7 @@ class RequestMailer < ApplicationMailer @from = contact_from_name_and_email headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # not much we can do if the user's email is broken 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF' # http://social.technet.microsoft.com/forums/en-US/exchangesvrdevelopment/thread/7e4af3fb-4ceb-4df6-9ed3-665ccdd157d2#fe60eeb3-b0ab-4443-9e54-3da490f25cbf + 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email @subject = "Clarify your FOI request - " + info_request.title @body = { :incoming_message => incoming_message, :info_request => info_request, :url => url } @@ -163,7 +163,7 @@ class RequestMailer < ApplicationMailer @from = contact_from_name_and_email headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # not much we can do if the user's email is broken 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF' # http://social.technet.microsoft.com/forums/en-US/exchangesvrdevelopment/thread/7e4af3fb-4ceb-4df6-9ed3-665ccdd157d2#fe60eeb3-b0ab-4443-9e54-3da490f25cbf + 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email @subject = "Somebody added a note to your FOI request - " + info_request.title @body = { :comment => comment, :info_request => info_request, :url => main_url(comment_url(comment)) } @@ -172,7 +172,7 @@ class RequestMailer < ApplicationMailer @from = contact_from_name_and_email headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # not much we can do if the user's email is broken 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 - 'X-Auto-Response-Suppress' => 'OOF' # http://social.technet.microsoft.com/forums/en-US/exchangesvrdevelopment/thread/7e4af3fb-4ceb-4df6-9ed3-665ccdd157d2#fe60eeb3-b0ab-4443-9e54-3da490f25cbf + 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email @subject = "Some notes have been added to your FOI request - " + info_request.title @body = { :count => count, :info_request => info_request, :url => main_url(comment_url(earliest_unalerted_comment)) } diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index 4b7c603a7..f8bef4d61 100644 --- a/app/models/track_mailer.rb +++ b/app/models/track_mailer.rb @@ -85,7 +85,11 @@ class TrackMailer < ApplicationMailer # If we have anything to send, then send everything for the user in one mail if email_about_things.size > 0 # Send the email + + previous_locale = I18n.locale + I18n.locale = user.get_locale TrackMailer.deliver_event_digest(user, email_about_things) + I18n.locale = previous_locale end # Record that we've now sent those alerts to that user diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index 16a0dab87..b74f7dad5 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -22,6 +22,7 @@ # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # # $Id: track_thing.rb,v 1.53 2009-09-17 21:10:05 francis Exp $ +require 'set' class TrackThing < ActiveRecord::Base belongs_to :tracking_user, :class_name => 'User' @@ -67,6 +68,63 @@ class TrackThing < ActiveRecord::Base TrackThing.track_type_description(self.track_type) end + def track_query_description + # XXX this is very brittle... we should probably ask users + # simply to name their tracks when they make them? + self.track_query = self.track_query.gsub(/([()]|OR)/, "") + filters = self.track_query.scan /\b\S+:\S+\b/ + text = self.track_query + varieties = Set.new + date = "" + statuses = Set.new + for filter in filters + text = text.sub(filter, "") + if filter =~ /variety:user/ + varieties << _("users") + end + if filter =~ /variety:comment/ + varieties << _("comments") + end + if filter =~ /variety:authority/ + varieties << _("authorities") + end + if filter =~ /(variety:(sent|followup_sent|response)|latest_status)/ + varieties << _("requests") + end + if filter =~ /[0-9\/]+\.\.[0-9\/]+/ + date = _("between two dates") + end + if filter =~ /(rejected|not_held)/ + statuses << _("unsuccessful") + end + if filter =~ /(:successful|:partially_successful)/ + statuses << _("successful") + end + if filter =~ /waiting/ + statuses << _("awaiting a response") + end + end + if filters.empty? + text = self.track_query + end + descriptions = [] + if varieties.include? _("requests") + descriptions << _("requests which are {{list_of_statuses}}", :list_of_statuses => Array(statuses).join(_(' or '))) + varieties -= [_("requests")] + end + if descriptions.empty? and varieties.empty? + varieties << _("anything") + end + descriptions += Array(varieties) + text = text.strip + descriptions = descriptions.join(_(" or ")) + if !text.empty? + descriptions += _("{{list_of_things}} matching text '{{search_query}}'", :list_of_things => "", :search_query => text) + end + return descriptions + end + + def TrackThing.create_track_for_request(info_request) track_thing = TrackThing.new track_thing.track_type = 'request_updates' @@ -105,10 +163,25 @@ class TrackThing < ActiveRecord::Base return track_thing end - def TrackThing.create_track_for_search_query(query) + def TrackThing.create_track_for_search_query(query, variety_postfix = nil) track_thing = TrackThing.new track_thing.track_type = 'search_query' + if !(query =~ /variety:/) + case variety_postfix + when "requests" + query += " variety:sent" + when "users" + query += " variety:user" + when "authorities" + query += " variety:authority" + end + end track_thing.track_query = query + # XXX should extract requested_by:, request:, requested_from: + # and stick their values into the respective relations. + # Should also update "params" to make the list_description + # nicer and more generic. It will need to do some clever + # parsing of the query to do this nicely return track_thing end @@ -119,16 +192,16 @@ class TrackThing < ActiveRecord::Base if self.track_type == 'request_updates' @params = { # Website - :list_description => "'<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>', a request", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :list_description => _("'{{link_to_request}}', a request", :link_to_request => "<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how :verb_on_page => _("Track this request by email"), :verb_on_page_already => _("You are already tracking this request by email"), # Email - :title_in_email => "New updates for the request '" + self.info_request.title + "'", - :title_in_rss => "New updates for the request '" + self.info_request.title + "'", + :title_in_email => _("New updates for the request '{{request_title}}'", :request_title => self.info_request.title), + :title_in_rss => _("New updates for the request '{{request_title}}'", :request_title => self.info_request.title), # Authentication - :web => "To follow updates to the request '" + CGI.escapeHTML(self.info_request.title) + "'", - :email => "Then you will be emailed whenever the request '" + CGI.escapeHTML(self.info_request.title) + "' is updated.", - :email_subject => "Confirm you want to follow updates to the request '" + self.info_request.title + "'", + :web => _("To follow updates to the request '{{request_title}}'", :request_title => CGI.escapeHTML(self.info_request.title)), + :email => _("Then you will be emailed whenever the request '{{request_title}}' is updated.", :request_title => CGI.escapeHTML(self.info_request.title)), + :email_subject => _("Confirm you want to follow updates to the request '{{request_title}}'", :request_title => self.info_request.title), # RSS sorting :feed_sortby => 'newest' } @@ -170,7 +243,7 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'public_body_updates' @params = { # Website - :list_description => "'<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>', a public authority", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :list_description => _("'{{link_to_authority}}', a public authority", :link_to_authority => "<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how :verb_on_page => _("Track requests to {{public_body_name}} by email",:public_body_name=>CGI.escapeHTML(self.public_body.name)), :verb_on_page_already => _("You are already tracking requests to {{public_body_name}} by email", :public_body_name=>CGI.escapeHTML(self.public_body.name)), # Email @@ -186,7 +259,7 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'user_updates' @params = { # Website - :list_description => "'<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>', a person", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :list_description => _("'{{link_to_user}}', a person", :link_to_user => "<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how :verb_on_page => _("Track this person by email"), :verb_on_page_already => _("You are already tracking this person by email"), # Email @@ -202,16 +275,16 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'search_query' @params = { # Website - :list_description => "'<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest\">" + CGI.escapeHTML(self.track_query) + "</a>' in new requests/responses", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how - :verb_on_page => _("Track things matching '{{query}}' by email", :query=>CGI.escapeHTML(self.track_query)), - :verb_on_page_already => _("You are already tracking things matching '{{query}}' by email", :query=>CGI.escapeHTML(self.track_query)), + :list_description => "<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest/advanced\">" + self.track_query_description + "</a>", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :verb_on_page => _("Track things matching this search by email"), + :verb_on_page_already => _("You are already tracking things matching this search by email"), # Email - :title_in_email => _("Requests or responses matching '{{query}}'", :query=>self.track_query), - :title_in_rss => _("Requests or responses matching '{{query}}'", :query=>self.track_query), + :title_in_email => _("Requests or responses matching your saved search"), + :title_in_rss => _("Requests or responses matching your saved search"), # Authentication - :web => _("To follow requests and responses matching '{{query}}'", :query=>CGI.escapeHTML(self.track_query)), - :email => _("Then you will be emailed whenever a new request or response matches '{{query}}'.", :query=>CGI.escapeHTML(self.track_query)), - :email_subject => _("Confirm you want to be emailed about new requests or responses matching '{{query}}'", :query=>self.track_query), + :web => _("To follow requests and responses matching your search"), + :email => _("Then you will be emailed whenever a new request or response matches your search."), + :email_subject => _("Confirm you want to be emailed about new requests or responses matching your search"), # RSS sorting - XXX hmmm, we don't really know which to use # here for sorting. Might be a query term (e.g. 'cctv'), in # which case newest is good, or might be something like diff --git a/app/models/user.rb b/app/models/user.rb index fddb6b035..c3c3da6f7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -96,6 +96,15 @@ class User < ActiveRecord::Base end end end + + def get_locale + if !self.locale.nil? + locale = self.locale + else + locale = I18n.locale + end + return locale.to_s + end def visible_comments self.comments.find(:all, :conditions => 'visible') diff --git a/app/models/user_mailer.rb b/app/models/user_mailer.rb index 0972e167d..7adf5b63c 100644 --- a/app/models/user_mailer.rb +++ b/app/models/user_mailer.rb @@ -46,7 +46,5 @@ class UserMailer < ApplicationMailer @body[:old_email] = old_email @body[:new_email] = new_email end - - end |