Skip to content

Commit

Permalink
Merge d4204e6 into 5b9b61c
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-griffen committed Feb 26, 2024
2 parents 5b9b61c + d4204e6 commit b3a7025
Show file tree
Hide file tree
Showing 32 changed files with 105 additions and 236 deletions.
17 changes: 9 additions & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,26 @@ def long_cache
# required due to the I18nProxy used in Rails to trigger the
# lookup_context and expire the template cache
def set_gettext_locale
params_locale = params[:locale]

if AlaveteliConfiguration.include_default_locale_in_urls == false
params_locale ||= AlaveteliLocalization.default_locale
end

if AlaveteliConfiguration.use_default_browser_language
browser_locale = request.env['HTTP_ACCEPT_LANGUAGE']
end

locale = AlaveteliLocalization.set_session_locale(
params_locale, session[:locale], cookies[:locale], browser_locale
params[:locale],
current_user&.locale, # FIXME: Do we really want to use
# the user locale, or prioritise the session?
session[:locale],
cookies[:locale],
browser_locale,
AlaveteliLocalization.default_locale
)

# set the current locale to the requested_locale
session[:locale] = locale
response.headers['Content-Language'] = I18n.locale.to_s

# ensure current user locale attribute is up-to-date
current_user.update_column(:locale, locale) if current_user
current_user&.update_column(:locale, locale)
end

# Help work out which request causes RAM spike.
Expand Down
3 changes: 0 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,4 @@ def matches?(request)
:defaults => { :pro => '1' }
end
end
####

filter :conditionallyprependlocale
end
8 changes: 8 additions & 0 deletions config/routes/redirects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,11 @@
get '/:prefix/request/:url_title',
constraints: { prefix: 'categorise' },
to: info_request_redirect

get ':locale',
constraints: { locale: /(?!new|pro)[a-z]{2,3}(-[A-Z]{2,3}|_[A-Z1-9]{2,3})?/ },
to: redirect('?locale=%{locale}')

get ':locale/*path',
constraints: { locale: /(?!new|pro)[a-z]{2,3}(-[A-Z]{2,3}|_[A-Z1-9]{2,3})?/ },
to: redirect('%{path}?locale=%{locale}')
1 change: 1 addition & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Highlighted Features

