aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2011-08-22 14:11:02 +0100
committerSeb Bacon <seb.bacon@gmail.com>2011-08-22 14:19:05 +0100
commit5c3881bfacdb34a605ddfbadf1531d0e341d7beb (patch)
tree088e752d1a6d2fb38d1409dbfb1cb332af92594c /app/controllers
parent15a174375e638b91c138d771d4851613110f9cdc (diff)
parenta29b3aaf0ae77af49d38813b62dddcb6889c1ebe (diff)
merge from master and make tests pass
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin_general_controller.rb7
-rw-r--r--app/controllers/admin_public_body_controller.rb6
-rw-r--r--app/controllers/admin_request_controller.rb17
-rw-r--r--app/controllers/application_controller.rb25
-rw-r--r--app/controllers/general_controller.rb4
-rw-r--r--app/controllers/request_controller.rb57
-rw-r--r--app/controllers/request_game_controller.rb4
7 files changed, 70 insertions, 50 deletions
diff --git a/app/controllers/admin_general_controller.rb b/app/controllers/admin_general_controller.rb
index 5073cdc5b..ae51e0923 100644
--- a/app/controllers/admin_general_controller.rb
+++ b/app/controllers/admin_general_controller.rb
@@ -8,6 +8,13 @@
class AdminGeneralController < AdminController
def index
+ # ensure we have a trailing slash
+ current_uri = request.env['REQUEST_URI']
+ if params[:suppress_redirect].nil? && !(current_uri =~ /\/$/)
+ redirect_to admin_general_index_url + "/"
+ return
+ end
+
# Overview counts of things
@public_body_count = PublicBody.count
diff --git a/app/controllers/admin_public_body_controller.rb b/app/controllers/admin_public_body_controller.rb
index f88b25572..021122734 100644
--- a/app/controllers/admin_public_body_controller.rb
+++ b/app/controllers/admin_public_body_controller.rb
@@ -154,10 +154,10 @@ class AdminPublicBodyController < AdminController
else
raise "internal error, unknown button label"
end
-
+
# Try with dry run first
csv_contents = params[:csv_file].read
- en = PublicBody.import_csv(csv_contents, params[:tag], true, admin_http_auth_user())
+ en = PublicBody.import_csv(csv_contents, params[:tag], true, admin_http_auth_user(), I18n.available_locales)
errors = en[0]
notes = en[1]
@@ -166,7 +166,7 @@ class AdminPublicBodyController < AdminController
notes.push("Dry run was successful, real run would do as above.")
else
# And if OK, with real run
- en = PublicBody.import_csv(csv_contents, params[:tag], false, admin_http_auth_user())
+ en = PublicBody.import_csv(csv_contents, params[:tag], false, admin_http_auth_user(), available_locales)
errors = en[0]
notes = en[1]
if errors.size != 0
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index d5bd4c4d6..e5de4f8b7 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -177,7 +177,7 @@ class AdminRequestController < AdminController
raw_email_data = incoming_message.raw_email.data
mail = TMail::Mail.parse(raw_email_data)
mail.base64_decode
- destination_request.receive(mail, raw_email_data)
+ destination_request.receive(mail, raw_email_data, true)
incoming_message_id = incoming_message.id
incoming_message.fully_destroy
@@ -275,7 +275,6 @@ class AdminRequestController < AdminController
def show_raw_email
@raw_email = RawEmail.find(params[:id])
-
# For the holding pen, try to guess where it should be ...
@holding_pen = false
if (@raw_email.incoming_message.info_request == InfoRequest.holding_pen_request && !@raw_email.incoming_message.mail.from_addrs.nil? && @raw_email.incoming_message.mail.from_addrs.size > 0)
@@ -294,15 +293,11 @@ class AdminRequestController < AdminController
end
# 2. Match the email address in the message without matching the hash
- @info_requests = []
- addresses =
- (@raw_email.incoming_message.mail.to || []) +
- (@raw_email.incoming_message.mail.cc || []) +
- (@raw_email.incoming_message.mail.envelope_to || [])
- addresses.uniq!
- for address in addresses
- @info_requests += InfoRequest.guess_by_incoming_email(address)
- end
+ @info_requests = InfoRequest.guess_by_incoming_email(@raw_email.incoming_message)
+
+ # 3. Give a reason why it's in the holding pen
+ last_event = InfoRequestEvent.find_by_incoming_message_id(@raw_email.incoming_message.id)
+ @rejected_reason = last_event.params[:rejected_reason]
end
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 5f18be2e5..0df3e22da 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -42,18 +42,18 @@ class ApplicationController < ActionController::Base
end
def set_gettext_locale
- requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE']
+ if MySociety::Config.get('USE_DEFAULT_BROWSER_LANGUAGE', true)
+ requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale
+ else
+ requested_locale = params[:locale] || session[:locale] || cookies[:locale] || I18n.default_locale
+ end
session[:locale] = FastGettext.set_locale(requested_locale)
end
# scrub sensitive parameters from the logs
filter_parameter_logging :password
- helper_method :site_name, :locale_from_params
- def site_name
- site_name = MySociety::Config.get('SITE_NAME', 'Alaveteli')
- return site_name
- end
+ helper_method :locale_from_params
# Help work out which request causes RAM spike.
# http://www.codeweblog.com/rails-to-monitor-the-process-of-memory-leaks-skills/
@@ -221,7 +221,11 @@ class ApplicationController < ActionController::Base
if session[:user_id].nil?
return nil
else
- return User.find(session[:user_id])
+ begin
+ return User.find(session[:user_id])
+ rescue ActiveRecord::RecordNotFound
+ return nil
+ end
end
end
@@ -272,7 +276,9 @@ class ApplicationController < ActionController::Base
def check_read_only
read_only = MySociety::Config.get('READ_ONLY', '')
if !read_only.empty?
- flash[:notice] = "<p>WhatDoTheyKnow is currently in maintenance. You can only view existing requests. You cannot make new ones, add followups or annotations, or otherwise change the database.</p> <p>" + read_only + "</p>"
+ flash[:notice] = _("<p>{{site_name}} is currently in maintenance. You can only view existing requests. You cannot make new ones, add followups or annotations, or otherwise change the database.</p> <p>{{read_only}}</p>",
+ :site_name => site_name,
+ :read_only => read_only)
redirect_to frontpage_url
end
@@ -347,6 +353,9 @@ class ApplicationController < ActionController::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/controllers/general_controller.rb b/app/controllers/general_controller.rb
index ffc97237a..4fa603aab 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -63,7 +63,7 @@ class GeneralController < ApplicationController
end
end
- # Display WhatDoTheyKnow category from mySociety blog
+ # Display blog entries
def blog
medium_cache
@feed_autodetect = []
@@ -73,7 +73,7 @@ class GeneralController < ApplicationController
@data = XmlSimple.xml_in(content)
@channel = @data['channel'][0]
@blog_items = @channel['item']
- @feed_autodetect = [ { :url => feed_url, :title => "WhatDoTheyKnow blog"} ]
+ @feed_autodetect = [{:url => feed_url, :title => "#{site_name} blog"}]
else
@blog_items = []
end
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index e446854ab..c1a13273a 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -393,29 +393,31 @@ class RequestController < ApplicationController
flash[:notice] = _("<p>Thank you! Hope you don't have to wait much longer.</p> <p>By law, you should have got a response promptly, and normally before the end of <strong>{{date_response_required_by}}</strong>.</p>",:date_response_required_by=>simple_date(@info_request.date_response_required_by))
redirect_to request_url(@info_request)
elsif @info_request.calculate_status == 'waiting_response_very_overdue'
- flash[:notice] = _("<p>Thank you! Your request is long overdue, by more than 40 working days. Most requests should be answered within 20 working days. You might like to complain about this, see below.</p>")
+ flash[:notice] = _("<p>Thank you! Your request is long overdue, by more than {{very_late_number_of_days}} working days. Most requests should be answered within {{late_number_of_days}} working days. You might like to complain about this, see below.</p>", :very_late_number_of_days => MySociety::Config.get('REPLY_VERY_LATE_AFTER_DAYS', 40), :late_number_of_days => MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20))
redirect_to unhappy_url(@info_request)
elsif @info_request.calculate_status == 'not_held'
flash[:notice] = _("<p>Thank you! Here are some ideas on what to do next:</p>
<ul>
- <li>To send your request to another authority, first copy the text of your request below, then <a href=\"%s\">find the other authority</a>.</li>
+ <li>To send your request to another authority, first copy the text of your request below, then <a href=\"{{find_authority_url}}\">find the other authority</a>.</li>
<li>If you would like to contest the authority's claim that they do not hold the information, here is
- <a href=\"%s\">how to complain</a>.
+ <a href=\"{{complain_url}}\">how to complain</a>.
</li>
- <li>We have <a href=\"%s\">suggestions</a>
+ <li>We have <a href=\"{{other_means_url}}\">suggestions</a>
on other means to answer your question.
</li>
- </ul>
- ") % ["/new",CGI.escapeHTML(unhappy_url(@info_request)),CGI.escapeHTML(unhappy_url(@info_request)) + "#other_means"]
+ </ul>",
+ :find_authority_url => "/new",
+ :complain_url => CGI.escapeHTML(unhappy_url(@info_request)),
+ :other_means_url => CGI.escapeHTML(unhappy_url(@info_request)) + "#other_means")
redirect_to request_url(@info_request)
elsif @info_request.calculate_status == 'rejected'
flash[:notice] = _("Oh no! Sorry to hear that your request was refused. Here is what to do now.")
redirect_to unhappy_url(@info_request)
elsif @info_request.calculate_status == 'successful'
- flash[:notice] = _("<p>We're glad you got all the information that you wanted. If you write about or make use of the information, please come back and add an annotation below saying what you did.</p><p>If you found WhatDoTheyKnow useful, <a href=\"%s\">make a donation</a> to the charity which runs it.</p>") % ["http://www.mysociety.org/donate/"]
+ flash[:notice] = _("<p>We're glad you got all the information that you wanted. If you write about or make use of the information, please come back and add an annotation below saying what you did.</p><p>If you found {{site_name}} useful, <a href=\"{{donation_url}}\">make a donation</a> to the charity which runs it.</p>", :site_name=>site_name, :donation_url => "http://www.mysociety.org/donate/")
redirect_to request_url(@info_request)
elsif @info_request.calculate_status == 'partially_successful'
- flash[:notice] = _("<p>We're glad you got some of the information that you wanted. If you found WhatDoTheyKnow useful, <a href=\"%s\">make a donation</a> to the charity which runs it.</p><p>If you want to try and get the rest of the information, here's what to do now.</p>") % ["http://www.mysociety.org/donate/"]
+ flash[:notice] = _("<p>We're glad you got some of the information that you wanted. If you found {{site_name}} useful, <a href=\"{{donation_url}}\">make a donation</a> to the charity which runs it.</p><p>If you want to try and get the rest of the information, here's what to do now.</p>", :site_name=>site_name, :donation_url=>"http://www.mysociety.org/donate/")
redirect_to unhappy_url(@info_request)
elsif @info_request.calculate_status == 'waiting_clarification'
flash[:notice] = _("Please write your follow up message containing the necessary clarifications below.")
@@ -423,7 +425,7 @@ class RequestController < ApplicationController
elsif @info_request.calculate_status == 'gone_postal'
redirect_to respond_to_last_url(@info_request) + "?gone_postal=1"
elsif @info_request.calculate_status == 'internal_review'
- flash[:notice] = _("<p>Thank you! Hopefully your wait isn't too long.</p><p>You should get a response within 20 days, or be told if it will take longer (<a href=\"%s\">details</a>).</p>") % [unhappy_url(@info_request) + "#internal_review"]
+ flash[:notice] = _("<p>Thank you! Hopefully your wait isn't too long.</p><p>You should get a response within {{late_number_of_days}} days, or be told if it will take longer (<a href=\"{{review_url}}\">details</a>).</p>",:late_number_of_days => MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20), :review_url => unhappy_url(@info_request) + "#internal_review")
redirect_to request_url(@info_request)
elsif @info_request.calculate_status == 'error_message'
flash[:notice] = _("<p>Thank you! We'll look into what happened and try and fix it up.</p><p>If the error was a delivery failure, and you can find an up to date FOI email address for the authority, please tell us using the form below.</p>")
@@ -602,23 +604,29 @@ class RequestController < ApplicationController
# special caching code so mime types are handled right
around_filter :cache_attachments, :only => [ :get_attachment, :get_attachment_as_html ]
def cache_attachments
- key = params.merge(:only_path => true)
- key_path = foi_fragment_cache_path(key)
+ if !params[:skip_cache].nil?
+ yield
+ else
+ key = params.merge(:only_path => true)
+ key_path = foi_fragment_cache_path(key)
- if foi_fragment_cache_exists?(key_path)
- cached = foi_fragment_cache_read(key_path)
- response.content_type = AlaveteliFileTypes.filename_to_mimetype(params[:file_name].join("/")) || 'application/octet-stream'
- render_for_text(cached)
- return
- end
+ if foi_fragment_cache_exists?(key_path)
+ cached = foi_fragment_cache_read(key_path)
+ response.content_type = AlaveteliFileTypes.filename_to_mimetype(params[:file_name].join("/")) || 'application/octet-stream'
+ render_for_text(cached)
+ return
+ end
- yield
+ yield
- # write it to the fileystem ourselves, so is just a plain file. (The
- # various fragment cache functions using Ruby Marshall to write the file
- # which adds a header, so isnt compatible with images that have been
- # extracted elsewhere from PDFs)
- foi_fragment_cache_write(key_path, response.body)
+ if params[:skip_cache].nil?
+ # write it to the fileystem ourselves, so is just a plain file. (The
+ # various fragment cache functions using Ruby Marshall to write the file
+ # which adds a header, so isnt compatible with images that have been
+ # extracted elsewhere from PDFs)
+ foi_fragment_cache_write(key_path, response.body)
+ end
+ end
end
def get_attachment
@@ -647,7 +655,7 @@ class RequestController < ApplicationController
view_html_stylesheet = render_to_string :partial => "request/view_html_stylesheet"
html.sub!(/<head>/i, "<head>" + view_html_stylesheet)
- html.sub!(/<body[^>]*>/i, '<body><prefix-here><div id="' + wrapper_id + '"><div id="view_html_content">')
+ html.sub!(/<body[^>]*>/i, '<body><prefix-here><div id="' + wrapper_id + '"><div id="view-html-content">')
html.sub!(/<\/body[^>]*>/i, '</div></div></body>')
view_html_prefix = render_to_string :partial => "request/view_html_prefix"
@@ -655,7 +663,6 @@ class RequestController < ApplicationController
html.sub!("<attachment-url-here>", CGI.escape(@attachment_url))
@incoming_message.html_mask_stuff!(html)
-
response.content_type = 'text/html'
render :text => html
end
diff --git a/app/controllers/request_game_controller.rb b/app/controllers/request_game_controller.rb
index b9440a906..8a84575bb 100644
--- a/app/controllers/request_game_controller.rb
+++ b/app/controllers/request_game_controller.rb
@@ -20,7 +20,9 @@ class RequestGameController < ApplicationController
@requests = old.sort_by{ rand }.slice(0..2)
if @missing == 0
- flash[:notice] = _('<p>All done! Thank you very much for your help.</p><p>There are <a href="%s">more things you can do</a> to help WhatDoTheyKnow.</p>') % [help_credits_path+"#helpus"]
+ flash[:notice] = _('<p>All done! Thank you very much for your help.</p><p>There are <a href="{{helpus_url}}">more things you can do</a> to help {{site_name}}.</p>',
+ :helpus_url => help_credits_path+"#helpus",
+ :site_name => site_name)
end
@league_table_28_days = InfoRequestEvent.make_league_table(