Commit Graph

4 Commits

Author SHA1 Message Date
Senén Rodero Rodríguez
c263a6fc2f Configure Rails/I18nLocaleAssignment cop to scan all Ruby files
This cop scans only the tests files by default, but we prefer to scan all
application Ruby files, so when a developer uses the class method
`I18n.locale=`, the cop will embrace using the method
`I18n.with_locale` instead. By doing this way, the cop will help
developers to avoid unexpected translation errors.

Quoting the Rails 6 guides:
> I18n.locale can leak into subsequent requests served by the same
thread/process if it is not consistently set in every controller. For
example executing I18n.locale = :es in one POST requests will have
effects for all later requests to controllers that don't set the locale,
but only in that particular thread/process. For that reason, instead of
I18n.locale = you can use I18n.with_locale which does not have this
leak issue.

Now we enabled the cop for all application Ruby files; we have to
remove the assignments at the controller level to set the request
locale. As Rails 6 guides suggest [1], we can use the `around_action`
controller callback to set each request locale without breaking the
rule.

This cop will warn CONSUL developers when using `I18n.locale`
assignment embracing them to use the `I18n.with_locale`instead.

[1] https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests
2022-06-13 15:45:32 +02:00
taitus
8b9f478e81 Render the page in the user's preferred locale
We add new method set_user_locale to render the page
with the user's preferred locale.

Note that we add a condition 'if params[:locale].blank?'
to recover the user's preferred locale. This is necessary
because it may be the case that the user does not have an
associated locale, and when execute '@user.locale' when
this value is 'nil', by default returns the default locale.
As we do not want this to happen and we want the locale we
receive as parameter to prevail in this case.
2022-01-21 20:21:52 +01:00
taitus
2bfdc421ae Allow updating the status of notifications
You can update the same "notifications" section that we allow you to
update in "my account".

This "subscriptions" section differs from the "my account" section
because we do not need to be logged in to update the status of the
notifications.
2022-01-21 20:21:38 +01:00
taitus
6d9e4a9330 Allow users to manage their notifications
The user can access this page without being logged in.
We identify the user through the "subscriptions_token" parameter and
show a list of the notifications that can be enable/disable.

We will return a 404 error in case someone accesses the page with a
non-existent token.

We also control the case that some anonymous user tries to access the
page without any token, by returning the CanCan::AccessDenied exception.
2022-01-21 18:58:38 +01:00