diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/application_mailer.rb | 2 | ||||
-rw-r--r-- | app/models/change_email_validator.rb | 2 | ||||
-rw-r--r-- | app/models/contact_mailer.rb | 4 | ||||
-rw-r--r-- | app/models/exim_log.rb | 4 | ||||
-rw-r--r-- | app/models/foi_attachment.rb | 20 | ||||
-rw-r--r-- | app/models/holiday.rb | 4 | ||||
-rw-r--r-- | app/models/incoming_message.rb | 62 | ||||
-rw-r--r-- | app/models/info_request.rb | 68 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 56 | ||||
-rw-r--r-- | app/models/outgoing_mailer.rb | 6 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 14 | ||||
-rw-r--r-- | app/models/post_redirect.rb | 2 | ||||
-rw-r--r-- | app/models/profile_photo.rb | 10 | ||||
-rw-r--r-- | app/models/public_body.rb | 48 | ||||
-rw-r--r-- | app/models/raw_email.rb | 4 | ||||
-rw-r--r-- | app/models/request_mailer.rb | 28 | ||||
-rw-r--r-- | app/models/track_mailer.rb | 8 | ||||
-rw-r--r-- | app/models/track_thing.rb | 22 | ||||
-rw-r--r-- | app/models/user.rb | 52 | ||||
-rw-r--r-- | app/models/user_info_request_sent_alert.rb | 2 |
20 files changed, 209 insertions, 209 deletions
diff --git a/app/models/application_mailer.rb b/app/models/application_mailer.rb index e9f82a2c3..80f0d7289 100644 --- a/app/models/application_mailer.rb +++ b/app/models/application_mailer.rb @@ -28,7 +28,7 @@ class ApplicationMailer < ActionMailer::Base # views (for links) and mailers (for use in emails), so include them into # all of all. include LinkToHelper - + # Site-wide access to configuration settings include ConfigHelper end diff --git a/app/models/change_email_validator.rb b/app/models/change_email_validator.rb index e3f8fa892..80db96c64 100644 --- a/app/models/change_email_validator.rb +++ b/app/models/change_email_validator.rb @@ -30,7 +30,7 @@ class ChangeEmailValidator < ActiveRecord::BaseWithoutTable validates_presence_of :old_email, :message => N_("Please enter your old email address") validates_presence_of :new_email, :message => N_("Please enter your new email address") validates_presence_of :password, :message => N_("Please enter your password"), :unless => :changing_email - + def changing_email() self.user_circumstance == 'change_email' end diff --git a/app/models/contact_mailer.rb b/app/models/contact_mailer.rb index 0390fc347..74c213c7a 100644 --- a/app/models/contact_mailer.rb +++ b/app/models/contact_mailer.rb @@ -25,7 +25,7 @@ class ContactMailer < ApplicationMailer # they shouldn't, and this might help. (Have had mysterious cases of a # reply coming in duplicate from a public body to both From and envelope # from) - + # Send message to another user def user_message(from_user, recipient_user, from_user_url, subject, message) @from = from_user.name_and_email @@ -34,7 +34,7 @@ class ContactMailer < ApplicationMailer headers 'Return-Path' => blackhole_email, 'Reply-To' => @from @recipients = recipient_user.name_and_email @subject = subject - @body = { + @body = { :message => message, :from_user => from_user, :recipient_user => recipient_user, diff --git a/app/models/exim_log.rb b/app/models/exim_log.rb index 77e5e2d21..2c6bea4f8 100644 --- a/app/models/exim_log.rb +++ b/app/models/exim_log.rb @@ -40,7 +40,7 @@ class EximLog < ActiveRecord::Base ActiveRecord::Base.transaction do # see if we already have it - done = EximLogDone.find_by_filename(file_name_db) + done = EximLogDone.find_by_filename(file_name_db) if !done.nil? if modified.utc == done.last_stat.utc # already have that, nothing to do @@ -124,7 +124,7 @@ class EximLog < ActiveRecord::Base return ok end - + end diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb index da92d1c2d..1906b56db 100644 --- a/app/models/foi_attachment.rb +++ b/app/models/foi_attachment.rb @@ -177,7 +177,7 @@ class FoiAttachment < ActiveRecord::Base filename = filename.gsub(/\//, "-") return filename - end + end # XXX changing this will break existing URLs, so have a care - maybe # make another old_display_filename see above @@ -248,16 +248,16 @@ class FoiAttachment < ActiveRecord::Base return !! { "application/pdf" => true, # .pdf "image/tiff" => true, # .tiff - + "application/vnd.ms-word" => true, # .doc "application/vnd.openxmlformats-officedocument.wordprocessingml.document" => true, # .docx - + "application/vnd.ms-powerpoint" => true, # .ppt "application/vnd.openxmlformats-officedocument.presentationml.presentation" => true, # .pptx - + "application/vnd.ms-excel" => true, # .xls "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => true, # .xlsx - + } [self.content_type] end @@ -277,16 +277,16 @@ class FoiAttachment < ActiveRecord::Base return { "text/plain" => "Text file", 'application/rtf' => "RTF file", - + 'application/pdf' => "PDF file", 'image/tiff' => "TIFF image", - + 'application/vnd.ms-word' => "Word document", 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => "Word document", - + 'application/vnd.ms-powerpoint' => "PowerPoint presentation", 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => "PowerPoint presentation", - + 'application/vnd.ms-excel' => "Excel spreadsheet", 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => "Excel spreadsheet", }[self.content_type] @@ -345,7 +345,7 @@ class FoiAttachment < ActiveRecord::Base if self.has_google_docs_viewer? wrapper_id = "wrapper_google_embed" ret = ret + "<iframe src='http://docs.google.com/viewer?url=<attachment-url-here>&embedded=true' width='100%' height='100%' style='border: none;'></iframe>"; - else + else ret = ret + "<p>Sorry, we were unable to convert this file to HTML. Please use the download link at the top right.</p>" end ret = ret + "</body></html>" diff --git a/app/models/holiday.rb b/app/models/holiday.rb index 60b5ff443..1fa599c13 100644 --- a/app/models/holiday.rb +++ b/app/models/holiday.rb @@ -10,7 +10,7 @@ # models/holiday.rb: # -# Store details on, and perform calculations with, public holidays on which +# Store details on, and perform calculations with, public holidays on which # the clock for answering FOI requests does not run: # # ... "working day" means any day other than a Saturday, a Sunday, Christmas @@ -37,7 +37,7 @@ class Holiday < ActiveRecord::Base # Count forward (20) working days. We start with today as "day zero". The # first of the twenty full working days is the next day. We return the # date of the last of the twenty. - + # This response for example of a public authority complains that we had # it wrong. We didn't (even thought I changed the code for a while, # it's changed back now). A day is a day, our lawyer tells us. diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 2896de68a..8de6e5ba8 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -81,7 +81,7 @@ class IncomingMessage < ActiveRecord::Base # http://www.whatdotheyknow.com/request/reviews_of_unduly_lenient_senten#incoming-4830 # Report of TMail bug: # http://rubyforge.org/tracker/index.php?func=detail&aid=21810&group_id=4512&atid=17370 - copy_of_raw_data = self.raw_email.data.gsub(/; boundary=\s+"/ims,'; boundary="') + copy_of_raw_data = self.raw_email.data.gsub(/; boundary=\s+"/ims,'; boundary="') @mail = TMail::Mail.parse(copy_of_raw_data) @mail.base64_decode @@ -92,7 +92,7 @@ class IncomingMessage < ActiveRecord::Base # Returns the name of the person the incoming message is from, or nil if # there isn't one or if there is only an email address. XXX can probably # remove from_name_if_present (which is a monkey patch) by just calling - # .from_addrs[0].name here instead? + # .from_addrs[0].name here instead? # Return false if for some reason this is a message that we shouldn't let them reply to def _calculate_valid_to_reply_to @@ -178,7 +178,7 @@ class IncomingMessage < ActiveRecord::Base def safe_mail_from if !self.mail_from.nil? mail_from = self.mail_from.dup - self.info_request.apply_censor_rules_to_text!(mail_from) + self.info_request.apply_censor_rules_to_text!(mail_from) return mail_from end end @@ -191,7 +191,7 @@ class IncomingMessage < ActiveRecord::Base # XXX This fills in part.rfc822_attachment and part.url_part_number within # all the parts of the email (see TMail monkeypatch above for how these # attributes are added). ensure_parts_counted must be called before using - # the attributes. + # the attributes. def ensure_parts_counted @count_parts_count = 0 _count_parts_recursive(self.mail) @@ -215,7 +215,7 @@ class IncomingMessage < ActiveRecord::Base # e.g. http://www.whatdotheyknow.com/request/chinese_names_for_british_politi msg = Mapi::Msg.open(StringIO.new(part.body)) part.rfc822_attachment = TMail::Mail.parse(msg.to_mime.to_s) - elsif part.content_type == 'application/ms-tnef' + elsif part.content_type == 'application/ms-tnef' # A set of attachments in a TNEF file part.rfc822_attachment = TNEF.as_tmail(part.body) end @@ -289,7 +289,7 @@ class IncomingMessage < ActiveRecord::Base # buggy versions of pdftk sometimes fail on # compression, I don't see it's a disaster in # these cases to save an uncompressed version? - recompressed_text = censored_uncompressed_text + recompressed_text = censored_uncompressed_text logger.warn "Unable to compress PDF; problem with your pdftk version?" end if !recompressed_text.nil? && !recompressed_text.empty? @@ -297,10 +297,10 @@ class IncomingMessage < ActiveRecord::Base end end end - return + return end - self._binary_mask_stuff_internal!(text) + self._binary_mask_stuff_internal!(text) end # Used by binary_mask_stuff - replace text in place @@ -309,7 +309,7 @@ class IncomingMessage < ActiveRecord::Base orig_size = text.size # Replace ASCII email addresses... - text.gsub!(MySociety::Validate.email_find_regexp) do |email| + text.gsub!(MySociety::Validate.email_find_regexp) do |email| email.gsub(/[^@.]/, 'x') end @@ -320,7 +320,7 @@ class IncomingMessage < ActiveRecord::Base emails = ascii_chars.scan(MySociety::Validate.email_find_regexp) # Convert back to UCS-2, making a mask at the same time emails.map! {|email| [ - Iconv.conv('ucs-2le', 'ascii', email[0]), + Iconv.conv('ucs-2le', 'ascii', email[0]), Iconv.conv('ucs-2le', 'ascii', email[0].gsub(/[^@.]/, 'x')) ] } # Now search and replace the UCS-2 email with the UCS-2 mask @@ -416,7 +416,7 @@ class IncomingMessage < ActiveRecord::Base # http://www.whatdotheyknow.com/request/secured_convictions_aided_by_cct multiline_original_message = '(' + '''>>>.* \d\d/\d\d/\d\d\d\d\s+\d\d:\d\d(?::\d\d)?\s*>>>''' + ')' text.gsub!(/^(#{multiline_original_message}\n.*)$/ms, replacement) - + # Single line sections text.gsub!(/^(>.*\n)/, replacement) text.gsub!(/^(On .+ (wrote|said):\n)/, replacement) @@ -453,8 +453,8 @@ class IncomingMessage < ActiveRecord::Base # http://www.whatdotheyknow.com/request/123/response/192 # http://www.whatdotheyknow.com/request/235/response/513 # http://www.whatdotheyknow.com/request/445/response/743 - original_message = - '(' + '''----* This is a copy of the message, including all the headers. ----*''' + + original_message = + '(' + '''----* This is a copy of the message, including all the headers. ----*''' + '|' + '''----*\s*Original Message\s*----*''' + '|' + '''----*\s*Forwarded message.+----*''' + '|' + '''----*\s*Forwarded by.+----*''' + @@ -482,7 +482,7 @@ class IncomingMessage < ActiveRecord::Base return part_file_name end - # (This risks losing info if the unchosen alternative is the only one to contain + # (This risks losing info if the unchosen alternative is the only one to contain # useful info, but let's worry about that another time) def get_attachment_leaves force = true @@ -538,7 +538,7 @@ class IncomingMessage < ActiveRecord::Base if calc_mime curr_mail.content_type = calc_mime end - end + end # Use standard content types for Word documents etc. curr_mail.content_type = normalise_content_type(curr_mail.content_type) @@ -660,11 +660,11 @@ class IncomingMessage < ActiveRecord::Base # Test if it's good UTF-8 text = Iconv.conv('utf-8', 'utf-8', text) rescue Iconv::IllegalSequence - # Text looks like unlabelled nonsense, + # Text looks like unlabelled nonsense, # strip out anything that isn't UTF-8 begin - text = Iconv.conv('utf-8//IGNORE', source_charset, text) + - _("\n\n[ {{site_name}} note: The above text was badly encoded, and has had strange characters removed. ]", + text = Iconv.conv('utf-8//IGNORE', source_charset, text) + + _("\n\n[ {{site_name}} note: The above text was badly encoded, and has had strange characters removed. ]", :site_name => MySociety::Config.get('SITE_NAME', 'Alaveteli')) rescue Iconv::InvalidEncoding, Iconv::IllegalSequence if source_charset != "utf-8" @@ -673,7 +673,7 @@ class IncomingMessage < ActiveRecord::Base end end end - + # Fix DOS style linefeeds to Unix style ones (or other later regexps won't work) # Needed for e.g. http://www.whatdotheyknow.com/request/60/response/98 @@ -693,7 +693,7 @@ class IncomingMessage < ActiveRecord::Base # Find first part which is text/plain or text/html # (We have to include HTML, as increasingly there are mail clients that # include no text alternative for the main part, and we don't want to - # instead use the first text attachment + # instead use the first text attachment # e.g. http://www.whatdotheyknow.com/request/list_of_public_authorties) leaves.each do |p| if p.content_type == 'text/plain' or p.content_type == 'text/html' @@ -707,8 +707,8 @@ class IncomingMessage < ActiveRecord::Base return p end end - - # ... or if none, consider first part + + # ... or if none, consider first part p = leaves[0] # if it is a known type then don't use it, return no body (nil) if !p.nil? && AlaveteliFileTypes.mimetype_to_extension(p.content_type) @@ -752,7 +752,7 @@ class IncomingMessage < ActiveRecord::Base :display_size => "0K") attachment.save! attachments << attachment - end + end return attachments end @@ -802,7 +802,7 @@ class IncomingMessage < ActiveRecord::Base # XXX call _convert_part_body_to_text here, but need to get charset somehow # e.g. http://www.whatdotheyknow.com/request/1593/response/3088/attach/4/Freedom%20of%20Information%20request%20-%20car%20oval%20sticker:%20Article%2020,%20Convention%20on%20Road%20Traffic%201949.txt body = headers + "\n" + body - + # This is quick way of getting all headers, but instead we only add some a) to # make it more usable, b) as at least one authority accidentally leaked security # information into a header. @@ -836,7 +836,7 @@ class IncomingMessage < ActiveRecord::Base end # now get rid of any attachments we no longer have - FoiAttachment.destroy_all("id NOT IN (#{attachments.join(',')}) AND incoming_message_id = #{self.id}") + FoiAttachment.destroy_all("id NOT IN (#{attachments.join(',')}) AND incoming_message_id = #{self.id}") end # Returns body text as HTML with quotes flattened, and emails removed. @@ -898,13 +898,13 @@ class IncomingMessage < ActiveRecord::Base self.remove_privacy_sensitive_things!(text) # This can be useful for memory debugging #STDOUT.puts 'xxx '+ MySociety::DebugHelpers::allocated_string_size_around_gc - + # Save clipped version for snippets if self.cached_attachment_text_clipped.nil? self.cached_attachment_text_clipped = text[0..MAX_ATTACHMENT_TEXT_CLIPPED] self.save! end - + return text end # Returns a version reduced to a sensible maximum size - this @@ -987,7 +987,7 @@ class IncomingMessage < ActiveRecord::Base for entry in zip_file if entry.file? filename = entry.to_s - begin + begin body = entry.get_input_stream.read rescue # move to next attachment silently if there were problems @@ -1001,7 +1001,7 @@ class IncomingMessage < ActiveRecord::Base else content_type = 'application/octet-stream' end - + text += _get_attachment_text_internal_one_file(content_type, body) end end @@ -1051,7 +1051,7 @@ class IncomingMessage < ActiveRecord::Base end end - # Search all info requests for + # Search all info requests for def IncomingMessage.find_all_unknown_mime_types for incoming_message in IncomingMessage.find(:all) for attachment in incoming_message.get_attachments_for_display @@ -1117,7 +1117,7 @@ class IncomingMessage < ActiveRecord::Base content_type = 'application/vnd.ms-excel' end if content_type == 'application/mspowerpoint' or content_type == 'application/x-ms-powerpoint' - content_type = 'application/vnd.ms-powerpoint' + content_type = 'application/vnd.ms-powerpoint' end if content_type == 'application/msword' or content_type == 'application/x-ms-word' content_type = 'application/vnd.ms-word' diff --git a/app/models/info_request.rb b/app/models/info_request.rb index e570150bb..3b86f4cb3 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -51,14 +51,14 @@ class InfoRequest < ActiveRecord::Base # user described state (also update in info_request_event, admin_request/edit.rhtml) validate :must_be_valid_state - validates_inclusion_of :prominence, :in => [ - 'normal', + validates_inclusion_of :prominence, :in => [ + 'normal', 'backpage', 'hidden', 'requester_only' ] - validates_inclusion_of :law_used, :in => [ + validates_inclusion_of :law_used, :in => [ 'foi', # Freedom of Information Act 'eir', # Environmental Information Regulations ] @@ -77,13 +77,13 @@ class InfoRequest < ActiveRecord::Base ] def self.enumerate_states - states = [ + states = [ 'waiting_response', - 'waiting_clarification', + 'waiting_clarification', 'gone_postal', 'not_held', 'rejected', # this is called 'refused' in UK FOI law and the user interface, but 'rejected' internally for historic reasons - 'successful', + 'successful', 'partially_successful', 'internal_review', 'error_message', @@ -97,7 +97,7 @@ class InfoRequest < ActiveRecord::Base end def must_be_valid_state - errors.add(:described_state, "is not a valid state") if + errors.add(:described_state, "is not a valid state") if !InfoRequest.enumerate_states.include? described_state end @@ -123,7 +123,7 @@ class InfoRequest < ActiveRecord::Base 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 - + OLD_AGE_IN_DAYS = 21.days def after_initialize @@ -169,7 +169,7 @@ class InfoRequest < ActiveRecord::Base end end # Force reindex when tag string changes - alias_method :orig_tag_string=, :tag_string= + alias_method :orig_tag_string=, :tag_string= def tag_string=(tag_string) ret = self.orig_tag_string=(tag_string) reindex_request_events @@ -222,7 +222,7 @@ public end # Email which public body should use to respond to request. This is in - # the format PREFIXrequest-ID-HASH@DOMAIN. Here ID is the id of the + # the format PREFIXrequest-ID-HASH@DOMAIN. Here ID is the id of the # FOI request, and HASH is a signature for that id. def incoming_email return self.magic_email("request-") @@ -254,7 +254,7 @@ public end end - # Two sorts of laws for requests, FOI or EIR + # Two sorts of laws for requests, FOI or EIR def law_used_full if self.law_used == 'foi' return _("Freedom of Information") @@ -309,7 +309,7 @@ public guesses = [] # 1. Try to guess based on the email address(es) addresses = - (incoming_message.mail.to || []) + + (incoming_message.mail.to || []) + (incoming_message.mail.cc || []) + (incoming_message.mail.envelope_to || []) addresses.uniq! @@ -541,7 +541,7 @@ public self.base_calculate_status end end - + def base_calculate_status return 'waiting_classification' if self.awaiting_description return described_state unless self.described_state == "waiting_response" @@ -561,13 +561,13 @@ public 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 curr_state.nil? if !event.described_state.nil? curr_state = event.described_state end end - if !curr_state.nil? && event.event_type == 'response' + if !curr_state.nil? && event.event_type == 'response' if event.calculated_state != curr_state event.calculated_state = curr_state event.last_described_at = Time.now() @@ -581,7 +581,7 @@ public elsif !curr_state.nil? && (event.event_type == 'followup_sent' || event.event_type == 'sent') && !event.described_state.nil? && (event.described_state == 'waiting_response' || event.described_state == 'internal_review') # Followups can set the status to waiting response / internal # review. Initial requests ('sent') set the status to waiting response. - + # We want to store that in calculated_state state so it gets # indexed. if event.calculated_state != event.described_state @@ -725,8 +725,8 @@ public def index_of_last_described_event events = self.info_request_events events.each_index do |i| - revi = events.size - 1 - i - m = events[revi] + revi = events.size - 1 - i + m = events[revi] if not m.described_state.nil? return revi end @@ -737,7 +737,7 @@ public def last_event_id_needing_description last_event = events_needing_description[-1] last_event.nil? ? 0 : last_event.id - end + end # Returns all the events which the user hasn't described yet - an empty array if all described. def events_needing_description @@ -825,11 +825,11 @@ public track_thing.destroy end self.user_info_request_sent_alerts.each { |a| a.destroy } - self.info_request_events.each do |info_request_event| + self.info_request_events.each do |info_request_event| info_request_event.track_things_sent_emails.each { |a| a.destroy } info_request_event.destroy end - self.exim_logs.each do |exim_log| + self.exim_logs.each do |exim_log| exim_log.destroy end self.outgoing_messages.each { |a| a.destroy } @@ -844,8 +844,8 @@ public return InfoRequest.magic_email_for_id(prefix_part, self.id) end - def InfoRequest.magic_email_for_id(prefix_part, id) - magic_email = MySociety::Config.get("INCOMING_EMAIL_PREFIX", "") + def InfoRequest.magic_email_for_id(prefix_part, id) + magic_email = MySociety::Config.get("INCOMING_EMAIL_PREFIX", "") magic_email += prefix_part + id.to_s magic_email += "-" + InfoRequest.hash_from_id(id) magic_email += "@" + MySociety::Config.get("INCOMING_EMAIL_DOMAIN", "localhost") @@ -890,14 +890,14 @@ public def InfoRequest.find_old_unclassified(extra_params={}) last_response_created_at = last_event_time_clause('response') age = extra_params[:age_in_days] ? extra_params[:age_in_days].days : OLD_AGE_IN_DAYS - params = {:select => "*, #{last_response_created_at} as last_response_time", - :conditions => ["awaiting_description = ? and #{last_response_created_at} < ? and url_title != 'holding_pen'", - true, Time.now() - age], + params = {:select => "*, #{last_response_created_at} as last_response_time", + :conditions => ["awaiting_description = ? and #{last_response_created_at} < ? and url_title != 'holding_pen'", + true, Time.now() - age], :order => "last_response_time"} params[:limit] = extra_params[:limit] if extra_params[:limit] params[:include] = extra_params[:include] if extra_params[:include] if extra_params[:order] - params[:order] = extra_params[:order] + params[:order] = extra_params[:order] params.delete(:select) end if extra_params[:conditions] @@ -907,7 +907,7 @@ public end find(:all, params) end - + def is_old_unclassified? return false if !awaiting_description return false if url_title == 'holding_pen' @@ -926,7 +926,7 @@ public next end incoming_message.safe_mail_from - + email = OutgoingMailer.email_for_followup(self, incoming_message) name = OutgoingMailer.name_for_followup(self, incoming_message) @@ -955,7 +955,7 @@ public end end end - + def apply_censor_rules_to_binary!(binary) for censor_rule in self.censor_rules censor_rule.apply_to_binary!(binary) @@ -966,7 +966,7 @@ public end end end - + def is_owning_user?(user) !user.nil? && (user.id == user_id || user.owns_every_request?) end @@ -975,10 +975,10 @@ public end def user_can_view?(user) - if self.prominence == 'hidden' + if self.prominence == 'hidden' return User.view_hidden_requests?(user) end - if self.prominence == 'requester_only' + if self.prominence == 'requester_only' return self.is_owning_user?(user) end return true @@ -1019,7 +1019,7 @@ public end def json_for_api(deep) - ret = { + ret = { :id => self.id, :url_title => self.url_title, :title => self.title, diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index cb49596cb..9ce191f6b 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -36,7 +36,7 @@ class InfoRequestEvent < ActiveRecord::Base has_many :track_things_sent_emails validates_presence_of :event_type - + def self.enumerate_event_types [ 'sent', @@ -64,27 +64,27 @@ class InfoRequestEvent < ActiveRecord::Base validate :must_be_valid_state # whether event is publicly visible - validates_inclusion_of :prominence, :in => [ - 'normal', + validates_inclusion_of :prominence, :in => [ + 'normal', 'hidden', 'requester_only' ] def must_be_valid_state if !described_state.nil? and !InfoRequest.enumerate_states.include?(described_state) - errors.add(described_state, "is not a valid state") + errors.add(described_state, "is not a valid state") end end - + def user_can_view?(user) if !self.info_request.user_can_view?(user) raise "internal error, called user_can_view? on event when there is not permission to view entire request" end - if self.prominence == 'hidden' + if self.prominence == 'hidden' return User.view_hidden_requests?(user) end - if self.prominence == 'requester_only' + if self.prominence == 'requester_only' return self.info_request.is_owning_user?(user) end return true @@ -93,7 +93,7 @@ class InfoRequestEvent < ActiveRecord::Base # Full text search indexing acts_as_xapian :texts => [ :search_text_main, :title ], - :values => [ + :values => [ [ :created_at, 0, "range_search", :date ], # for QueryParser range searches e.g. 01/01/2008..14/01/2008 [ :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 @@ -110,7 +110,7 @@ class InfoRequestEvent < ActiveRecord::Base [ :latest_status, 'L', "latest_status" ], [ :waiting_classification, 'W', "waiting_classification" ], [ :filetype, 'T', "filetype" ], - [ :tags, 'U', "tag" ] + [ :tags, 'U', "tag" ] ], :if => :indexed_by_search?, :eager_load => [ :outgoing_message, :comment, { :info_request => [ :user, :public_body, :censor_rules ] } ] @@ -119,7 +119,7 @@ class InfoRequestEvent < ActiveRecord::Base self.info_request.user.url_name end def requested_from - # acts_as_xapian will detect translated fields via Globalize and add all the + # acts_as_xapian will detect translated fields via Globalize and add all the # available locales to the index. But 'requested_from' is not translated directly, # although it relies on a translated field in PublicBody. Hence, we need to # manually add all the localized values to the index (Xapian can handle a list @@ -174,15 +174,15 @@ class InfoRequestEvent < ActiveRecord::Base end def described_at_numeric # format it here as no datetime support in Xapian's value ranges - return self.described_at.strftime("%Y%m%d%H%M%S") + return self.described_at.strftime("%Y%m%d%H%M%S") end def created_at_numeric # format it here as no datetime support in Xapian's value ranges - return self.created_at.strftime("%Y%m%d%H%M%S") + return self.created_at.strftime("%Y%m%d%H%M%S") end - + def incoming_message_selective_columns(fields) - message = IncomingMessage.find(:all, + message = IncomingMessage.find(:all, :select => fields + ", incoming_messages.info_request_id", :joins => "INNER JOIN info_request_events ON incoming_messages.id = incoming_message_id ", :conditions => "info_request_events.id = #{self.id}" @@ -218,7 +218,7 @@ class InfoRequestEvent < ActiveRecord::Base # performance reasons. Xapian will take the full text. def search_text_main(clipped = false) text = '' - if self.event_type == 'sent' + if self.event_type == 'sent' text = text + self.outgoing_message.get_text_for_indexing + "\n\n" elsif self.event_type == 'followup_sent' text = text + self.outgoing_message.get_text_for_indexing + "\n\n" @@ -236,7 +236,7 @@ class InfoRequestEvent < ActiveRecord::Base return text end def title - if self.event_type == 'sent' + if self.event_type == 'sent' return self.info_request.title end return '' @@ -317,26 +317,26 @@ class InfoRequestEvent < ActiveRecord::Base old_value = old_params[key].to_s new_value = new_params[key].to_s if old_value != new_value - ret = ret + "<em>" + CGI.escapeHTML(key) + ":</em> " - ret = ret + - CGI.escapeHTML(MySociety::Format.wrap_email_body_by_lines(old_value).strip).gsub(/\n/, '<br>') + - " => " + + ret = ret + "<em>" + CGI.escapeHTML(key) + ":</em> " + ret = ret + + CGI.escapeHTML(MySociety::Format.wrap_email_body_by_lines(old_value).strip).gsub(/\n/, '<br>') + + " => " + CGI.escapeHTML(MySociety::Format.wrap_email_body_by_lines(new_value).strip).gsub(/\n/, '<br>') ret = ret + "<br>" end end for key, value in other_params - ret = ret + "<em>" + CGI.escapeHTML(key.to_s) + ":</em> " - ret = ret + CGI.escapeHTML(value.to_s.strip) + ret = ret + "<em>" + CGI.escapeHTML(key.to_s) + ":</em> " + ret = ret + CGI.escapeHTML(value.to_s.strip) ret = ret + "<br>" end return ret end - - def is_incoming_message?() not self.incoming_message_selective_columns("incoming_messages.id").nil? end - def is_outgoing_message?() not self.outgoing_message.nil? end - def is_comment?() not self.comment.nil? end + + def is_incoming_message?() not self.incoming_message_selective_columns("incoming_messages.id").nil? end + def is_outgoing_message?() not self.outgoing_message.nil? end + def is_comment?() not self.comment.nil? end # Display version of status def display_status @@ -406,7 +406,7 @@ class InfoRequestEvent < ActiveRecord::Base end def json_for_api(deep, snippet_highlight_proc = nil) - ret = { + ret = { :id => self.id, :event_type => self.event_type, # params_yaml has possibly sensitive data in it, don't include it @@ -431,7 +431,7 @@ class InfoRequestEvent < ActiveRecord::Base ret[:snippet] = snippet_highlight_proc.call(self.search_text_main(true)) end - if deep + if deep ret[:info_request] = self.info_request.json_for_api(false) ret[:public_body] = self.info_request.public_body.json_for_api ret[:user] = self.info_request.user.json_for_api diff --git a/app/models/outgoing_mailer.rb b/app/models/outgoing_mailer.rb index bf81bb89f..8562c5b68 100644 --- a/app/models/outgoing_mailer.rb +++ b/app/models/outgoing_mailer.rb @@ -10,12 +10,12 @@ # separated) paragraphs, as is the convention for all the other mailers. This # turned out to fit better with user exepectations when formatting messages. # -# XXX The other mail templates are written to use blank line separated +# XXX The other mail templates are written to use blank line separated # paragraphs. They could be rewritten, and the wrapping method made uniform # throughout the application. class OutgoingMailer < ApplicationMailer - + # Email to public body requesting info def initial_request(info_request, outgoing_message) @wrap_lines_as_paragraphs = true @@ -96,4 +96,4 @@ class OutgoingMailer < ApplicationMailer end end - + diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index de3c916aa..29445d587 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -37,7 +37,7 @@ class OutgoingMessage < ActiveRecord::Base # can have many events, for items which were resent by site admin e.g. if # contact address changed - has_many :info_request_events + has_many :info_request_events # To override the default letter attr_accessor :default_letter @@ -45,7 +45,7 @@ class OutgoingMessage < ActiveRecord::Base # reindex if body text is edited (e.g. by admin interface) after_update :xapian_reindex_after_update def xapian_reindex_after_update - if self.changes.include?('body') + if self.changes.include?('body') for info_request_event in self.info_request_events info_request_event.xapian_mark_needs_index end @@ -83,11 +83,11 @@ class OutgoingMessage < ActiveRecord::Base "\n\n" + "I am writing to request an internal review of " + self.info_request.public_body.name + - "'s handling of my FOI request " + - "'" + self.info_request.title + "'." + + "'s handling of my FOI request " + + "'" + self.info_request.title + "'." + "\n\n\n\n [ " + self.get_internal_review_insert_here_note + " ] \n\n\n\n" + "A full history of my FOI request and all correspondence is available on the Internet at this address:\n" + - "http://" + MySociety::Config.get("DOMAIN", '127.0.0.1:3000') + "/request/" + self.info_request.url_title + "http://" + MySociety::Config.get("DOMAIN", '127.0.0.1:3000') + "/request/" + self.info_request.url_title else "" end @@ -98,7 +98,7 @@ class OutgoingMessage < ActiveRecord::Base def set_signature_name(name) # XXX We use raw_body here to get unstripped one if self.raw_body == self.get_default_message - self.body = self.raw_body + name + self.body = self.raw_body + name end end @@ -130,7 +130,7 @@ class OutgoingMessage < ActiveRecord::Base def contains_postcode? MySociety::Validate.contains_postcode?(self.body) end - + # Set default letter def after_initialize if self.body.nil? diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index c9a6229a4..2b636453f 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -64,7 +64,7 @@ class PostRedirect < ActiveRecord::Base MySociety::Util.generate_token end - # Make the token + # Make the token def after_initialize # The token is used to return you to what you are doing after the login form. if not self.token diff --git a/app/models/profile_photo.rb b/app/models/profile_photo.rb index 798094d90..6c66d868a 100644 --- a/app/models/profile_photo.rb +++ b/app/models/profile_photo.rb @@ -27,9 +27,9 @@ class ProfilePhoto < ActiveRecord::Base belongs_to :user # deliberately don't strip_attributes, so keeps raw photo properly - + attr_accessor :x, :y, :w, :h - + # convert binary data blob into ImageMagick image when assigned attr_accessor :image def after_initialize @@ -45,7 +45,7 @@ class ProfilePhoto < ActiveRecord::Base self.image = nil return end - + self.image = image_list[0] # XXX perhaps take largest image or somesuch if there were multiple in the file? self.convert_image end @@ -68,7 +68,7 @@ class ProfilePhoto < ActiveRecord::Base # draft images are before the user has cropped them if !self.draft && (image.columns != WIDTH || image.rows != HEIGHT) # do any exact cropping (taken from Jcrop interface) - if self.w && self.h + if self.w && self.h image.crop!(self.x.to_i, self.y.to_i, self.w.to_i, self.h.to_i) end # do any further cropping @@ -98,7 +98,7 @@ class ProfilePhoto < ActiveRecord::Base if self.image.format != 'PNG' errors.add(:data, N_("Failed to convert image to a PNG")) end - + if !self.draft && (self.image.columns != WIDTH || self.image.rows != HEIGHT) errors.add(:data, N_("Failed to convert image to the correct size: at %{cols}x%{rows}, need %{width}x%{height}" % { :cols => self.image.columns, :rows => self.image.rows, :width => WIDTH, :height => HEIGHT })) end diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 54af547bd..0e21037ef 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -58,11 +58,11 @@ class PublicBody < ActiveRecord::Base short_long_name = t.short_name if t.short_name and !t.short_name.empty? t.url_name = MySociety::Format.simplify_url_part(short_long_name, 'body') end - + def translated_versions translations end - + def translated_versions=(translation_attrs) def skip?(attrs) valueless = attrs.inject({}) { |h, (k, v)| h[k] = v if v != '' and k != 'locale'; h } # because we want to fall back to alternative translations where there are empty values @@ -86,7 +86,7 @@ class PublicBody < ActiveRecord::Base end end end - + # Make sure publication_scheme gets the correct default value. # (This would work automatically, were publication_scheme not a translated attribute) def after_initialize @@ -96,7 +96,7 @@ class PublicBody < ActiveRecord::Base # like find_by_url_name but also search historic url_name if none found def self.find_by_url_name_with_historic(name) locale = self.locale || I18n.locale - PublicBody.with_locale(locale) do + PublicBody.with_locale(locale) do found = PublicBody.find(:all, :conditions => ["public_body_translations.url_name='#{name}'"], :joins => :translations, @@ -192,15 +192,15 @@ class PublicBody < ActiveRecord::Base end acts_as_xapian :texts => [ :name, :short_name, :notes ], - :values => [ + :values => [ [ :created_at_numeric, 1, "created_at", :number ] # for sorting ], :terms => [ [ :variety, 'V', "variety" ], - [ :tag_array_for_search, 'U', "tag" ] + [ :tag_array_for_search, 'U', "tag" ] ] def created_at_numeric # format it here as no datetime support in Xapian's value ranges - return self.created_at.strftime("%Y%m%d%H%M%S") + return self.created_at.strftime("%Y%m%d%H%M%S") end def variety return "authority" @@ -236,7 +236,7 @@ class PublicBody < ActiveRecord::Base def update_url_name self.url_name = MySociety::Format.simplify_url_part(self.short_or_long_name, 'body') end - + # Return the short name if present, or else long name def short_or_long_name if self.short_name.nil? || self.short_name.empty? # 'nil' can happen during construction @@ -253,7 +253,7 @@ class PublicBody < ActiveRecord::Base first = true for tag in self.tags if PublicBodyCategories::get().by_tag().include?(tag.name) - desc = PublicBodyCategories::get().singular_by_tag()[tag.name] + desc = PublicBodyCategories::get().singular_by_tag()[tag.name] if first # terrible that Ruby/Rails doesn't have an equivalent of ucfirst # (capitalize shockingly converts later characters to lowercase) @@ -270,7 +270,7 @@ class PublicBody < ActiveRecord::Base if types.size > 0 ret = types[0, types.size - 1].join(", ") if types.size > 1 - ret = ret + " and " + ret = ret + " and " end ret = ret + types[-1] return ret @@ -351,12 +351,12 @@ class PublicBody < ActiveRecord::Base for existing_body in bodies # Hide InternalAdminBody from import notes next if existing_body.id == PublicBody.internal_admin_body.id - + bodies_by_name[existing_body.name] = existing_body set_of_existing.add(existing_body.name) end end - + set_of_importing = Set.new() field_names = { 'name'=>1, 'request_email'=>2 } # Default values in case no field list is given line = 0 @@ -372,7 +372,7 @@ class PublicBody < ActiveRecord::Base fields = {} field_names.each{|name, i| fields[name] = row[i]} - + name = row[field_names['name']] email = row[field_names['request_email']] next if name.nil? @@ -384,7 +384,7 @@ class PublicBody < ActiveRecord::Base errors.push "error: line #{line.to_s}: invalid email '#{email}' for authority '#{name}'" next end - + field_list = ['name', 'short_name', 'request_email', 'notes', 'publication_scheme', 'home_page', 'tag_string'] if public_body = bodies_by_name[name] # Existing public body @@ -394,7 +394,7 @@ class PublicBody < ActiveRecord::Base field_list.each do |field_name| localized_field_name = (locale.to_s == I18n.default_locale.to_s) ? field_name : "#{field_name}.#{locale}" localized_value = field_names[localized_field_name] && row[field_names[localized_field_name]] - + # Tags are a special case, as we support adding to the field, not just setting a new value if localized_field_name == 'tag_string' if localized_value.nil? @@ -402,11 +402,11 @@ class PublicBody < ActiveRecord::Base else if tag_behaviour == 'add' localized_value = "#{localized_value} #{tag}" unless tag.empty? - localized_value = "#{localized_value} #{public_body.tag_string}" + localized_value = "#{localized_value} #{public_body.tag_string}" end end end - + if !localized_value.nil? and public_body.send(field_name) != localized_value changed[field_name] = "#{public_body.send(field_name)}: #{localized_value}" public_body.send("#{field_name}=", localized_value) @@ -416,14 +416,14 @@ class PublicBody < ActiveRecord::Base unless changed.empty? notes.push "line #{line.to_s}: updating authority '#{name}' (locale: #{locale}):\n\t#{changed.to_json}" public_body.last_edit_editor = editor - public_body.last_edit_comment = 'Updated from spreadsheet' + public_body.last_edit_comment = 'Updated from spreadsheet' public_body.save! end end end else # New public body public_body = PublicBody.new(:name=>"", :short_name=>"", :request_email=>"") - available_locales.each do |locale| + available_locales.each do |locale| PublicBody.with_locale(locale) do changed = ActiveSupport::OrderedHash.new field_list.each do |field_name| @@ -433,7 +433,7 @@ class PublicBody < ActiveRecord::Base if localized_field_name == 'tag_string' and tag_behaviour == 'add' localized_value = "#{localized_value} #{tag}" unless tag.empty? end - + if !localized_value.nil? and public_body.send(field_name) != localized_value changed[field_name] = localized_value public_body.send("#{field_name}=", localized_value) @@ -444,7 +444,7 @@ class PublicBody < ActiveRecord::Base notes.push "line #{line.to_s}: creating new authority '#{name}' (locale: #{locale}):\n\t#{changed.to_json}" public_body.publication_scheme = public_body.publication_scheme || "" public_body.last_edit_editor = editor - public_body.last_edit_comment = 'Created from spreadsheet' + public_body.last_edit_comment = 'Created from spreadsheet' public_body.save! end end @@ -454,7 +454,7 @@ class PublicBody < ActiveRecord::Base set_of_importing.add(name) end - # Give an error listing ones that are to be deleted + # Give an error listing ones that are to be deleted deleted_ones = set_of_existing - set_of_importing if deleted_ones.size > 0 notes.push "Notes: Some " + tag + " bodies are in database, but not in CSV file:\n " + Array(deleted_ones).sort.join("\n ") + "\nYou may want to delete them manually.\n" @@ -530,7 +530,7 @@ class PublicBody < ActiveRecord::Base end def json_for_api - return { + return { :id => self.id, :url_name => self.url_name, :name => self.name, @@ -538,7 +538,7 @@ class PublicBody < ActiveRecord::Base # :request_email # we hide this behind a captcha, to stop people doing bulk requests easily :created_at => self.created_at, :updated_at => self.updated_at, - # don't add the history as some edit comments contain sensitive information + # don't add the history as some edit comments contain sensitive information # :version, :last_edit_editor, :last_edit_comment :home_page => self.calculated_home_page, :notes => self.notes, diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb index 1feb9c70b..29122e692 100644 --- a/app/models/raw_email.rb +++ b/app/models/raw_email.rb @@ -16,7 +16,7 @@ class RawEmail < ActiveRecord::Base # deliberately don't strip_attributes, so keeps raw email properly - + has_one :incoming_message # We keep the old data_text field (which is of type text) for backwards @@ -30,7 +30,7 @@ class RawEmail < ActiveRecord::Base return File.join(Rails.root, 'files/raw_email_test') else return File.join(MySociety::Config.get('RAW_EMAILS_LOCATION', - 'files/raw_emails'), + 'files/raw_emails'), request_id[0..2], request_id) end end diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index 177a39241..e336111ee 100644 --- a/app/models/request_mailer.rb +++ b/app/models/request_mailer.rb @@ -9,7 +9,7 @@ require 'alaveteli_file_types' class RequestMailer < ApplicationMailer - + # Used when an FOI officer uploads a response from their web browser - this is # the "fake" email used to store in the same format in the database as if they @@ -38,7 +38,7 @@ class RequestMailer < ApplicationMailer @subject = "Your response to an FOI request was not delivered" attachment :content_type => 'message/rfc822', :body => raw_email_data, :filename => "original.eml", :transfer_encoding => '7bit', :content_disposition => 'inline' - @body = { + @body = { :info_request => info_request, :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') } @@ -142,7 +142,7 @@ class RequestMailer < ApplicationMailer # Tell the requester that they need to clarify their request def not_clarified_alert(info_request, incoming_message) respond_url = show_response_url(:id => info_request.id, :incoming_message_id => incoming_message.id) - respond_url = respond_url + "#followup" + respond_url = respond_url + "#followup" post_redirect = PostRedirect.new( :uri => respond_url, @@ -182,7 +182,7 @@ class RequestMailer < ApplicationMailer # Class function, called by script/mailin with all incoming responses. # [ This is a copy (Monkeypatch!) of function from action_mailer/base.rb, # but which additionally passes the raw_email to the member function, as we - # want to record it. + # want to record it. # # That is because we want to be sure we properly record the actual message # received in its raw form - so any information won't be lost in a round @@ -215,7 +215,7 @@ class RequestMailer < ApplicationMailer # Find which info requests the email is for reply_info_requests = self.requests_matching_email(email) # Nothing found, so save in holding pen - if reply_info_requests.size == 0 + if reply_info_requests.size == 0 reason = _("Could not identify the request from the email address") request = InfoRequest.holding_pen_request request.receive(email, raw_email, false, reason) @@ -225,7 +225,7 @@ class RequestMailer < ApplicationMailer # Send the message to each request, to be archived with it for reply_info_request in reply_info_requests # If environment variable STOP_DUPLICATES is set, don't send message with same id again - if ENV['STOP_DUPLICATES'] + if ENV['STOP_DUPLICATES'] if reply_info_request.already_received?(email, raw_email) raise "message " + email.message_id + " already received by request" end @@ -275,7 +275,7 @@ class RequestMailer < ApplicationMailer end end - # Send email alerts for new responses which haven't been classified. By default, + # Send email alerts for new responses which haven't been classified. By default, # it goes out 3 days after last update of event, then after 10, then after 24. def self.alert_new_response_reminders MySociety::Config.get("NEW_RESPONSE_REMINDER_AFTER_DAYS", [3, 10, 24]).each_with_index do |days, i| @@ -283,10 +283,10 @@ class RequestMailer < ApplicationMailer end end def self.alert_new_response_reminders_internal(days_since, type_code) - info_requests = InfoRequest.find_old_unclassified(:order => 'info_requests.id', - :include => [:user], + info_requests = InfoRequest.find_old_unclassified(:order => 'info_requests.id', + :include => [:user], :age_in_days => days_since) - + for info_request in info_requests alert_event_id = info_request.get_last_response_event_id last_response_message = info_request.get_last_response @@ -302,7 +302,7 @@ class RequestMailer < ApplicationMailer store_sent.user = info_request.user store_sent.alert_type = type_code store_sent.info_request_event_id = alert_event_id - # XXX uses same template for reminder 1 and reminder 2 right now. + # XXX uses same template for reminder 1 and reminder 2 right now. RequestMailer.deliver_new_response_reminder_alert(info_request, last_response_message) store_sent.save! end @@ -340,11 +340,11 @@ class RequestMailer < ApplicationMailer # Send email alert to request submitter for new comments on the request. def self.alert_comment_on_request() - + # We only check comments made in the last month - this means if the # cron jobs broke for more than a month events would be lost, but no # matter. I suspect the performance gain will be needed (with an index on updated_at) - + # XXX the :order part info_request_events.created_at is a work around # for a very old Rails bug which means eager loading does not respect # association orders. @@ -352,7 +352,7 @@ class RequestMailer < ApplicationMailer # http://lists.rubyonrails.org/pipermail/rails-core/2006-July/001798.html # That that patch has not been applied, despite bribes of beer, is # typical of the lack of quality of Rails. - + info_requests = InfoRequest.find(:all, :conditions => [ "info_requests.id in ( diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index 0c053c4ad..f618fba49 100644 --- a/app/models/track_mailer.rb +++ b/app/models/track_mailer.rb @@ -48,7 +48,7 @@ class TrackMailer < ApplicationMailer end for user in users next if !user.should_be_emailed? - + email_about_things = [] track_things = TrackThing.find(:all, :conditions => [ "tracking_user_id = ? and track_medium = ?", user.id, 'email_daily' ]) for track_thing in track_things @@ -56,7 +56,7 @@ class TrackMailer < ApplicationMailer # # We only use track_things_sent_emails records which are less than 14 days old. # In the search query loop below, we also only use items described in last 7 days. - # An item described that recently definitely can't appear in track_things_sent_emails + # An item described that recently definitely can't appear in track_things_sent_emails # earlier, so this is safe (with a week long margin of error). If the alerts break # for a whole week, then they will miss some items. Tough. done_info_request_events = {} @@ -70,7 +70,7 @@ class TrackMailer < ApplicationMailer # Query for things in this track. We use described_at for the # ordering, so we catch anything new (before described), or # anything whose new status has been described. - xapian_object = InfoRequest.full_search([InfoRequestEvent], track_thing.track_query, 'described_at', true, nil, 100, 1) + xapian_object = InfoRequest.full_search([InfoRequestEvent], track_thing.track_query, 'described_at', true, nil, 100, 1) # Go through looking for unalerted things alert_results = [] for result in xapian_object.results @@ -86,7 +86,7 @@ class TrackMailer < ApplicationMailer alert_results.push(result) end # If there were more alerts for this track, then store them - if alert_results.size > 0 + if alert_results.size > 0 email_about_things.push([track_thing, alert_results, xapian_object]) end end diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index bdcd87e4f..446060279 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -35,17 +35,17 @@ class TrackThing < ActiveRecord::Base has_many :track_things_sent_emails - validates_inclusion_of :track_type, :in => [ - 'request_updates', + validates_inclusion_of :track_type, :in => [ + 'request_updates', 'all_new_requests', 'all_successful_requests', - 'public_body_updates', + 'public_body_updates', 'user_updates', 'search_query' ] - validates_inclusion_of :track_medium, :in => [ - 'email_daily', + validates_inclusion_of :track_medium, :in => [ + 'email_daily', 'feed' ] @@ -69,7 +69,7 @@ class TrackThing < ActiveRecord::Base end def track_query_description - # XXX this is very brittle... we should probably ask users + # XXX this is very brittle... we should probably ask users # simply to name their tracks when they make them? original_text = parsed_text = self.track_query.gsub(/([()]|OR)/, "") filters = parsed_text.scan /\b\S+:\S+\b/ @@ -101,7 +101,7 @@ class TrackThing < ActiveRecord::Base end if filter =~ /waiting/ statuses << _("awaiting a response") - end + end end if filters.empty? parsed_text = original_text @@ -195,7 +195,7 @@ class TrackThing < ActiveRecord::Base if self.track_type == 'request_updates' @params = { # Website - :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 + :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 @@ -246,7 +246,7 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'public_body_updates' @params = { # Website - :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 + :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 @@ -262,7 +262,7 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'user_updates' @params = { # Website - :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 + :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 @@ -278,7 +278,7 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'search_query' @params = { # Website - :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 + :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 diff --git a/app/models/user.rb b/app/models/user.rb index 73d65a8ca..cd8d3e721 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -52,22 +52,22 @@ class User < ActiveRecord::Base attr_accessor :password_confirmation, :no_xapian_reindex validates_confirmation_of :password, :message => _("Please enter the same password twice") - validates_inclusion_of :admin_level, :in => [ + validates_inclusion_of :admin_level, :in => [ 'none', - 'super', + 'super', ], :message => N_('Admin level is not included in list') acts_as_xapian :texts => [ :name, :about_me ], - :values => [ + :values => [ [ :created_at_numeric, 1, "created_at", :number ] # for sorting ], :terms => [ [ :variety, 'V', "variety" ] ], :if => :indexed_by_search? def created_at_numeric # format it here as no datetime support in Xapian's value ranges - return self.created_at.strftime("%Y%m%d%H%M%S") + return self.created_at.strftime("%Y%m%d%H%M%S") end - + def variety "user" end @@ -79,7 +79,7 @@ class User < ActiveRecord::Base if self.new_record? # make alert emails go out at a random time for each new user, so # overall they are spread out throughout the day. - self.last_daily_track_email = User.random_time_in_last_day + self.last_daily_track_email = User.random_time_in_last_day end end @@ -101,7 +101,7 @@ class User < ActiveRecord::Base end end end - + def get_locale if !self.locale.nil? locale = self.locale @@ -117,10 +117,10 @@ class User < ActiveRecord::Base def validate if self.email != "" && !MySociety::Validate.is_valid_email(self.email) - errors.add(:email, _("Please enter a valid email address")) + errors.add(:email, _("Please enter a valid email address")) end if MySociety::Validate.is_valid_email(self.name) - errors.add(:name, _("Please enter your name, not your email address, in the name field.")) + errors.add(:name, _("Please enter your name, not your email address, in the name field.")) end end @@ -139,7 +139,7 @@ class User < ActiveRecord::Base end # Return user given login email, password and other form parameters (e.g. name) - # + # # The specific_user_login parameter says that login as a particular user is # expected, so no parallel registration form is being displayed. def User.authenticate_from_form(params, specific_user_login = false) @@ -235,10 +235,10 @@ class User < ActiveRecord::Base # changed more than a day ago) def get_undescribed_requests self.info_requests.find( - :all, - :conditions => [ 'awaiting_description = ? and ' + InfoRequest.last_event_time_clause + ' < ?', - true, Time.now() - 1.day - ] + :all, + :conditions => [ 'awaiting_description = ? and ' + InfoRequest.last_event_time_clause + ' < ?', + true, Time.now() - 1.day + ] ) end @@ -256,7 +256,7 @@ class User < ActiveRecord::Base def owns_every_request? self.admin_level == 'super' end - + def User.owns_every_request?(user) !user.nil? && user.owns_every_request? end @@ -271,7 +271,7 @@ class User < ActiveRecord::Base def User.stay_logged_in_on_redirect?(user) !user.nil? && user.admin_level == 'super' end - + # Does the user get "(admin)" links on each page on the main site? def admin_page_links? self.admin_level == 'super' @@ -287,21 +287,21 @@ class User < ActiveRecord::Base def exceeded_limit? # Some users have no limit return false if self.no_limit - + # Has the user issued as many as MAX_REQUESTS_PER_USER_PER_DAY requests in the past 24 hours? daily_limit = MySociety::Config.get("MAX_REQUESTS_PER_USER_PER_DAY") return false if daily_limit.nil? recent_requests = InfoRequest.count(:conditions => ["user_id = ? and created_at > now() - '1 day'::interval", self.id]) - + return (recent_requests >= daily_limit) end def next_request_permitted_at return nil if self.no_limit - + daily_limit = MySociety::Config.get("MAX_REQUESTS_PER_USER_PER_DAY") n_most_recent_requests = InfoRequest.all(:conditions => ["user_id = ? and created_at > now() - '1 day'::interval", self.id], :order => "created_at DESC", :limit => daily_limit) return nil if n_most_recent_requests.size < daily_limit - + nth_most_recent_request = n_most_recent_requests[-1] return nth_most_recent_request.created_at + 1.day end @@ -375,7 +375,7 @@ class User < ActiveRecord::Base end def json_for_api - return { + return { :id => self.id, :url_name => self.url_name, :name => self.name, @@ -391,11 +391,11 @@ class User < ActiveRecord::Base self.email_bounce_message = message self.save! end - + def should_be_emailed? return (self.email_confirmed && self.email_bounced_at.nil?) end - + def indexed_by_search? return self.email_confirmed end @@ -406,17 +406,17 @@ class User < ActiveRecord::Base def create_new_salt self.salt = self.object_id.to_s + rand.to_s end - + ## Class methods def User.encrypted_password(password, salt) string_to_hash = password + salt # XXX need to add a secret here too? Digest::SHA1.hexdigest(string_to_hash) end - + def User.record_bounce_for_email(email, message) user = User.find_user_by_email(email) return false if user.nil? - + if user.email_bounced_at.nil? user.record_bounce(message) end diff --git a/app/models/user_info_request_sent_alert.rb b/app/models/user_info_request_sent_alert.rb index 5f23355bf..15cac515f 100644 --- a/app/models/user_info_request_sent_alert.rb +++ b/app/models/user_info_request_sent_alert.rb @@ -23,7 +23,7 @@ class UserInfoRequestSentAlert < ActiveRecord::Base belongs_to :user belongs_to :info_request - validates_inclusion_of :alert_type, :in => [ + validates_inclusion_of :alert_type, :in => [ 'overdue_1', # tell user that info request has become overdue 'very_overdue_1', # tell user that info request has become very overdue 'new_response_reminder_1', # reminder user to classify the recent response |