diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/admin_controller.rb | 1 | ||||
| -rw-r--r-- | app/controllers/assets_controller.rb | 1 | ||||
| -rw-r--r-- | app/controllers/concerns/pinned_to_default_locale.rb | 22 | ||||
| -rw-r--r-- | app/controllers/events_controller.rb | 3 | ||||
| -rw-r--r-- | app/controllers/node_actions_controller.rb | 1 | ||||
| -rw-r--r-- | app/controllers/nodes_controller.rb | 7 | ||||
| -rw-r--r-- | app/controllers/otp_enrollments_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/related_assets_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/revisions_controller.rb | 1 | ||||
| -rw-r--r-- | app/controllers/users_controller.rb | 1 |
10 files changed, 34 insertions, 7 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 2b35fd20..3b8b3582 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | class AdminController < ApplicationController | 1 | class AdminController < ApplicationController |
| 2 | include PinnedToDefaultLocale | ||
| 2 | 3 | ||
| 3 | # Private | 4 | # Private |
| 4 | 5 | ||
diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index f1c259e3..988d56d1 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | class AssetsController < ApplicationController | 1 | class AssetsController < ApplicationController |
| 2 | include PinnedToDefaultLocale | ||
| 2 | 3 | ||
| 3 | # Private | 4 | # Private |
| 4 | 5 | ||
diff --git a/app/controllers/concerns/pinned_to_default_locale.rb b/app/controllers/concerns/pinned_to_default_locale.rb new file mode 100644 index 00000000..6c7fb900 --- /dev/null +++ b/app/controllers/concerns/pinned_to_default_locale.rb | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | # Chrome locale and content locale are separate concerns, and in the | ||
| 2 | # admin they must not touch. Globalize.locale falls back to | ||
| 3 | # I18n.locale when unset, so without this pin a visit to /en/admin | ||
| 4 | # would silently switch every Page and MenuItem read to its English | ||
| 5 | # translation. | ||
| 6 | # | ||
| 7 | # Translation editors are the exception and select their locale from | ||
| 8 | # params, not from the chrome. They nest their own | ||
| 9 | # Globalize.with_locale inside this one, which wins. | ||
| 10 | module PinnedToDefaultLocale | ||
| 11 | extend ActiveSupport::Concern | ||
| 12 | |||
| 13 | included do | ||
| 14 | around_action :pin_to_default_locale | ||
| 15 | end | ||
| 16 | |||
| 17 | private | ||
| 18 | |||
| 19 | def pin_to_default_locale | ||
| 20 | Globalize.with_locale(I18n.default_locale) { yield } | ||
| 21 | end | ||
| 22 | end | ||
diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index f2c710bd..a322181d 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | class EventsController < ApplicationController | 1 | class EventsController < ApplicationController |
| 2 | 2 | include PinnedToDefaultLocale | |
| 3 | |||
| 3 | # Private | 4 | # Private |
| 4 | 5 | ||
| 5 | before_action :login_required | 6 | before_action :login_required |
diff --git a/app/controllers/node_actions_controller.rb b/app/controllers/node_actions_controller.rb index 0f547732..f20bdb7d 100644 --- a/app/controllers/node_actions_controller.rb +++ b/app/controllers/node_actions_controller.rb | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | class NodeActionsController < ApplicationController | 1 | class NodeActionsController < ApplicationController |
| 2 | include PinnedToDefaultLocale | ||
| 2 | 3 | ||
| 3 | before_action :login_required | 4 | before_action :login_required |
| 4 | 5 | ||
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index 2a2cde33..4ac3d99a 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | class NodesController < ApplicationController | 1 | class NodesController < ApplicationController |
| 2 | include PinnedToDefaultLocale | ||
| 2 | 3 | ||
| 3 | # Private | 4 | # Private |
| 4 | 5 | ||
| @@ -18,8 +19,6 @@ class NodesController < ApplicationController | |||
| 18 | :restore_from_trash | 19 | :restore_from_trash |
| 19 | ] | 20 | ] |
| 20 | 21 | ||
| 21 | around_action :pin_to_default_locale, :only => [:show, :edit, :update, :autosave] | ||
| 22 | |||
| 23 | def index | 22 | def index |
| 24 | @nodes = Node.root.descendants.includes(:head, :draft) | 23 | @nodes = Node.root.descendants.includes(:head, :draft) |
| 25 | .order('id DESC') | 24 | .order('id DESC') |
| @@ -295,10 +294,6 @@ class NodesController < ApplicationController | |||
| 295 | end | 294 | end |
| 296 | end | 295 | end |
| 297 | 296 | ||
| 298 | def pin_to_default_locale | ||
| 299 | Globalize.with_locale(I18n.default_locale) { yield } | ||
| 300 | end | ||
| 301 | |||
| 302 | def descendant_counts_for(ordered_with_level) | 297 | def descendant_counts_for(ordered_with_level) |
| 303 | counts = Hash.new(0) | 298 | counts = Hash.new(0) |
| 304 | stack = [] # [node, level, index] | 299 | stack = [] # [node, level, index] |
diff --git a/app/controllers/otp_enrollments_controller.rb b/app/controllers/otp_enrollments_controller.rb index 54b82214..82fc98dc 100644 --- a/app/controllers/otp_enrollments_controller.rb +++ b/app/controllers/otp_enrollments_controller.rb | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | # an administrator must never hold another account's secret -- admins get | 2 | # an administrator must never hold another account's secret -- admins get |
| 3 | # the witnessed reset on the user page instead. | 3 | # the witnessed reset on the user page instead. |
| 4 | class OtpEnrollmentsController < ApplicationController | 4 | class OtpEnrollmentsController < ApplicationController |
| 5 | include PinnedToDefaultLocale | ||
| 6 | |||
| 5 | before_action :login_required | 7 | before_action :login_required |
| 6 | 8 | ||
| 7 | layout 'admin' | 9 | layout 'admin' |
diff --git a/app/controllers/related_assets_controller.rb b/app/controllers/related_assets_controller.rb index 3aa6d3db..ef6cbe56 100644 --- a/app/controllers/related_assets_controller.rb +++ b/app/controllers/related_assets_controller.rb | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | class RelatedAssetsController < ApplicationController | 1 | class RelatedAssetsController < ApplicationController |
| 2 | include PinnedToDefaultLocale | ||
| 3 | |||
| 2 | before_action :login_required | 4 | before_action :login_required |
| 3 | before_action :find_node | 5 | before_action :find_node |
| 4 | 6 | ||
diff --git a/app/controllers/revisions_controller.rb b/app/controllers/revisions_controller.rb index 9f920b03..cddb9e72 100644 --- a/app/controllers/revisions_controller.rb +++ b/app/controllers/revisions_controller.rb | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | class RevisionsController < ApplicationController | 1 | class RevisionsController < ApplicationController |
| 2 | include PinnedToDefaultLocale | ||
| 2 | 3 | ||
| 3 | # Private | 4 | # Private |
| 4 | 5 | ||
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 12531d86..cb71db23 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | class UsersController < ApplicationController | 1 | class UsersController < ApplicationController |
| 2 | include PinnedToDefaultLocale | ||
| 2 | 3 | ||
| 3 | # Private | 4 | # Private |
| 4 | 5 | ||
