From cd73e401622d31a189d8cf3b38e9cbe46ca73e96 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 3 Aug 2011 14:18:22 +0100 Subject: Fail silently if there's no user matching one referenced in the current session. Fixes #105 --- app/controllers/application_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5f18be2e5..ba1cf4900 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 -- cgit v1.2.3 From a3c00d25d1bf6dc9ef554a44809e732a96ec1533 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Mon, 8 Aug 2011 13:02:03 +0100 Subject: Ensure we use sensible fallbacks for setting the default / initial locale for a user. (Partially) fixes #114 --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ba1cf4900..2918f39c0 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -42,7 +42,7 @@ class ApplicationController < ActionController::Base end def set_gettext_locale - requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] + requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale session[:locale] = FastGettext.set_locale(requested_locale) end -- cgit v1.2.3 From d5e1fc1c612e8edf6c571d019cf68ba66b3bee64 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Mon, 8 Aug 2011 15:24:01 +0100 Subject: Introduce config setting to ignore browser language settings --- app/controllers/application_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2918f39c0..0d8c83d6c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -42,7 +42,11 @@ class ApplicationController < ActionController::Base end def set_gettext_locale - requested_locale = params[:locale] || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale + 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 -- cgit v1.2.3 From 2dd460cb432460fc32178140e3b4d6c31b55e883 Mon Sep 17 00:00:00 2001 From: David Cabo Date: Mon, 8 Aug 2011 13:22:47 +0200 Subject: I18n'd hardcoded WhatDoTheyKnow strings, mostly in mails. Use named variable substitution in gettext strings. --- app/controllers/application_controller.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'app/controllers/application_controller.rb') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0d8c83d6c..0df3e22da 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -53,11 +53,7 @@ class ApplicationController < ActionController::Base # 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/ @@ -280,7 +276,9 @@ class ApplicationController < ActionController::Base def check_read_only read_only = MySociety::Config.get('READ_ONLY', '') if !read_only.empty? - flash[:notice] = "

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.

" + read_only + "

" + flash[:notice] = _("

{{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.

{{read_only}}

", + :site_name => site_name, + :read_only => read_only) redirect_to frontpage_url end @@ -355,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 -- cgit v1.2.3