Commit Graph

78 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
Javi Martín
b98244afd9 Remove votes query optimizations
Just like we did in commit 0214184b2d for investments, we're removing
some possible optimizations (we don't have any benchmarks proving they
affect performance at all) in order to simplify the code.

The investement votes component `delegate` code was accidentally left
but isn't used since commit 0214184b2, so we're removing it now that
we're removing the `voted_for?` helper method.
2022-02-21 18:47:13 +01:00
Javi Martín
6bd20ef5ff Extract concern to handle investments filters
We were defining the same filters in three different controllers. We
were also adding a method in the ApplicationController which only made
sense in the same three controllers.
2021-03-15 13:31:28 +01:00
Javi Martín
305bf9161c Enable forgery protection in ActionController
We were manually adding forgery protection to all our controllers, but
in Rails 5.2 there's an option (enabled by default for new applications)
which adds this protection to all controllers.
2020-10-15 14:57:42 +02:00
Javi Martín
83e4633643 Don't redirect to POST request URLs after sign out
Sometimes we define URLs for POST requests which are not defined for GET
requests, such as "/residence", so redirecting to it after signing out
results in a routing error.

So instead of using the request referer, we're using the stored location
devise uses, and we're not storing locations in POST requests.
2020-08-11 18:19:48 +02:00
Javi Martín
2fa8792a35 Redirect users in homepage to homepage after login
For reasons I'm not sure about, the homepage (and the welcome pages)
were an exception in our "redirect users to the same page they were"
policy.

I'm not sure about the welcome pages (no test was present indicating
they should behave in a special way), but in the case of the home page,
it was a bit annoying to be redirected to a different place after
signing in.
2020-08-11 18:19:27 +02:00
Andriy Iun
1ee750e042 Keep GET params in return URL
When signing in from a page containing GET params, like
`/budgets/1/investments?heading_id=4`, we were redirected to a URL
without those GET params; in this case, `/budgets/1/investments`.

Using the request fullpath, as recommended in the devise documentation,
keeps these parameters when redirecting.
2020-08-11 18:19:25 +02:00
taitus
3b5a96bdfd Refactor set_locale
Add new current_locale method to simplify logic
2020-06-25 19:53:48 +02:00
taitus
ee5ac25cb1 Improve set_locale
We discard session[:locale] as valid locale when it is no longer include in
the :available_locales
2020-06-25 19:45:56 +02:00
Javi Martín
002e9239d0 Simplify code involving Globalize.locale
We don't need to set this value. In commit f2ef27d3 I made a mistake
thinking `Globalize.locale` and `I18n.locale` should always be in sync,
but they're actually automatically in sync when `Globalize.locale` is
`nil`.

So the best way to avoid any issues is not to assign `Globalize.locale`,
and use `Globalize.with_locale` where necessary instead.
2020-06-25 19:37:57 +02:00
Javi Martín
50bdfd5488 Avoid redirects with unprotected query params
In theory it's possible to add a `host` parameter to a URL, and we could
end up redirecting to that host if we just redirect using query
parameters.

Generating the path using `url_for` with `only_path` solves the issue.

Note in the tests I'm using the `get` method because the `patch` method
wouldn't send query parameters. This doesn't mean the action can be
accessed through GET requests, since controller tests don't check route
verbs. Using feature specs doesn't seem to work because `controller` and
`host` parameters are filtered automatically in feature specs.

Also note I'm not testing every hidden/moderation controller because
they basically use the same code.
2019-11-12 19:27:58 +01:00
Javi Martín
667797161b Extract method to redirect keeping query params 2019-11-12 19:27:58 +01:00
Javi Martín
ea2aeab383 Apply rubocop Rails/FindBy rule everywhere
We didn't detect these cases because by default the rule only searches
for offenses in `app/models/`.
2019-11-08 19:15:04 +01:00
Javi Martín
ed223e0bd1 Use audited to track investment changes
Our manual implementation had a few issues. In particular, it didn't
track changes related to associations, which became more of an issue
when we made investments translatable.

Using audited gives us more functionality while at the same time
simplifies our code. However, it adds one more external dependency to
our project.

The reason for choosing audited over paper trail is audited seems to
make it easier to handle associations.
2019-11-05 13:02:37 +01:00
Javi Martín
ae6fab9f5e Inherit from builder instead of monkey patching it
We were monkey-patching FoundationRailsHelper::Formbuilder, which made
form customization difficult. We can inherit from it, which is the
standard way of extending what an existing class does, and make our form
the default one.
2019-10-05 16:01:58 +02:00
Javi Martín
9fe8c47528 Apply Rails/SafeNavigation rubocop rule 2019-09-10 21:43:39 +02:00
Senén Rodero Rodríguez
8c2f1b894d Add controller concern to initialize Globalize fallbacks
Ensure to initialize all requests including this concern into all
application base controllers.
2019-06-27 09:20:24 +02:00
German Galia
16ffa2a259 Add change log in investment participatory budget 2019-06-12 13:06:20 +02:00
voodoorai2000
d0b8fef6b3 Delete spending proposals 2019-05-31 18:22:59 +02:00
Javi Martín
286e0ca878 Handle AccessDenied in management sessions
We were raising a `CanCan::AcessDenied` and were getting a 500 Internal
Server Error.

