Skip to content

Commit

Permalink
Merge branch 'hotfix/0.29.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
crowbot committed Sep 26, 2017
2 parents fc83ca1 + 88451d6 commit 7bad890
Show file tree
Hide file tree
Showing 51 changed files with 847 additions and 292 deletions.
6 changes: 3 additions & 3 deletions app/controllers/admin_public_body_categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AdminPublicBodyCategoriesController < AdminController
before_filter :set_public_body_category, :only => [:edit, :update, :destroy]

def index
@locale = I18n.locale.to_s
@locale = AlaveteliLocalization.locale
@category_headings = PublicBodyHeading.by_display_order
@without_heading = PublicBodyCategory.without_headings
end
Expand All @@ -17,7 +17,7 @@ def new
end

def create
I18n.with_locale(I18n.default_locale) do
AlaveteliLocalization.with_locale(AlaveteliLocalization.default_locale) do
@public_body_category = PublicBodyCategory.new(public_body_category_params)
if @public_body_category.save
# FIXME: This can't handle failure (e.g. if a PublicBodyHeading
Expand Down Expand Up @@ -46,7 +46,7 @@ def update

heading_ids = []

I18n.with_locale(I18n.default_locale) do
AlaveteliLocalization.with_locale(AlaveteliLocalization.default_locale) do
if params[:public_body_category][:category_tag] && PublicBody.find_by_tag(@public_body_category.category_tag).count > 0 && @public_body_category.category_tag != params[:public_body_category][:category_tag]
flash[:error] = "There are authorities associated with this category, so the tag can't be renamed"
render :action => 'edit'
Expand Down
166 changes: 84 additions & 82 deletions app/controllers/admin_public_body_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def index
end

def show
@locale = I18n.locale.to_s
I18n.with_locale(@locale) do
@locale = AlaveteliLocalization.locale
AlaveteliLocalization.with_locale(@locale) do
@public_body = PublicBody.find(params[:id])
info_requests = @public_body.info_requests.order('created_at DESC')
if cannot? :admin, AlaveteliPro::Embargo
Expand Down Expand Up @@ -47,7 +47,7 @@ def new
end

def create
I18n.with_locale(I18n.default_locale) do
AlaveteliLocalization.with_locale(AlaveteliLocalization.default_locale) do
if params[:change_request_id]
@change_request = PublicBodyChangeRequest.find(params[:change_request_id])
end
Expand Down Expand Up @@ -89,7 +89,7 @@ def update
if params[:change_request_id]
@change_request = PublicBodyChangeRequest.find(params[:change_request_id])
end
I18n.with_locale(I18n.default_locale) do
AlaveteliLocalization.with_locale(AlaveteliLocalization.default_locale) do
params[:public_body][:last_edit_editor] = admin_current_user
if @public_body.update_attributes(public_body_params)
if @change_request
Expand Down Expand Up @@ -173,12 +173,13 @@ def import_csv
end
if !csv_contents.nil?
# Try with dry run first
errors, notes = PublicBody.import_csv(csv_contents,
params[:tag],
params[:tag_behaviour],
true,
admin_current_user,
FastGettext.default_available_locales)
errors, notes = PublicBody.
import_csv(csv_contents,
params[:tag],
params[:tag_behaviour],
true,
admin_current_user,
AlaveteliLocalization.available_locales)

if errors.size == 0
if dry_run_only
Expand All @@ -187,12 +188,14 @@ def import_csv
@temporary_csv_file = store_csv_data(csv_contents)
else
# And if OK, with real run
errors, notes = PublicBody.import_csv(csv_contents,
params[:tag],
params[:tag_behaviour],
false,
admin_current_user,
FastGettext.default_available_locales)
errors, notes = PublicBody.
import_csv(csv_contents,
params[:tag],
params[:tag_behaviour],
false,
admin_current_user,
AlaveteliLocalization.
available_locales)
if errors.size != 0
raise "dry run mismatched real run"
end
Expand Down Expand Up @@ -222,80 +225,79 @@ def store_csv_data(csv_contents)
# Delete the file, return the contents.
def retrieve_csv_data(tempfile_name)
if not /csv_upload-\d{8}-\d{1,5}/.match(tempfile_name)
raise "Invalid filename in upload_csv: #{tempfile_name}"
end
tempfile_path = File.join(Dir::tmpdir, tempfile_name)
if ! File.exist?(tempfile_path)
raise "Missing file in upload_csv: #{tempfile_name}"
end
csv_contents = File.read(tempfile_path)
File.delete(tempfile_path)
return csv_contents
raise "Invalid filename in upload_csv: #{tempfile_name}"
end
tempfile_path = File.join(Dir.tmpdir, tempfile_name)
if !File.exist?(tempfile_path)
raise "Missing file in upload_csv: #{tempfile_name}"
end
csv_contents = File.read(tempfile_path)
File.delete(tempfile_path)
return csv_contents
end

