aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin_comment_controller.rb2
-rw-r--r--app/controllers/admin_incoming_message_controller.rb6
-rw-r--r--app/controllers/admin_outgoing_message_controller.rb4
-rw-r--r--app/controllers/admin_public_body_controller.rb14
-rw-r--r--app/controllers/admin_request_controller.rb6
-rw-r--r--app/controllers/api_controller.rb2
-rw-r--r--app/controllers/application_controller.rb2
-rw-r--r--app/controllers/general_controller.rb4
-rw-r--r--app/controllers/public_body_controller.rb8
-rw-r--r--app/controllers/request_controller.rb8
-rw-r--r--app/controllers/request_game_controller.rb2
-rw-r--r--app/controllers/user_controller.rb6
-rw-r--r--app/helpers/public_body_helper.rb4
-rw-r--r--app/mailers/outgoing_mailer.rb12
-rw-r--r--app/mailers/request_mailer.rb93
-rw-r--r--app/mailers/track_mailer.rb2
-rw-r--r--app/models/comment.rb2
-rw-r--r--app/models/foi_attachment.rb34
-rw-r--r--app/models/incoming_message.rb4
-rw-r--r--app/models/info_request.rb107
-rw-r--r--app/models/info_request_batch.rb4
-rw-r--r--app/models/info_request_event.rb14
-rw-r--r--app/models/mail_server_log.rb54
-rw-r--r--app/models/public_body.rb10
-rw-r--r--app/models/public_body_category/category_collection.rb8
-rw-r--r--app/models/request_classification.rb2
-rw-r--r--app/models/user.rb4
-rw-r--r--app/views/public_body/show.html.erb12
-rw-r--r--app/views/public_body_change_requests/new.html.erb2
-rw-r--r--app/views/user/_user_listing_single.html.erb2
-rw-r--r--app/views/user/show.html.erb4
31 files changed, 207 insertions, 231 deletions
diff --git a/app/controllers/admin_comment_controller.rb b/app/controllers/admin_comment_controller.rb
index 0d5e84fed..030afb645 100644
--- a/app/controllers/admin_comment_controller.rb
+++ b/app/controllers/admin_comment_controller.rb
@@ -21,7 +21,7 @@ class AdminCommentController < AdminController
if @comment.update_attributes(params[:comment])
@comment.info_request.log_event("edit_comment",
{ :comment_id => @comment.id,
- :editor => admin_current_user(),
+ :editor => admin_current_user,
:old_body => old_body,
:body => @comment.body,
:old_visible => old_visible,
diff --git a/app/controllers/admin_incoming_message_controller.rb b/app/controllers/admin_incoming_message_controller.rb
index 8dfd53662..db7bed34c 100644
--- a/app/controllers/admin_incoming_message_controller.rb
+++ b/app/controllers/admin_incoming_message_controller.rb
@@ -14,7 +14,7 @@ class AdminIncomingMessageController < AdminController
if @incoming_message.save
@incoming_message.info_request.log_event('edit_incoming',
:incoming_message_id => @incoming_message.id,
- :editor => admin_current_user(),
+ :editor => admin_current_user,
:old_prominence => old_prominence,
:prominence => @incoming_message.prominence,
:old_prominence_reason => old_prominence_reason,
@@ -34,7 +34,7 @@ class AdminIncomingMessageController < AdminController
@incoming_message.fully_destroy
@incoming_message.info_request.log_event("destroy_incoming",
- { :editor => admin_current_user(), :deleted_incoming_message_id => incoming_message_id })
+ { :editor => admin_current_user, :deleted_incoming_message_id => incoming_message_id })
# expire cached files
expire_for_request(@info_request)
flash[:notice] = 'Incoming message successfully destroyed.'
@@ -64,7 +64,7 @@ class AdminIncomingMessageController < AdminController
incoming_message_id = incoming_message.id
incoming_message.info_request.log_event("redeliver_incoming", {
- :editor => admin_current_user(),
+ :editor => admin_current_user,
:destination_request => destination_request.id,
:deleted_incoming_message_id => incoming_message_id
})
diff --git a/app/controllers/admin_outgoing_message_controller.rb b/app/controllers/admin_outgoing_message_controller.rb
index 6c0b23ceb..56e27b108 100644
--- a/app/controllers/admin_outgoing_message_controller.rb
+++ b/app/controllers/admin_outgoing_message_controller.rb
@@ -12,7 +12,7 @@ class AdminOutgoingMessageController < AdminController
@outgoing_message.fully_destroy
@outgoing_message.info_request.log_event("destroy_outgoing",
- { :editor => admin_current_user(), :deleted_outgoing_message_id => outgoing_message_id })
+ { :editor => admin_current_user, :deleted_outgoing_message_id => outgoing_message_id })
flash[:notice] = 'Outgoing message successfully destroyed.'
redirect_to admin_request_url(@info_request)
@@ -30,7 +30,7 @@ class AdminOutgoingMessageController < AdminController
if @outgoing_message.save
@outgoing_message.info_request.log_event("edit_outgoing",
{ :outgoing_message_id => @outgoing_message.id,
- :editor => admin_current_user(),
+ :editor => admin_current_user,
:old_body => old_body,
:body => @outgoing_message.body,
:old_prominence => old_prominence,
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index 12ce8bf90..b3c2c1dfd 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_body_controller.rb
@@ -12,7 +12,7 @@ class AdminPublicBodyController < AdminController
end
def show
- @locale = self.locale_from_params()
+ @locale = locale_from_params
I18n.with_locale(@locale) do
@public_body = PublicBody.find(params[:id])
@info_requests = @public_body.info_requests.paginate :order => "created_at desc",
@@ -44,7 +44,7 @@ class AdminPublicBodyController < AdminController
if params[:change_request_id]
@change_request = PublicBodyChangeRequest.find(params[:change_request_id])
end
- params[:public_body][:last_edit_editor] = admin_current_user()
+ params[:public_body][:last_edit_editor] = admin_current_user
@public_body = PublicBody.new(params[:public_body])
if @public_body.save
if @change_request
@@ -85,7 +85,7 @@ class AdminPublicBodyController < AdminController
@change_request = PublicBodyChangeRequest.find(params[:change_request_id])
end
I18n.with_locale(I18n.default_locale) do
- params[:public_body][:last_edit_editor] = admin_current_user()
+ params[:public_body][:last_edit_editor] = admin_current_user
@public_body = PublicBody.find(params[:id])
if @public_body.update_attributes(params[:public_body])
if @change_request
@@ -102,7 +102,7 @@ class AdminPublicBodyController < AdminController
end
def destroy
- @locale = self.locale_from_params()
+ @locale = locale_from_params
I18n.with_locale(@locale) do
public_body = PublicBody.find(params[:id])
@@ -178,7 +178,7 @@ class AdminPublicBodyController < AdminController
params[:tag],
params[:tag_behaviour],
true,
- admin_current_user(),
+ admin_current_user,
I18n.available_locales)
if errors.size == 0
@@ -192,7 +192,7 @@ class AdminPublicBodyController < AdminController
params[:tag],
params[:tag_behaviour],
false,
- admin_current_user(),
+ admin_current_user,
I18n.available_locales)
if errors.size != 0
raise "dry run mismatched real run"
@@ -235,7 +235,7 @@ class AdminPublicBodyController < AdminController
end
def lookup_query
- @locale = self.locale_from_params()
+ @locale = locale_from_params
underscore_locale = @locale.gsub '-', '_'
I18n.with_locale(@locale) do
@query = params[:query]
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index bacf087e9..eaf6c337d 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -57,7 +57,7 @@ class AdminRequestController < AdminController
if @info_request.valid?
@info_request.save!
@info_request.log_event("edit",
- { :editor => admin_current_user(),
+ { :editor => admin_current_user,
:old_title => old_title, :title => @info_request.title,
:old_prominence => old_prominence, :prominence => @info_request.prominence,
:old_described_state => old_described_state, :described_state => params[:info_request][:described_state],
@@ -105,7 +105,7 @@ class AdminRequestController < AdminController
info_request.user = destination_user
info_request.save!
info_request.log_event("move_request", {
- :editor => admin_current_user(),
+ :editor => admin_current_user,
:old_user_url_name => old_user.url_name,
:user_url_name => destination_user.url_name
})
@@ -176,7 +176,7 @@ class AdminRequestController < AdminController
info_request.prominence = "requester_only"
info_request.log_event("hide", {
- :editor => admin_current_user(),
+ :editor => admin_current_user,
:reason => params[:reason],
:subject => subject,
:explanation => explanation
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 779ae04a6..3b8991f28 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -42,7 +42,7 @@ class ApiController < ApplicationController
:status => 'ready',
:message_type => 'initial_request',
:body => json["body"],
- :last_sent_at => Time.now(),
+ :last_sent_at => Time.now,
:what_doing => 'normal_sort',
:info_request => request
)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 07956d370..a76e6630a 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -206,7 +206,7 @@ class ApplicationController < ActionController::Base
def foi_fragment_cache_part_path(param)
path = url_for(param)
id = param['id'] || param[:id]
- first_three_digits = id.to_s()[0..2]
+ first_three_digits = id.to_s[0..2]
path = path.sub("/request/", "/request/" + first_three_digits + "/")
return path
end
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 324f5f2e4..53288c2f4 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -15,7 +15,7 @@ class GeneralController < ApplicationController
# New, improved front page!
def frontpage
medium_cache
- @locale = self.locale_from_params()
+ @locale = locale_from_params
successful_query = InfoRequestEvent.make_query_from_params( :latest_status => ['successful'] )
@track_thing = TrackThing.create_track_for_search_query(successful_query)
@feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'),
@@ -33,7 +33,7 @@ class GeneralController < ApplicationController
@feed_autodetect = []
@feed_url = AlaveteliConfiguration::blog_feed
separator = @feed_url.include?('?') ? '&' : '?'
- @feed_url = "#{@feed_url}#{separator}lang=#{self.locale_from_params()}"
+ @feed_url = "#{@feed_url}#{separator}lang=#{locale_from_params}"
@blog_items = []
if not @feed_url.empty?
content = quietly_try_to_open(@feed_url)
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb
index b34c929f5..1b01dc837 100644
--- a/app/controllers/public_body_controller.rb
+++ b/app/controllers/public_body_controller.rb
@@ -24,7 +24,7 @@ class PublicBodyController < ApplicationController
redirect_to :url_name => MySociety::Format.simplify_url_part(params[:url_name], 'body'), :status => :moved_permanently
return
end
- @locale = self.locale_from_params()
+ @locale = locale_from_params
I18n.with_locale(@locale) do
@public_body = PublicBody.find_by_url_name_with_historic(params[:url_name])
raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil?
@@ -40,6 +40,8 @@ class PublicBodyController < ApplicationController
set_last_body(@public_body)
+ @number_of_visible_requests = @public_body.info_requests.visible.count
+
top_url = frontpage_url
@searched_to_send_request = false
referrer = request.env['HTTP_REFERER']
@@ -83,7 +85,7 @@ class PublicBodyController < ApplicationController
@public_body = PublicBody.find_by_url_name_with_historic(params[:url_name])
raise ActiveRecord::RecordNotFound.new("None found") if @public_body.nil?
- I18n.with_locale(self.locale_from_params()) do
+ I18n.with_locale(locale_from_params) do
if params[:submitted_view_email]
if verify_recaptcha
flash.discard(:error)
@@ -106,7 +108,7 @@ class PublicBodyController < ApplicationController
@tag = params[:tag]
- @locale = self.locale_from_params
+ @locale = locale_from_params
underscore_locale = @locale.gsub '-', '_'
underscore_default_locale = I18n.default_locale.to_s.gsub '-', '_'
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index f63fb0301..45229fd7e 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -75,7 +75,7 @@ class RequestController < ApplicationController
else
medium_cache
end
- @locale = self.locale_from_params()
+ @locale = locale_from_params
I18n.with_locale(@locale) do
# Look up by old style numeric identifiers
@@ -164,7 +164,7 @@ class RequestController < ApplicationController
def list
medium_cache
@view = params[:view]
- @locale = self.locale_from_params()
+ @locale = locale_from_params
@page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect
@per_page = PER_PAGE
@max_results = MAX_RESULTS
@@ -848,7 +848,7 @@ class RequestController < ApplicationController
# FOI officers can upload a response
def upload_response
- @locale = self.locale_from_params()
+ @locale = locale_from_params
I18n.with_locale(@locale) do
@info_request = InfoRequest.find_by_url_title!(params[:url_title])
@@ -914,7 +914,7 @@ class RequestController < ApplicationController
end
def download_entire_request
- @locale = self.locale_from_params()
+ @locale = locale_from_params
I18n.with_locale(@locale) do
@info_request = InfoRequest.find_by_url_title!(params[:url_title])
if authenticated?(
diff --git a/app/controllers/request_game_controller.rb b/app/controllers/request_game_controller.rb
index cb3ba1f3a..2915b5c2f 100644
--- a/app/controllers/request_game_controller.rb
+++ b/app/controllers/request_game_controller.rb
@@ -23,7 +23,7 @@ class RequestGameController < ApplicationController
:site_name => site_name)
end
- @league_table_28_days = RequestClassification.league_table(10, [ "created_at >= ?", Time.now() - 28.days ])
+ @league_table_28_days = RequestClassification.league_table(10, [ "created_at >= ?", Time.now - 28.days ])
@league_table_all_time = RequestClassification.league_table(10)
@play_urls = true
end
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 8d9adfc77..bb4ba28d1 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -373,7 +373,7 @@ class UserController < ApplicationController
if (not session[:user_circumstance]) or (session[:user_circumstance] != "change_email")
# don't store the password in the db
params[:signchangeemail].delete(:password)
- post_redirect = PostRedirect.new(:uri => signchangeemail_url(),
+ post_redirect = PostRedirect.new(:uri => signchangeemail_url,
:post_params => params,
:circumstance => "change_email" # special login that lets you change your email
)
@@ -510,7 +510,7 @@ class UserController < ApplicationController
else
flash[:notice] = _("<p>Thanks for updating your profile photo.</p>
<p><strong>Next...</strong> You can put some text about you and your research on your profile.</p>")
- redirect_to set_profile_about_me_url()
+ redirect_to set_profile_about_me_url
end
else
render :template => 'user/set_draft_profile_photo'
@@ -596,7 +596,7 @@ class UserController < ApplicationController
else
flash[:notice] = _("<p>Thanks for changing the text about you on your profile.</p>
<p><strong>Next...</strong> You can upload a profile photograph too.</p>")
- redirect_to set_profile_photo_url()
+ redirect_to set_profile_photo_url
end
end
diff --git a/app/helpers/public_body_helper.rb b/app/helpers/public_body_helper.rb
index 3fb04d45a..e094d98b4 100644
--- a/app/helpers/public_body_helper.rb
+++ b/app/helpers/public_body_helper.rb
@@ -41,8 +41,8 @@ module PublicBodyHelper
def type_of_authority(public_body)
first = true
types = public_body.tags.each.map do |tag|
- if PublicBodyCategory.get().by_tag().include?(tag.name)
- desc = PublicBodyCategory.get().singular_by_tag()[tag.name]
+ if PublicBodyCategory.get.by_tag.include?(tag.name)
+ desc = PublicBodyCategory.get.singular_by_tag[tag.name]
if first
desc = desc.sub(/\S/) { |m| Unicode.upcase(m) }
first = false
diff --git a/app/mailers/outgoing_mailer.rb b/app/mailers/outgoing_mailer.rb
index 0a1b0aee3..78041d04b 100644
--- a/app/mailers/outgoing_mailer.rb
+++ b/app/mailers/outgoing_mailer.rb
@@ -41,7 +41,7 @@ class OutgoingMailer < ApplicationMailer
# TODO: also OutgoingMessage.get_salutation
# TODO: these look like they should be members of IncomingMessage, but logically they
# need to work even when IncomingMessage is nil
- def OutgoingMailer.name_and_email_for_followup(info_request, incoming_message_followup)
+ def self.name_and_email_for_followup(info_request, incoming_message_followup)
if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to?
return info_request.recipient_name_and_email
else
@@ -51,7 +51,7 @@ class OutgoingMailer < ApplicationMailer
end
end
# Used in the preview of followup
- def OutgoingMailer.name_for_followup(info_request, incoming_message_followup)
+ def self.name_for_followup(info_request, incoming_message_followup)
if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to?
return info_request.public_body.name
else
@@ -60,7 +60,7 @@ class OutgoingMailer < ApplicationMailer
end
end
# Used when making list of followup places to remove duplicates
- def OutgoingMailer.email_for_followup(info_request, incoming_message_followup)
+ def self.email_for_followup(info_request, incoming_message_followup)
if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to?
return info_request.recipient_email
else
@@ -68,7 +68,7 @@ class OutgoingMailer < ApplicationMailer
end
end
# Subject to use for followup
- def OutgoingMailer.subject_for_followup(info_request, outgoing_message, options = {})
+ def self.subject_for_followup(info_request, outgoing_message, options = {})
if outgoing_message.what_doing == 'internal_review'
return "Internal review of " + info_request.email_subject_request(:html => options[:html])
else
@@ -77,7 +77,7 @@ class OutgoingMailer < ApplicationMailer
end
end
# Whether we have a valid email address for a followup
- def OutgoingMailer.is_followupable?(info_request, incoming_message_followup)
+ def self.is_followupable?(info_request, incoming_message_followup)
if incoming_message_followup.nil? || !incoming_message_followup.valid_to_reply_to?
return info_request.recipient_email_valid_for_followup?
else
@@ -86,7 +86,7 @@ class OutgoingMailer < ApplicationMailer
end
end
# Message-ID to use
- def OutgoingMailer.id_for_message(outgoing_message)
+ def self.id_for_message(outgoing_message)
message_id = "ogm-" + outgoing_message.id.to_s
t = Time.now
message_id += "+" + '%08x%05x-%04x' % [t.to_i, t.tv_usec, rand(0xffff)]
diff --git a/app/mailers/request_mailer.rb b/app/mailers/request_mailer.rb
index f97556915..f12b4a0d6 100644
--- a/app/mailers/request_mailer.rb
+++ b/app/mailers/request_mailer.rb
@@ -100,13 +100,8 @@ class RequestMailer < ApplicationMailer
@url = confirm_url(:email_token => post_redirect.email_token)
@info_request = info_request
- headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # 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')
-
- mail(:from => contact_from_name_and_email,
- :to => user.name_and_email,
- :subject => _("Delayed response to your FOI request - ") + info_request.title.html_safe)
+ auto_generated_headers
+ mail_user_with_info_request_title(user, _("Delayed response to your FOI request - "), info_request)
end
# Tell the requester that the public body is very late in replying
@@ -120,13 +115,8 @@ class RequestMailer < ApplicationMailer
@url = confirm_url(:email_token => post_redirect.email_token)
@info_request = info_request
- headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # 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')
-
- mail(:from => contact_from_name_and_email,
- :to => user.name_and_email,
- :subject => _("You're long overdue a response to your FOI request - ") + info_request.title.html_safe)
+ auto_generated_headers
+ mail_user_with_info_request_title(user, _("You're long overdue a response to your FOI request - "), info_request)
end
# Tell the requester that they need to say if the new response
@@ -142,13 +132,8 @@ class RequestMailer < ApplicationMailer
@incoming_message = incoming_message
@info_request = info_request
- headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # 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')
-
- mail(:from => contact_from_name_and_email,
- :to => info_request.user.name_and_email,
- :subject => _("Was the response you got to your FOI request any good?"))
+ auto_generated_headers
+ mail_user(info_request.user, _("Was the response you got to your FOI request any good?"))
end
# Tell the requester that someone updated their old unclassified request
@@ -156,13 +141,8 @@ class RequestMailer < ApplicationMailer
@url = request_url(info_request)
@info_request = info_request
- headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # 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')
-
- mail(:from => contact_from_name_and_email,
- :to => info_request.user.name_and_email,
- :subject => _("Someone has updated the status of your request"))
+ auto_generated_headers
+ mail_user(info_request.user, _("Someone has updated the status of your request"))
end
# Tell the requester that they need to clarify their request
@@ -178,13 +158,8 @@ class RequestMailer < ApplicationMailer
@incoming_message = incoming_message
@info_request = info_request
- headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # 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')
-
- mail(:from => contact_from_name_and_email,
- :to => info_request.user.name_and_email,
- :subject => _("Clarify your FOI request - ") + info_request.title.html_safe)
+ auto_generated_headers
+ mail_user_with_info_request_title(info_request.user, _("Clarify your FOI request - "), info_request)
end
# Tell requester that somebody add an annotation to their request
@@ -192,25 +167,15 @@ class RequestMailer < ApplicationMailer
@comment, @info_request = comment, info_request
@url = comment_url(comment)
- headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # 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')
-
- mail(:from => contact_from_name_and_email,
- :to => info_request.user.name_and_email,
- :subject => _("Somebody added a note to your FOI request - ") + info_request.title.html_safe)
+ auto_generated_headers
+ mail_user_with_info_request_title(info_request.user, _("Somebody added a note to your FOI request - "), info_request)
end
def comment_on_alert_plural(info_request, count, earliest_unalerted_comment)
@count, @info_request = count, info_request
@url = comment_url(earliest_unalerted_comment)
- headers('Return-Path' => blackhole_email, 'Reply-To' => contact_from_name_and_email, # 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')
-
- mail(:from => contact_from_name_and_email,
- :to => info_request.user.name_and_email,
- :subject => _("Some notes have been added to your FOI request - ") + info_request.title.html_safe)
+ auto_generated_headers
+ mail_user_with_info_request_title(info_request.user, _("Some notes have been added to your FOI request - "), info_request)
end
# Class function, called by script/mailin with all incoming responses.
@@ -269,7 +234,7 @@ class RequestMailer < ApplicationMailer
end
# Send email alerts for overdue requests
- def self.alert_overdue_requests()
+ def self.alert_overdue_requests
info_requests = InfoRequest.find(:all,
:conditions => [
"described_state = 'waiting_response'
@@ -373,8 +338,8 @@ class RequestMailer < ApplicationMailer
# Send email alerts for requests which need clarification. Goes out 3 days
# after last update of event.
- def self.alert_not_clarified_request()
- info_requests = InfoRequest.find(:all, :conditions => [ "awaiting_description = ? and described_state = 'waiting_clarification' and info_requests.updated_at < ?", false, Time.now() - 3.days ], :include => [ :user ], :order => "info_requests.id" )
+ def self.alert_not_clarified_request
+ info_requests = InfoRequest.find(:all, :conditions => [ "awaiting_description = ? and described_state = 'waiting_clarification' and info_requests.updated_at < ?", false, Time.now - 3.days ], :include => [ :user ], :order => "info_requests.id" )
for info_request in info_requests
alert_event_id = info_request.get_last_public_response_event_id
last_response_message = info_request.get_last_public_response
@@ -401,7 +366,7 @@ class RequestMailer < ApplicationMailer
end
# Send email alert to request submitter for new comments on the request.
- def self.alert_comment_on_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
@@ -468,7 +433,27 @@ class RequestMailer < ApplicationMailer
end
end
+ private
-end
+ def auto_generated_headers
+ headers({
+ 'Return-Path' => blackhole_email,
+ 'Reply-To' => contact_from_name_and_email, # 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',
+ })
+ end
+ def mail_user_with_info_request_title(user, subject, info_request)
+ mail_user(user, subject + info_request.title.html_safe)
+ end
+
+ def mail_user(user, subject)
+ mail({
+ :from => contact_from_name_and_email,
+ :to => user.name_and_email,
+ :subject => subject,
+ })
+ end
+end
diff --git a/app/mailers/track_mailer.rb b/app/mailers/track_mailer.rb
index fc7895203..3f5de6a1b 100644
--- a/app/mailers/track_mailer.rb
+++ b/app/mailers/track_mailer.rb
@@ -39,7 +39,7 @@ class TrackMailer < ApplicationMailer
# User.find(:all, :conditions => [ "last_daily_track_email < ?", Time.now - 1.day ]).size
def self.alert_tracks
done_something = false
- now = Time.now()
+ now = Time.now
one_week_ago = now - 7.days
User.find_each(:conditions => [ "last_daily_track_email < ?",
now - 1.day ]) do |user|
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 772bb3eda..59f91ffb7 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -33,6 +33,8 @@ class Comment < ActiveRecord::Base
validate :check_body_has_content,
:check_body_uses_mixed_capitals
+ scope :visible, where(:visible => true)
+
after_save :event_xapian_update
# When posting a new comment, use this to check user hasn't double
diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb
index d1c30672f..0af47b26e 100644
--- a/app/models/foi_attachment.rb
+++ b/app/models/foi_attachment.rb
@@ -244,36 +244,32 @@ class FoiAttachment < ActiveRecord::Base
# The full list of supported types can be found at
# https://docs.google.com/support/bin/answer.py?hl=en&answer=1189935
def has_google_docs_viewer?
- return !! {
- "application/pdf" => true, # .pdf
- "image/tiff" => true, # .tiff
+ [
+ "application/pdf", # .pdf
+ "image/tiff", # .tiff
- "application/vnd.ms-word" => true, # .doc
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document" => true, # .docx
+ "application/vnd.ms-word", # .doc
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document", # .docx
- "application/vnd.ms-powerpoint" => true, # .ppt
- "application/vnd.openxmlformats-officedocument.presentationml.presentation" => true, # .pptx
+ "application/vnd.ms-powerpoint", # .ppt
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation", # .pptx
- "application/vnd.ms-excel" => true, # .xls
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => true, # .xlsx
-
- } [self.content_type]
+ "application/vnd.ms-excel", # .xls
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", # .xlsx
+ ].include?(content_type)
end
# Whether this type has a "View as HTML"
def has_body_as_html?
- return (
- !!{
- "text/plain" => true,
- "application/rtf" => true,
- }[self.content_type] or
- self.has_google_docs_viewer?
- )
+ [
+ "text/plain",
+ "application/rtf",
+ ].include?(content_type) || has_google_docs_viewer?
end
# Name of type of attachment type - only valid for things that has_body_as_html?
def name_of_content_type
- return {
+ {
"text/plain" => "Text file",
'application/rtf' => "RTF file",
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 986eb19f5..dff516f0e 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -726,7 +726,7 @@ class IncomingMessage < ActiveRecord::Base
end
# Search all info requests for
- def IncomingMessage.find_all_unknown_mime_types
+ def self.find_all_unknown_mime_types
for incoming_message in IncomingMessage.find(:all)
for attachment in incoming_message.get_attachments_for_display
raise "internal error incoming_message " + incoming_message.id.to_s if attachment.content_type.nil?
@@ -752,7 +752,7 @@ class IncomingMessage < ActiveRecord::Base
return ret.keys.join(" ")
end
# Return space separated list of all file extensions known
- def IncomingMessage.get_all_file_extensions
+ def self.get_all_file_extensions
return AlaveteliFileTypes.all_extensions.join(" ")
end
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 38627df50..3ce0e3cd2 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -197,23 +197,12 @@ class InfoRequest < ActiveRecord::Base
rescue MissingSourceFile, NameError
end
- # 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, _('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, _('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, _('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 visible_comments
- self.comments.find(:all, :conditions => 'visible')
+ warn %q([DEPRECATION] InfoRequest#visible_comments will be replaced with
+ InfoRequest#comments.visible as of 0.23).squish
+ comments.visible
end
# If the URL name has changed, then all request: queries will break unless
@@ -349,7 +338,7 @@ public
# only they are sent the email address with the has in it. (We don't check
# the prefix and domain, as sometimes those change, or might be elided by
# copying an email, and that doesn't matter)
- def InfoRequest.find_by_incoming_email(incoming_email)
+ def self.find_by_incoming_email(incoming_email)
id, hash = InfoRequest._extract_id_hash_from_email(incoming_email)
if hash_from_id(id) == hash
# Not using find(id) because we don't exception raised if nothing found
@@ -359,7 +348,7 @@ public
# Return list of info requests which *might* be right given email address
# e.g. For the id-hash email addresses, don't match the hash.
- def InfoRequest.guess_by_incoming_email(incoming_message)
+ def self.guess_by_incoming_email(incoming_message)
guesses = []
# 1. Try to guess based on the email address(es)
incoming_message.addresses.each do |address|
@@ -371,7 +360,7 @@ public
end
# Internal function used by find_by_magic_email and guess_by_incoming_email
- def InfoRequest._extract_id_hash_from_email(incoming_email)
+ def self._extract_id_hash_from_email(incoming_email)
# Match case insensitively, FOI officers often write Request with capital R.
incoming_email = incoming_email.downcase
@@ -398,7 +387,7 @@ public
# repeated requests, say once a quarter for time information, then might need to do that.
# TODO: this *should* also check outgoing message joined to is an initial
# request (rather than follow up)
- def InfoRequest.find_existing(title, public_body_id, body)
+ def self.find_existing(title, public_body_id, body)
return InfoRequest.find(:first, :conditions => [ "title = ? and public_body_id = ? and outgoing_messages.body = ?", title, public_body_id, body ], :include => [ :outgoing_messages ] )
end
@@ -538,7 +527,7 @@ public
# The "holding pen" is a special request which stores incoming emails whose
# destination request is unknown.
- def InfoRequest.holding_pen_request
+ def self.holding_pen_request
ir = InfoRequest.find_by_url_title("holding_pen")
if ir.nil?
ir = InfoRequest.new(
@@ -553,7 +542,7 @@ public
:status => 'ready',
:message_type => 'initial_request',
:body => 'This is the holding pen request. It shows responses that were sent to invalid addresses, and need moving to the correct request by an adminstrator.',
- :last_sent_at => Time.now(),
+ :last_sent_at => Time.now,
:what_doing => 'normal_sort'
})
@@ -568,7 +557,7 @@ public
# states which require administrator action (hence email administrators
# when they are entered, and offer state change dialog to them)
- def InfoRequest.requires_admin_states
+ def self.requires_admin_states
return ['requires_admin', 'error_message', 'attention_requested']
end
@@ -669,11 +658,11 @@ public
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()
+ event.last_described_at = Time.now
event.save!
end
if event.last_described_at.nil? # TODO: actually maybe this isn't needed
- event.last_described_at = Time.now()
+ event.last_described_at = Time.now
event.save!
end
curr_state = nil
@@ -685,7 +674,7 @@ public
# indexed.
if event.calculated_state != event.described_state
event.calculated_state = event.described_state
- event.last_described_at = Time.now()
+ event.last_described_at = Time.now
event.save!
end
@@ -702,7 +691,7 @@ public
# case there is a preceding response that the described state should be applied to.
if event.calculated_state != event.described_state
event.calculated_state = event.described_state
- event.last_described_at = Time.now()
+ event.last_described_at = Time.now
event.save!
end
end
@@ -885,7 +874,7 @@ public
# Display version of status
- def InfoRequest.get_status_description(status)
+ def self.get_status_description(status)
descriptions = {
'waiting_classification' => _("Awaiting classification."),
'waiting_response' => _("Awaiting response."),
@@ -947,7 +936,7 @@ public
return InfoRequest.magic_email_for_id(prefix_part, self.id)
end
- def InfoRequest.magic_email_for_id(prefix_part, id)
+ def self.magic_email_for_id(prefix_part, id)
magic_email = AlaveteliConfiguration::incoming_email_prefix
magic_email += prefix_part + id.to_s
magic_email += "-" + InfoRequest.hash_from_id(id)
@@ -961,7 +950,7 @@ public
self.idhash = InfoRequest.hash_from_id(self.id)
end
- def InfoRequest.create_from_attributes(info_request_atts, outgoing_message_atts, user=nil)
+ def self.create_from_attributes(info_request_atts, outgoing_message_atts, user=nil)
info_request = new(info_request_atts)
default_message_params = {
:status => 'ready',
@@ -975,12 +964,12 @@ public
info_request
end
- def InfoRequest.hash_from_id(id)
+ def self.hash_from_id(id)
return Digest::SHA1.hexdigest(id.to_s + AlaveteliConfiguration::incoming_email_secret)[0,8]
end
# Used to find when event last changed
- def InfoRequest.last_event_time_clause(event_type=nil, join_table=nil, join_clause=nil)
+ def self.last_event_time_clause(event_type=nil, join_table=nil, join_clause=nil)
event_type_clause = ''
event_type_clause = " AND info_request_events.event_type = '#{event_type}'" if event_type
tables = ['info_request_events']
@@ -995,20 +984,20 @@ public
LIMIT 1)"
end
- def InfoRequest.last_public_response_clause()
+ def self.last_public_response_clause
join_clause = "incoming_messages.id = info_request_events.incoming_message_id
AND incoming_messages.prominence = 'normal'"
last_event_time_clause('response', 'incoming_messages', join_clause)
end
- def InfoRequest.old_unclassified_params(extra_params, include_last_response_time=false)
- last_response_created_at = last_public_response_clause()
+ def self.old_unclassified_params(extra_params, include_last_response_time=false)
+ last_response_created_at = last_public_response_clause
age = extra_params[:age_in_days] ? extra_params[:age_in_days].days : OLD_AGE_IN_DAYS
params = { :conditions => ["awaiting_description = ?
AND #{last_response_created_at} < ?
AND url_title != 'holding_pen'
AND user_id IS NOT NULL",
- true, Time.now() - age] }
+ true, Time.now - age] }
if include_last_response_time
params[:select] = "*, #{last_response_created_at} AS last_response_time"
params[:order] = 'last_response_time'
@@ -1016,29 +1005,21 @@ public
return params
end
- def InfoRequest.count_old_unclassified(extra_params={})
+ def self.count_old_unclassified(extra_params={})
params = old_unclassified_params(extra_params)
- if extra_params[:conditions]
- condition_string = extra_params[:conditions].shift
- params[:conditions][0] += " AND #{condition_string}"
- params[:conditions] += extra_params[:conditions]
- end
+ add_conditions_from_extra_params(params, extra_params)
count(:all, params)
end
- def InfoRequest.get_random_old_unclassified(limit, extra_params)
+ def self.get_random_old_unclassified(limit, extra_params)
params = old_unclassified_params({})
- if extra_params[:conditions]
- condition_string = extra_params[:conditions].shift
- params[:conditions][0] += " AND #{condition_string}"
- params[:conditions] += extra_params[:conditions]
- end
+ add_conditions_from_extra_params(params, extra_params)
params[:limit] = limit
params[:order] = "random()"
find(:all, params)
end
- def InfoRequest.find_old_unclassified(extra_params={})
+ def self.find_old_unclassified(extra_params={})
params = old_unclassified_params(extra_params, include_last_response_time=true)
[:limit, :include, :offset].each do |extra|
params[extra] = extra_params[extra] if extra_params[extra]
@@ -1047,15 +1028,11 @@ public
params[:order] = extra_params[:order]
params.delete(:select)
end
- if extra_params[:conditions]
- condition_string = extra_params[:conditions].shift
- params[:conditions][0] += " AND #{condition_string}"
- params[:conditions] += extra_params[:conditions]
- end
+ add_conditions_from_extra_params(params, extra_params)
find(:all, params)
end
- def InfoRequest.download_zip_dir()
+ def self.download_zip_dir
File.join(Rails.root, "cache", "zips", "#{Rails.env}")
end
@@ -1073,7 +1050,7 @@ public
end
def request_dirs
- first_three_digits = id.to_s()[0..2]
+ first_three_digits = id.to_s[0..2]
File.join(first_three_digits.to_s, id.to_s)
end
@@ -1082,7 +1059,7 @@ public
end
def make_zip_cache_path(user)
- cache_file_dir = File.join(InfoRequest.download_zip_dir(),
+ cache_file_dir = File.join(InfoRequest.download_zip_dir,
"download",
request_dirs,
last_update_hash)
@@ -1206,7 +1183,7 @@ public
end
# This is called from cron regularly.
- def InfoRequest.stop_new_responses_on_old_requests
+ def self.stop_new_responses_on_old_requests
# 6 months since last change to request, only allow new incoming messages from authority domains
InfoRequest.update_all "allow_new_responses_from = 'authority_only' where updated_at < (now() - interval '6 months') and allow_new_responses_from = 'anybody' and url_title <> 'holding_pen'"
# 1 year since last change requests, don't allow any new incoming messages
@@ -1255,7 +1232,7 @@ public
:model => self.class.base_class.to_s,
:model_id => self.id)
end
- req.save()
+ req.save
end
end
@@ -1300,7 +1277,7 @@ public
return [xapian_similar, xapian_similar_more]
end
- def InfoRequest.request_list(filters, page, per_page, max_results)
+ def self.request_list(filters, page, per_page, max_results)
xapian_object = ActsAsXapian::Search.new([InfoRequestEvent],
InfoRequestEvent.make_query_from_params(filters),
:offset => (page - 1) * per_page,
@@ -1317,7 +1294,7 @@ public
:show_no_more_than => show_no_more_than }
end
- def InfoRequest.recent_requests
+ def self.recent_requests
request_events = []
request_events_all_successful = false
# Get some successful requests
@@ -1364,7 +1341,7 @@ public
return [request_events, request_events_all_successful]
end
- def InfoRequest.find_in_state(state)
+ def self.find_in_state(state)
select("*, #{ last_event_time_clause } as last_event_time").
where(:described_state => state).
order('last_event_time')
@@ -1411,7 +1388,7 @@ public
self.described_state = 'waiting_response'
end
rescue ActiveModel::MissingAttributeError
- # this should only happen on Model.exists?() call. It can be safely ignored.
+ # this should only happen on Model.exists? call. It can be safely ignored.
# See http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/
end
@@ -1432,5 +1409,13 @@ public
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
+
+ def self.add_conditions_from_extra_params(params, extra_params)
+ if extra_params[:conditions]
+ condition_string = extra_params[:conditions].shift
+ params[:conditions][0] += " AND #{condition_string}"
+ params[:conditions] += extra_params[:conditions]
+ end
+ end
end
diff --git a/app/models/info_request_batch.rb b/app/models/info_request_batch.rb
index 5a20edce8..684467c61 100644
--- a/app/models/info_request_batch.rb
+++ b/app/models/info_request_batch.rb
@@ -22,7 +22,7 @@ class InfoRequestBatch < ActiveRecord::Base
validates_presence_of :body
# When constructing a new batch, use this to check user hasn't double submitted.
- def InfoRequestBatch.find_existing(user, title, body, public_body_ids)
+ def self.find_existing(user, title, body, public_body_ids)
find(:first, :conditions => ['user_id = ?
AND title = ?
AND body = ?
@@ -70,7 +70,7 @@ class InfoRequestBatch < ActiveRecord::Base
info_request
end
- def InfoRequestBatch.send_batches()
+ def self.send_batches
find_each(:conditions => "sent_at IS NULL") do |info_request_batch|
unrequestable = info_request_batch.create_batch!
mail_message = InfoRequestBatchMailer.batch_sent(info_request_batch,
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 285e54f9a..29c1ce965 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -326,9 +326,17 @@ class InfoRequestEvent < ActiveRecord::Base
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?
+ !self.incoming_message_selective_columns("incoming_messages.id").nil?
+ end
+
+ def is_outgoing_message?
+ !self.outgoing_message.nil?
+ end
+
+ def is_comment?
+ !self.comment.nil?
+ end
# Display version of status
def display_status
diff --git a/app/models/mail_server_log.rb b/app/models/mail_server_log.rb
index 1c69635f3..64a740e1d 100644
--- a/app/models/mail_server_log.rb
+++ b/app/models/mail_server_log.rb
@@ -26,7 +26,7 @@ class MailServerLog < ActiveRecord::Base
# Doesn't do anything if file hasn't been modified since it was last loaded.
# Note: If you do use rotated log files (rather than files named by date), at some
# point old loaded log lines will get deleted in the database.
- def MailServerLog.load_file(file_name)
+ def self.load_file(file_name)
is_gz = file_name.include?(".gz")
file_name_db = is_gz ? file_name.gsub(".gz", "") : file_name
@@ -63,23 +63,16 @@ class MailServerLog < ActiveRecord::Base
end
# Scan the file
- def MailServerLog.load_exim_log_data(f, done)
+ def self.load_exim_log_data(f, done)
order = 0
f.each do |line|
order = order + 1
emails = email_addresses_on_line(line)
- for email in emails
- info_request = InfoRequest.find_by_incoming_email(email)
- if info_request
- info_request.mail_server_logs.create!(:line => line, :order => order, :mail_server_log_done => done)
- else
- puts "Warning: Could not find request with email #{email}"
- end
- end
+ create_mail_server_logs(emails, line, order, done)
end
end
- def MailServerLog.load_postfix_log_data(f, done)
+ def self.load_postfix_log_data(f, done)
order = 0
emails = scan_for_postfix_queue_ids(f)
# Go back to the beginning of the file
@@ -88,19 +81,12 @@ class MailServerLog < ActiveRecord::Base
order = order + 1
queue_id = extract_postfix_queue_id_from_syslog_line(line)
if emails.has_key?(queue_id)
- emails[queue_id].each do |email|
- info_request = InfoRequest.find_by_incoming_email(email)
- if info_request
- info_request.mail_server_logs.create!(:line => line, :order => order, :mail_server_log_done => done)
- else
- puts "Warning: Could not find request with email #{email}"
- end
- end
+ create_mail_server_logs(emails[queue_id], line, order, done)
end
end
end
- def MailServerLog.scan_for_postfix_queue_ids(f)
+ def self.scan_for_postfix_queue_ids(f)
result = {}
f.each do |line|
emails = email_addresses_on_line(line)
@@ -112,7 +98,7 @@ class MailServerLog < ActiveRecord::Base
end
# Retuns nil if there is no queue id
- def MailServerLog.extract_postfix_queue_id_from_syslog_line(line)
+ def self.extract_postfix_queue_id_from_syslog_line(line)
# Assume the log file was written using syslog and parse accordingly
m = SyslogProtocol.parse("<13>" + line).content.match(/^\S+: (\S+):/)
m[1] if m
@@ -120,13 +106,13 @@ class MailServerLog < ActiveRecord::Base
# We also check the email prefix so that we could, for instance, separately handle a staging and production
# instance running on the same server with different email prefixes.
- def MailServerLog.email_addresses_on_line(line)
+ def self.email_addresses_on_line(line)
prefix = Regexp::quote(AlaveteliConfiguration::incoming_email_prefix)
domain = Regexp::quote(AlaveteliConfiguration::incoming_email_domain)
line.scan(/#{prefix}request-[^\s]+@#{domain}/).sort.uniq
end
- def MailServerLog.request_sent?(ir)
+ def self.request_sent?(ir)
case(AlaveteliConfiguration::mta_log_type.to_sym)
when :exim
request_exim_sent?(ir)
@@ -138,7 +124,7 @@ class MailServerLog < ActiveRecord::Base
end
# Look at the log for a request and check that an email was delivered
- def MailServerLog.request_exim_sent?(ir)
+ def self.request_exim_sent?(ir)
# Look for line showing request was sent
found = false
ir.mail_server_logs.each do |mail_server_log|
@@ -157,7 +143,7 @@ class MailServerLog < ActiveRecord::Base
found
end
- def MailServerLog.request_postfix_sent?(ir)
+ def self.request_postfix_sent?(ir)
# dsn=2.0.0 is the magic word that says that postfix delivered the email
# See http://tools.ietf.org/html/rfc3464
ir.mail_server_logs.any? { |l| l.line.include?("dsn=2.0.0") }
@@ -174,11 +160,11 @@ class MailServerLog < ActiveRecord::Base
# NB: There can be several emails involved in a request. This just checks that
# at least one of them has been succesfully sent.
#
- def MailServerLog.check_recent_requests_have_been_sent
+ def self.check_recent_requests_have_been_sent
# Get all requests sent for from 2 to 10 days ago. The 2 day gap is
# because we load mail server log lines via cron at best an hour after they
# are made)
- irs = InfoRequest.find(:all, :conditions => [ "created_at < ? and created_at > ? and user_id is not null", Time.now() - 2.day, Time.now() - 10.days ] )
+ irs = InfoRequest.find(:all, :conditions => [ "created_at < ? and created_at > ? and user_id is not null", Time.now - 2.day, Time.now - 10.days ] )
# Go through each request and check it
ok = true
@@ -193,7 +179,17 @@ class MailServerLog < ActiveRecord::Base
ok
end
-end
-
+ private
+ def self.create_mail_server_logs(emails, line, order, done)
+ emails.each do |email|
+ info_request = InfoRequest.find_by_incoming_email(email)
+ if info_request
+ info_request.mail_server_logs.create!(:line => line, :order => order, :mail_server_log_done => done)
+ else
+ puts "Warning: Could not find request with email #{email}"
+ end
+ end
+ end
+end
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index feec7cdd5..fec1cefb6 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -138,7 +138,7 @@ class PublicBody < ActiveRecord::Base
end
# Set the first letter on a public body or translation
- def PublicBody.set_first_letter(instance)
+ def self.set_first_letter(instance)
unless instance.name.nil? or instance.name.empty?
# we use a regex to ensure it works with utf-8/multi-byte
first_letter = Unicode.upcase instance.name.scan(/^./mu)[0]
@@ -334,7 +334,7 @@ class PublicBody < ActiveRecord::Base
end
# The "internal admin" is a special body for internal use.
- def PublicBody.internal_admin_body
+ def self.internal_admin_body
# Use find_by_sql to avoid the search being specific to a
# locale, since url_name is a translated field:
sql = "SELECT * FROM public_bodies WHERE url_name = 'internal_admin_authority'"
@@ -387,7 +387,7 @@ class PublicBody < ActiveRecord::Base
# matching names won't work afterwards, and we'll create new bodies instead
# of updating them
bodies_by_name = {}
- set_of_existing = Set.new()
+ set_of_existing = Set.new
internal_admin_body_id = PublicBody.internal_admin_body.id
I18n.with_locale(I18n.default_locale) do
bodies = (tag.nil? || tag.empty?) ? PublicBody.find(:all, :include => :translations) : PublicBody.find_by_tag(tag)
@@ -400,7 +400,7 @@ class PublicBody < ActiveRecord::Base
end
end
- set_of_importing = Set.new()
+ set_of_importing = Set.new
# Default values in case no field list is given
field_names = { 'name' => 1, 'request_email' => 2 }
line = 0
@@ -567,7 +567,7 @@ class PublicBody < ActiveRecord::Base
# Return the domain part of an email address, canonicalised and with common
# extra UK Government server name parts removed.
- def PublicBody.extract_domain_from_email(email)
+ def self.extract_domain_from_email(email)
email =~ /@(.*)/
if $1.nil?
return nil
diff --git a/app/models/public_body_category/category_collection.rb b/app/models/public_body_category/category_collection.rb
index 3938722c0..7d5732a82 100644
--- a/app/models/public_body_category/category_collection.rb
+++ b/app/models/public_body_category/category_collection.rb
@@ -14,19 +14,19 @@ class PublicBodyCategory::CategoryCollection
end
def with_description
- @categories.select() { |a| a.instance_of?(Array) }
+ @categories.select { |a| a.instance_of?(Array) }
end
def tags
- tags = with_description.map() { |a| a[0] }
+ tags = with_description.map { |a| a[0] }
end
def by_tag
- Hash[*with_description.map() { |a| a[0..1] }.flatten]
+ Hash[*with_description.map { |a| a[0..1] }.flatten]
end
def singular_by_tag
- Hash[*with_description.map() { |a| [a[0],a[2]] }.flatten]
+ Hash[*with_description.map { |a| [a[0],a[2]] }.flatten]
end
def by_heading
diff --git a/app/models/request_classification.rb b/app/models/request_classification.rb
index eccf610d7..ab0cd1f21 100644
--- a/app/models/request_classification.rb
+++ b/app/models/request_classification.rb
@@ -16,7 +16,7 @@ class RequestClassification < ActiveRecord::Base
# return classification instances representing the top n
# users, with a 'cnt' attribute representing the number
# of classifications the user has made.
- def RequestClassification.league_table(size, conditions=[])
+ def self.league_table(size, conditions=[])
find(:all, :select => 'user_id, count(*) as cnt',
:conditions => conditions,
:group => 'user_id',
diff --git a/app/models/user.rb b/app/models/user.rb
index bb40dbc26..d50000aba 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -198,7 +198,9 @@ class User < ActiveRecord::Base
end
def visible_comments
- comments.find(:all, :conditions => 'visible')
+ warn %q([DEPRECATION] User#visible_comments will be replaced with
+ User#comments.visible as of 0.23).squish
+ comments.visible
end
# Don't display any leading/trailing spaces
diff --git a/app/views/public_body/show.html.erb b/app/views/public_body/show.html.erb
index 016c2460d..9dd3dc7cb 100644
--- a/app/views/public_body/show.html.erb
+++ b/app/views/public_body/show.html.erb
@@ -42,12 +42,12 @@
</div>
<% end %>
- <% if @public_body.info_requests.size > 0 %>
+ <% if @number_of_visible_requests > 0 %>
<div class="authority__header__stats">
<%= n_('{{count}} request',
'{{count}} requests',
- @public_body.info_requests.size,
- :count => @public_body.info_requests.size) %>
+ @number_of_visible_requests,
+ :count => @number_of_visible_requests) %>
</div>
<% end %>
@@ -81,7 +81,7 @@
<div class="authority__body">
<div class="authority__body__foi-results">
- <% if @public_body.info_requests.size == 0 %>
+ <% if @number_of_visible_requests == 0 %>
<% if @public_body.is_requestable? or @public_body.not_requestable_reason != 'defunct' %>
<% if @public_body.eir_only? %>
<h2><%= _('Environmental Information Regulations requests made using this site') %></h2>
@@ -99,7 +99,7 @@
<% end %>
<a name="results"></a>
- <% if @public_body.info_requests.size > 4 %>
+ <% if @number_of_visible_requests > 4 %>
<%= render :partial => 'request/request_filter_form' %>
<% end %>
<% end %>
@@ -132,7 +132,7 @@
</div>
<div class="authority__body__sidebar">
- <% if @public_body.info_requests.size > 4 %>
+ <% if @number_of_visible_requests > 4 %>
<%= render :partial => 'request/request_search_form' %>
<% end %>
<%= render :partial => 'more_info', :locals => { :public_body => @public_body } %>
diff --git a/app/views/public_body_change_requests/new.html.erb b/app/views/public_body_change_requests/new.html.erb
index b52d583be..9abe03732 100644
--- a/app/views/public_body_change_requests/new.html.erb
+++ b/app/views/public_body_change_requests/new.html.erb
@@ -12,7 +12,7 @@
<p>
<label class="form_label" for="user_email">
- <%= ("Your email:") %>
+ <%= _("Your email:") %>
</label>
<%= f.text_field :user_email %>
</p>
diff --git a/app/views/user/_user_listing_single.html.erb b/app/views/user/_user_listing_single.html.erb
index 3cb0d283f..03ac7347b 100644
--- a/app/views/user/_user_listing_single.html.erb
+++ b/app/views/user/_user_listing_single.html.erb
@@ -17,7 +17,7 @@ end %>
<span class="bottomline">
<%= pluralize(display_user.info_requests.size, "request") %> <%= _('made.')%>
- <%= pluralize(display_user.visible_comments.size, "annotation") %> <%= _('made.')%>
+ <%= pluralize(display_user.comments.visible.size, "annotation") %> <%= _('made.')%>
<%= _('Joined in')%> <%= display_user.created_at.year %>.
</span>
diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb
index 78b513d6a..a67663389 100644
--- a/app/views/user/show.html.erb
+++ b/app/views/user/show.html.erb
@@ -173,7 +173,7 @@
<% end %>
<% else %>
<h2 id="annotations">
- <%= @is_you ? n_('Your {{count}} annotation', 'Your {{count}} annotations', @display_user.visible_comments.size, :count => @display_user.visible_comments.size) : n_("This person's {{count}} annotation", "This person's {{count}} annotations", @display_user.visible_comments.size, :count => @display_user.visible_comments.size) %>
+ <%= @is_you ? n_('Your {{count}} annotation', 'Your {{count}} annotations', @display_user.comments.visible.size, :count => @display_user.comments.visible.size) : n_("This person's {{count}} annotation", "This person's {{count}} annotations", @display_user.comments.visible.size, :count => @display_user.comments.visible.size) %>
<!-- matches_estimated <%=@xapian_comments.matches_estimated%> -->
<%= @page_desc %>
</h2>
@@ -182,7 +182,7 @@
<%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model] } %>
<% end %>
- <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @display_user.visible_comments.size) %>
+ <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @display_user.comments.visible.size) %>
<% end %>
<% end %>