* Remove locale prefixes from URLs (Alexander Griffen)
* Reduce amount of storage related background jobs (Graeme Porteous)
* Add automatic parsing of emails contain Excel spreadsheets (Graeme Porteous)
* Improve rendering of admin hidden request prominence and explanations (Graeme
Expand Down
10 changes: 0 additions & 10 deletions lib/alaveteli_localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@ def set_locales(available_locales, default_locale)

set_fast_gettext_locales(available, default)
set_i18n_locales(available, default)
set_conditionally_prepend_locale_locales(available, default)
end

def set_default_text_domain(name, repos)
FastGettext.add_text_domain name, type: :chain, chain: repos
FastGettext.default_text_domain = name
end

def set_default_locale_urls(include_default_locale_in_urls)
RoutingFilter::Locale.
include_default_locale = include_default_locale_in_urls
end

# rubocop:disable Naming/AccessorMethodName
def set_default_locale(locale)
locale = Locale.parse(locale)
Expand Down Expand Up @@ -95,10 +89,6 @@ def set_i18n_locales(available, default)
I18n.locale = I18n.default_locale = default.hyphenate.to_sym
end

def set_conditionally_prepend_locale_locales(available, _default)
RoutingFilter::Conditionallyprependlocale.locales = available.map(&:to_s)
end

# Parse String locales to Locale instances
def parse_locales(available_locales, default_locale)
[available_locales.to_s.split(/ /).map { |locale| Locale.parse(locale) },
Expand Down
4 changes: 0 additions & 4 deletions lib/alaveteli_localization/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ class Railtie < Rails::Railtie

I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)

AlaveteliLocalization.set_default_locale_urls(
AlaveteliConfiguration.include_default_locale_in_urls
)

if Rails.version < '7.0.0' && Rails.env.development?
##
# Ideally the following would only be called in the `after_initialize`
Expand Down
49 changes: 0 additions & 49 deletions lib/routing_filters.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,3 @@
module RoutingFilter
class Conditionallyprependlocale < RoutingFilter::Locale
# Override core Locale filter not to prepend locale path segment
# when there's only one locale
def prepend_locale?(locale)
locale &&
AlaveteliLocalization.available_locales.length > 1 &&
(self.class.include_default_locale? || !default_locale?(locale))
end

# And override the generation logic to use FastGettext.locale
# rather than I18n.locale (the latter is what rails uses
# internally and may look like `en-US`, whereas the former is
# what FastGettext and other POSIX-based systems use, and will
# look like `en_US`
def around_generate(*args)
# this is because we might get a call like forum_topics_path(forum, topic, :locale => :en)
params = args.extract_options!
# extract the passed :locale option
locale = params.delete(:locale)
if locale.nil?
# default to underscore locale when locale is nil (could also be false)
locale = AlaveteliLocalization.locale
end
unless valid_locale?(locale)
# reset to no locale when locale is not valid
locale = nil
end
args << params

yield.tap do |result|
next unless prepend_locale?(locale)

result.update prepend_segment(result.url, locale)
end
end

def default_locale?(locale)
AlaveteliLocalization.default_locale?(locale)
end

# Reset the locale pattern when the locales are set.
class << self
def locales_pattern
%r(^/(#{locales.map { |l| Regexp.escape(l.to_s) }.join('|')})(?=/|$))
end
end
end
end

ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper.class_eval do
def self.optimize_helper?(_route)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ We’ll attempt to bill your card again over the coming days.

If payment continues to fail, unfortunately your account will revert back to a free account, and you’ll no longer have access to Alaveteli Professional.

If you wish to preserve your access to Alaveteli Professional, please could you check that your card has sufficient funds, and that the card details are correct on your subscriptions page: http://test.host/en/profile/subscriptions
If you wish to preserve your access to Alaveteli Professional, please could you check that your card has sufficient funds, and that the card details are correct on your subscriptions page: http://test.host/profile/subscriptions

-- the Alaveteli Professional team
34 changes: 17 additions & 17 deletions spec/fixtures/files/notification_mailer/daily-summary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You have a new response to the Freedom of Information request 'The cost of paper

To view the response, click on the link below.

http://test.host/en/request/the_cost_of_paperclips?nocache=incoming-$THE_COST_OF_PAPERCLIPS_MOF_INCOMING_ID$#incoming-$THE_COST_OF_PAPERCLIPS_MOF_INCOMING_ID$
http://test.host/request/the_cost_of_paperclips?nocache=incoming-$THE_COST_OF_PAPERCLIPS_MOF_INCOMING_ID$#incoming-$THE_COST_OF_PAPERCLIPS_MOF_INCOMING_ID$


Thefts of stationary
Expand All @@ -19,11 +19,11 @@ You have a new response to the Freedom of Information request 'Thefts of station

To view the response, click on the link below.

http://test.host/en/request/thefts_of_stationary?nocache=incoming-$THEFTS_OF_STATIONARY_MIQ_INCOMING_ID$#incoming-$THEFTS_OF_STATIONARY_MIQ_INCOMING_ID$
http://test.host/request/thefts_of_stationary?nocache=incoming-$THEFTS_OF_STATIONARY_MIQ_INCOMING_ID$#incoming-$THEFTS_OF_STATIONARY_MIQ_INCOMING_ID$

This request will be made public on Alaveteli in the next week. If you do not wish this request to go public at that time, please click on the link below to keep it private for longer.

http://test.host/en/request/thefts_of_stationary
http://test.host/request/thefts_of_stationary


Missing staplers
Expand All @@ -32,7 +32,7 @@ Missing staplers
What's happened:
This request will be made public on Alaveteli in the next week. If you do not wish this request to go public at that time, please click on the link below to keep it private for longer.

http://test.host/en/request/missing_staplers
http://test.host/request/missing_staplers


Late expenses claims
Expand All @@ -41,7 +41,7 @@ Late expenses claims
What's happened:
Ministry of fact keeping have not replied to your FOI request Late expenses claims promptly, as normally required by law. Click on the link below to remind them to reply.

http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$LATE_EXPENSES_CLAIMS_MOF_URL_TITLE$%2Ffollowups%2Fnew
http://test.host/profile/sign_in?r=%2Frequest%2F$LATE_EXPENSES_CLAIMS_MOF_URL_TITLE$%2Ffollowups%2Fnew


Extremely late expenses claims
Expand All @@ -50,7 +50,7 @@ Extremely late expenses claims
What's happened:
Ministry of fact keeping have still not replied to your FOI request Extremely late expenses claims, as normally required by law. Click on the link below to tell them to reply. You might like to ask for an internal review, asking them to find out why their response to the request has been so slow.

http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$EXTREMELY_LATE_EXPENSES_CLAIMS_MOF_URL_TITLE$%2Ffollowups%2Fnew
http://test.host/profile/sign_in?r=%2Frequest%2F$EXTREMELY_LATE_EXPENSES_CLAIMS_MOF_URL_TITLE$%2Ffollowups%2Fnew


Misdelivered letters
Expand All @@ -59,7 +59,7 @@ Misdelivered letters
What's happened:
This request has been made public on Alaveteli.

http://test.host/en/request/misdelivered_letters
http://test.host/request/misdelivered_letters


Zero hours employees
Expand All @@ -72,8 +72,8 @@ Zero hours employees
What's happened:
2 requests had new responses:
You can see the responses with the following links:
Ministry of fact keeping: http://test.host/en/request/zero_hours_employees?nocache=incoming-$ZERO_HOURS_EMPLOYEES_MOF_INCOMING_ID$#incoming-$ZERO_HOURS_EMPLOYEES_MOF_INCOMING_ID$
Minor infractions quango: http://test.host/en/request/zero_hours_employees_2?nocache=incoming-$ZERO_HOURS_EMPLOYEES_2_MIQ_INCOMING_ID$#incoming-$ZERO_HOURS_EMPLOYEES_2_MIQ_INCOMING_ID$
Ministry of fact keeping: http://test.host/request/zero_hours_employees?nocache=incoming-$ZERO_HOURS_EMPLOYEES_MOF_INCOMING_ID$#incoming-$ZERO_HOURS_EMPLOYEES_MOF_INCOMING_ID$
Minor infractions quango: http://test.host/request/zero_hours_employees_2?nocache=incoming-$ZERO_HOURS_EMPLOYEES_2_MIQ_INCOMING_ID$#incoming-$ZERO_HOURS_EMPLOYEES_2_MIQ_INCOMING_ID$


Employees caught stealing stationary
Expand All @@ -85,8 +85,8 @@ Employees caught stealing stationary

What's happened:
2 requests will be made public on Alaveteli in the next week. If you do not wish these requests to go public at that time, please click on the links below to keep them private for longer.
Ministry of fact keeping: http://test.host/en/request/employees_caught_stealing_statio
Minor infractions quango: http://test.host/en/request/employees_caught_stealing_statio_2
Ministry of fact keeping: http://test.host/request/employees_caught_stealing_statio
Minor infractions quango: http://test.host/request/employees_caught_stealing_statio_2


Employee of the month awards
Expand All @@ -98,8 +98,8 @@ Employee of the month awards

What's happened:
2 requests have been made public on Alaveteli.
Ministry of fact keeping: http://test.host/en/request/employee_of_the_month_awards
Minor infractions quango: http://test.host/en/request/employee_of_the_month_awards_2
Ministry of fact keeping: http://test.host/request/employee_of_the_month_awards
Minor infractions quango: http://test.host/request/employee_of_the_month_awards_2


Late FOI requests
Expand All @@ -114,8 +114,8 @@ What's happened:

You can see the requests and remind the bodies to respond with the following links:

Ministry of fact keeping: http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$LATE_FOI_REQUESTS_MOF_URL_TITLE$%2Ffollowups%2Fnew
Minor infractions quango: http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$LATE_FOI_REQUESTS_2_MIQ_URL_TITLE$%2Ffollowups%2Fnew
Ministry of fact keeping: http://test.host/profile/sign_in?r=%2Frequest%2F$LATE_FOI_REQUESTS_MOF_URL_TITLE$%2Ffollowups%2Fnew
Minor infractions quango: http://test.host/profile/sign_in?r=%2Frequest%2F$LATE_FOI_REQUESTS_2_MIQ_URL_TITLE$%2Ffollowups%2Fnew


Ignored FOI requests
Expand All @@ -130,8 +130,8 @@ What's happened:

You can see the requests and tell the bodies to respond with the following links. You might like to ask for internal reviews, asking the bodies to find out why responses to the requests have been so slow.

Ministry of fact keeping: http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$IGNORED_FOI_REQUESTS_MOF_URL_TITLE$%2Ffollowups%2Fnew
Minor infractions quango: http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2F$IGNORED_FOI_REQUESTS_2_MIQ_URL_TITLE$%2Ffollowups%2Fnew
Ministry of fact keeping: http://test.host/profile/sign_in?r=%2Frequest%2F$IGNORED_FOI_REQUESTS_MOF_URL_TITLE$%2Ffollowups%2Fnew
Minor infractions quango: http://test.host/profile/sign_in?r=%2Frequest%2F$IGNORED_FOI_REQUESTS_2_MIQ_URL_TITLE$%2Ffollowups%2Fnew



Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The following request will be made public on Alaveteli in the next week. If you do not wish this request to go public at that time, please click on the link below to keep it private for longer.

http://test.host/en/request/here_is_a_character_that_needs_q
http://test.host/request/here_is_a_character_that_needs_q

-- the Alaveteli team
2 changes: 1 addition & 1 deletion spec/fixtures/files/notification_mailer/expire_embargo.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The following request has been made public on Alaveteli.

http://test.host/en/request/here_is_a_character_that_needs_q
http://test.host/request/here_is_a_character_that_needs_q

-- the Alaveteli team
2 changes: 1 addition & 1 deletion spec/fixtures/files/notification_mailer/new_response.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ You have a new response to the Freedom of Information request 'Here is a charact

To view the response, click on the link below.

http://test.host/en/request/here_is_a_character_that_needs_q?nocache=incoming-INCOMING_MESSAGE_ID#incoming-INCOMING_MESSAGE_ID
http://test.host/request/here_is_a_character_that_needs_q?nocache=incoming-INCOMING_MESSAGE_ID#incoming-INCOMING_MESSAGE_ID

When you get there, please update the status to say if the response contains any useful information.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ You have a new response to the Freedom of Information request 'Here is a charact

To view the response, click on the link below.

http://test.host/en/profile/sign_in?r=http%3A%2F%2Ftest.host%2Fen%2Frequest%2Fhere_is_a_character_that_needs_q%3Fnocache%3Dincoming-INCOMING_MESSAGE_ID%23incoming-INCOMING_MESSAGE_ID
http://test.host/profile/sign_in?r=http%3A%2F%2Ftest.host%2Frequest%2Fhere_is_a_character_that_needs_q%3Fnocache%3Dincoming-INCOMING_MESSAGE_ID%23incoming-INCOMING_MESSAGE_ID

When you get there, please update the status to say if the response contains any useful information.

Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/notification_mailer/overdue.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ They have not replied to your FOI request Here is a character that needs quoting

Click on the link below to send a message to Test public body reminding them to reply to your request.

http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2FINFO_REQUEST_URL_TITLE%2Ffollowups%2Fnew
http://test.host/profile/sign_in?r=%2Frequest%2FINFO_REQUEST_URL_TITLE%2Ffollowups%2Fnew


-- the Alaveteli team
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/files/notification_mailer/very_overdue.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ They have still not replied to your FOI request Here is a character that needs q

Click on the link below to send a message to Test public body telling them to reply to your request. You might like to ask for an internal review, asking them to find out why their response to the request has been so slow.

http://test.host/en/profile/sign_in?r=%2Fen%2Frequest%2FINFO_REQUEST_URL_TITLE%2Ffollowups%2Fnew
http://test.host/profile/sign_in?r=%2Frequest%2FINFO_REQUEST_URL_TITLE%2Ffollowups%2Fnew

-- the Alaveteli team
13 changes: 2 additions & 11 deletions spec/helpers/link_to_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,6 @@
RoutingFilter.active = @was_routing_filter_active
end

it 'prepends current path with new locale' do
allow(controller).to receive(:params).and_return(
ActionController::Parameters.new(
controller: 'public_body', action: 'show',
url_name: 'welsh_government', view: 'all'
)
)
expect(current_path_with_locale('cy')).to eq '/cy/body/welsh_government'
end

it 'ignores current protocol and host' do
allow(controller).to receive(:params).and_return(
ActionController::Parameters.new(
Expand All @@ -252,7 +242,8 @@
protocol: 'http', host: 'example.com'
)
)
expect(current_path_with_locale('cy')).to eq '/cy/body/welsh_government'
expect(current_path_with_locale('cy')).
to eq '/body/welsh_government?locale=cy'
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/public_body_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
)
public_body = FactoryBot.create(:public_body, tag_string: 'spec')

anchor = %Q(<a href="/es/body/list/spec">Spec category</a>)
anchor = %Q(<a href="/body/list/spec">Spec category</a>)
AlaveteliLocalization.with_locale(:es) do
expect(type_of_authority(public_body)).to eq(anchor)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/integration/alaveteli_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ def using_pro_session(session_id)
def login(user, **params)
u = user.is_a?(User) ? user : users(user)
alaveteli_session(u.id) do
visit signin_path(locale: 'en', **params)
visit signin_path(**params)
within '#signin_form' do
fill_in "Your e-mail:", with: u.email
fill_in "Password:", with: "jonespassword"
click_button "Sign in"
fill_in "user_signin_email", with: u.email
fill_in "user_signin_password", with: "jonespassword"
find("input[name='commit']", visible: true).click
end
end
u.id
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/change_email_address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Check confirmation URL works
visit confirmation_url_from_email
expect(page).to have_current_path("/en/user/#{user.url_name}")
expect(page).to have_current_path("/user/#{user.url_name}")
expect(page).to have_content('You have now changed your email address')
user.reload
expect(user.email).to eq('newbob@localhost')
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/errors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

it 'should assign the locale for the general/exception_caught template' do
allow(InfoRequest).to receive(:find_by_url_title!).and_raise("An example error")
get "/es/request/example"
get "/request/example?locale=es"
expect(response).to render_template('general/exception_caught')
expect(response.body).to match('Lo sentimos, hubo un problema procesando esta página')
end
Expand Down

0 comments on commit b3a7025

Please sign in to comment.