def lookup_query
@locale = I18n.locale.to_s
underscore_locale = @locale.gsub '-', '_'
I18n.with_locale(@locale) do
@query = params[:query]
if @query == ""
@query = nil
end
@page = params[:page]
if @page == ""
@page = nil
end

query = if @query
query_str = <<-EOF.strip_heredoc
(lower(public_body_translations.name)
LIKE lower('%'||?||'%')
OR lower(public_body_translations.short_name)
LIKE lower('%'||?||'%')
OR lower(public_body_translations.request_email)
LIKE lower('%'||?||'%' ))
AND (public_body_translations.locale = '#{underscore_locale}')
EOF

[query_str, @query, @query, @query]
else
<<-EOF.strip_heredoc
public_body_translations.locale = '#{underscore_locale}'
EOF
end

@public_bodies =
PublicBody.
joins(:translations).
where(query).
order('public_body_translations.name').
paginate(:page => @page, :per_page => 100)
end
def lookup_query
@locale = AlaveteliLocalization.locale
AlaveteliLocalization.with_locale(@locale) do
@query = params[:query]
if @query == ""
@query = nil
end
@page = params[:page]
if @page == ""
@page = nil
end

@public_bodies_by_tag = PublicBody.find_by_tag(@query)
end
query = if @query
query_str = <<-EOF.strip_heredoc
(lower(public_body_translations.name)
LIKE lower('%'||?||'%')
OR lower(public_body_translations.short_name)
LIKE lower('%'||?||'%')
OR lower(public_body_translations.request_email)
LIKE lower('%'||?||'%' ))
AND (public_body_translations.locale = '#{@locale}')
EOF

def public_body_params
if public_body_params = params[:public_body]
keys = { :translated_keys => [:locale,
:name,
:short_name,
:request_email,
:publication_scheme,
:notes],
:general_keys => [:tag_string,
:home_page,
:disclosure_log,
:last_edit_comment,
:last_edit_editor] }
translatable_params(keys, public_body_params)
[query_str, @query, @query, @query]
else
{}
<<-EOF.strip_heredoc
public_body_translations.locale = '#{@locale}'
EOF
end

@public_bodies =
PublicBody.
joins(:translations).
where(query).
order('public_body_translations.name').
paginate(:page => @page, :per_page => 100)
end

def set_public_body
@public_body = PublicBody.find(params[:id])
@public_bodies_by_tag = PublicBody.find_by_tag(@query)
end

def public_body_params
if public_body_params = params[:public_body]
keys = { :translated_keys => [:locale,
:name,
:short_name,
:request_email,
:publication_scheme,
:notes],
:general_keys => [:tag_string,
:home_page,
:disclosure_log,
:last_edit_comment,
:last_edit_editor] }
translatable_params(keys, public_body_params)
else
{}
end
end

def set_public_body
@public_body = PublicBody.find(params[:id])
end

end
4 changes: 2 additions & 2 deletions app/controllers/admin_public_body_headings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def new
end

def create
I18n.with_locale(I18n.default_locale) do
AlaveteliLocalization.with_locale(AlaveteliLocalization.default_locale) do
@public_body_heading = PublicBodyHeading.new(public_body_heading_params)
if @public_body_heading.save
flash[:notice] = 'Heading was successfully created.'
Expand All @@ -28,7 +28,7 @@ def edit
end

def update
I18n.with_locale(I18n.default_locale) do
AlaveteliLocalization.with_locale(AlaveteliLocalization.default_locale) do
if @public_body_heading.update_attributes(public_body_heading_params)
flash[:notice] = 'Heading was successfully updated.'
redirect_to edit_admin_heading_path(@public_body_heading)
Expand Down
35 changes: 21 additions & 14 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,32 @@ def long_cache
anonymous_cache(24.hours)
end