I've chosen to do the same thing we do in the ApplicationController.
There are other options to handle this request, like redirecting to the
login page or returning a 401 Unauthorized HTTP status.
2019-04-25 20:36:50 +02:00
Juanjo Bazán
c63c06b7ec protect_from_forgery is not prepended by default
so it has to appear before devise's auth methods
2019-04-25 14:22:19 +02:00
Senén Rodero Rodríguez
97974a8bc7 Set globalize fallbacks for requests
New version of globalize uses RequestStore gem to store I18n.locale and
Globalize.fallbacks in a per request basis to avoid collissions between
different requests. This gem update broke Globalize.fallback results
because it tries to fetch fallbacks from RequestStore, where there is no
locale fallbacks definition.
2019-04-17 17:40:57 +02:00
Julian Herrero
d24376f6ad Use double quotes in controllers/ 2019-03-13 22:19:49 +01:00
Julian Herrero
c9522b424b Show unfeasible and unselected investments for finished budgets
We were filtering by winners investments for finished budget without
having in consideration other filters.
We want the default filter to be `winners` for finished budgets.
2019-02-06 13:50:50 +01:00
Javier Martín
f2ef27d3ae Always set Globalize.locale after I18n.locale.
The test "Budget Investments Show milestones" was failing in certain
cases where `Globalize.locale` had been changed in a previous test.

Since having different values in `Globalize.locale` and `I18n.locale`
has proven to be an issue on the test enviroment, this commit also
changes application code in order to avoid similar situations on
production.

See issue #2718.
2018-07-03 00:52:20 +02:00
María Checa
1169c10907 Add condition to show only selected investments in publishing_prices phase 2018-05-29 08:40:32 -04:00
rgarcia
be554a629c Make current_budget accessible in controller and views 2018-01-15 19:13:45 +01:00
rgarcia
c0488c3b3c refactors investment filters 2017-05-06 04:57:06 +02:00
kikito
9ac6e2d60b Uses invisible_captcha's default "foo fast" action 2016-04-28 12:47:04 +02:00
kikito
7adc706d23 Moves redirect_timestamp_spam to AppController 2016-04-27 16:13:49 +02:00
kikito
dea1a28a69 purges simple_captcha 2016-04-27 16:07:47 +02:00
rgarcia
ed1ec1c553 adds votes to spending proposals 2016-03-29 14:53:46 +02:00
kikito
6ba1db1a02 includes a "cancel" option when logging in via omniauth
restores missing proposal in common_actions
2016-02-03 11:59:19 +01:00
kikito
1e8d46d83a fixes failing email specs
Conflicts:
	app/models/user.rb

fixes missing i18n entry

fixes badly done merge

fixes i18n issues

force build to start
2016-01-26 18:15:43 +01:00
kikito
981e82fb4d Refactors ensure_signup_complete action 2016-01-26 18:11:04 +01:00
Josep Jaume Rey Peroy
f9b6284df6 Explicitly check for different locale before updating 2016-01-22 18:26:08 +01:00
Josep Jaume Rey Peroy
cf00f12ec7 Store locale in a user's field and switch locale on mailers 2016-01-22 18:10:28 +01:00
rgarcia
b5e9113718 merges activities into notifications 2016-01-06 12:33:37 +01:00
Julian Herrero
d9ba3edc2a mostrar notificaciones a los usuarios cuando alguien comenta en su
debate o responde a su comentario
2016-01-05 17:43:44 +01:00
Julian Herrero
ba0ce4e14b añadir track_activity para mostrar futuras notificaciones a los usuarios 2016-01-05 17:42:10 +01:00
kikito
866e04f776 makes devise remember the last visited page before login in 2015-12-21 16:44:30 +01:00
kikito
7996f5f816 makes cancan return a json error when asked for json and permissions fail 2015-12-16 14:02:03 +01:00
Juanjo Bazán
1e0ac137bb removes beta testers functionality 2015-10-29 13:19:00 +01:00
rgarcia
c71bf4c876 tracks visits from different email templates 2015-10-22 12:23:15 +02:00
kikito
18db6482f9 makes sure verifications only happen for signed in users when doing a letter verification 2015-10-20 17:18:28 +02:00
kikito
0d0806c9ae improvements in the letter verification error messages 2015-10-20 16:19:17 +02:00
kikito
1caf6348a9 Extract HasOrders + partial from DebatesController 2015-09-12 16:48:41 +02:00
rgarcia
f2b917d486 adds proposal show 2015-09-12 12:30:20 +02:00
Juanjo Bazán
f517d7f410 adds before action for verified users 2015-09-11 16:44:52 +02:00
rgarcia
abc68dc868 refactors lock tries [#279] 2015-09-10 20:26:49 +02:00