# This is an override of the method provided by gettext_i18n_rails - note the explicit
# setting of I18n.locale, required due to the I18nProxy used in Rails 3 to trigger the
# This is an override of the method provided by gettext_i18n_rails.
# AlaveteliLocalization.set_session_locale explicitly sets I18n.locale,
# required due to the I18nProxy used in Rails to trigger the
# lookup_context and expire the template cache
def set_gettext_locale
if AlaveteliConfiguration::include_default_locale_in_urls == false
params_locale = params[:locale] ? params[:locale] : I18n.default_locale
if AlaveteliConfiguration.include_default_locale_in_urls == false
params_locale = params.fetch(:locale) do
AlaveteliLocalization.default_locale
end
else
params_locale = params[:locale]
end
if AlaveteliConfiguration::use_default_browser_language
requested_locale = params_locale || session[:locale] || cookies[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'] || I18n.default_locale
browser_locale = if AlaveteliConfiguration.use_default_browser_language
request.env['HTTP_ACCEPT_LANGUAGE']
else
requested_locale = params_locale || session[:locale] || cookies[:locale] || I18n.default_locale
nil
end
requested_locale = FastGettext.best_locale_in(requested_locale)
session[:locale] = I18n.locale = FastGettext.set_locale(requested_locale)
AlaveteliLocalization.set_session_locale(params_locale,
session[:locale],
cookies[:locale],
browser_locale)
# set the currrent locale to the requested_locale
session[:locale] = AlaveteliLocalization.locale
if !@user.nil?
if @user.locale != requested_locale
@user.locale = session[:locale]
if @user.locale != AlaveteliLocalization.locale
@user.locale = AlaveteliLocalization.locale
@user.save!
end
end
Expand Down Expand Up @@ -513,9 +520,9 @@ def sanitize_path(params)
#
# Returns a Hash
def collect_locales
@locales = { :current => FastGettext.locale, :available => [] }
FastGettext.default_available_locales.map(&:to_s).each do |possible_locale|
if possible_locale == FastGettext.locale
@locales = { :current => AlaveteliLocalization.locale, :available => [] }
AlaveteliLocalization.available_locales.each do |possible_locale|
if possible_locale == AlaveteliLocalization.locale
@locales[:current] = possible_locale
else
@locales[:available] << possible_locale
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/general_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GeneralController < ApplicationController
# New, improved front page!
def frontpage
medium_cache
@locale = I18n.locale.to_s
@locale = AlaveteliLocalization.locale
successful_query = InfoRequestEvent.make_query_from_params( :latest_status => ['successful'] )
@request_events, @request_events_all_successful = InfoRequest.recent_requests
@track_thing = TrackThing.create_track_for_search_query(successful_query)
Expand Down Expand Up @@ -47,7 +47,8 @@ def get_blog_content
@feed_autodetect = []
@feed_url = AlaveteliConfiguration::blog_feed
separator = @feed_url.include?('?') ? '&' : '?'
@feed_url = "#{@feed_url}#{separator}lang=#{I18n.locale}"
@feed_url = "#{ @feed_url }#{ separator }lang=" \
"#{ AlaveteliLocalization.html_lang }"
@blog_items = []
if not @feed_url.empty?
timeout = if AlaveteliConfiguration.blog_timeout.blank?
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/public_body_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def show
return
end

@locale = I18n.locale.to_s
@locale = AlaveteliLocalization.locale

I18n.with_locale(@locale) do
AlaveteliLocalization.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?

Expand Down Expand Up @@ -99,7 +99,7 @@ def view_email
@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(I18n.locale.to_s) do
AlaveteliLocalization.with_locale(AlaveteliLocalization.locale) do
if params[:submitted_view_email]
if verify_recaptcha
flash.discard(:error)
Expand All @@ -124,9 +124,9 @@ def list
@tag = params[:tag]

@country_code = AlaveteliConfiguration.iso_country_code
@locale = I18n.locale.to_s
underscore_locale = @locale.gsub '-', '_'
underscore_default_locale = I18n.default_locale.to_s.gsub '-', '_'
@locale = AlaveteliLocalization.locale
underscore_locale = AlaveteliLocalization.locale
underscore_default_locale = AlaveteliLocalization.default_locale

where_condition = "public_bodies.id <> #{PublicBody.internal_admin_body.id}"
where_parameters = []
Expand Down Expand Up @@ -158,7 +158,7 @@ def list
where_parameters.concat [@tag]
end

I18n.with_locale(@locale) do
AlaveteliLocalization.with_locale(@locale) do

if AlaveteliConfiguration::public_body_list_fallback_to_default_locale
# Unfortunately, when we might fall back to the
Expand Down
Loading

0 comments on commit 7bad890

Please sign in to comment.