Commit Graph

18 Commits

Author SHA1 Message Date
Javi Martín
cc628f0363 Raise an exception on open redirects
This way we'll add an extra layer of protection from attacks that might
cause our application to redirect to an external host.

There's one place where we're allowing redirects to external hosts,
though: administrators can link external resources in notifications, and
we're redirecting to them after marking the notification as read.

Since the tests for the remote translations controller were
(accidentally) using an external redirect, we're updating them to use a
relative URL.
2024-04-15 15:39:28 +02:00
Javi Martín
ff93f5a591 Use "resolve" for polymorphic hierarchy paths
In the past, we couldn't use `polymorphic_path` in many places. For
instance, `polymorphic_path(budget, investment)` would return
`budget_budget_investment_path`, while in our routes we had defined
`budget_investment_path`.

With the `resolve` method, introduced in Rails 5.1, we can use symbols
to define we want it to use `investment` instead of `budget_investment`.
It also works with nested resources, so now we can write
`polymorphic_path(investment)`.

This makes the code for `resource_hierarchy_for` almost impossible to
understand. I reached this result after having a look at the internals
of the `resolve` method in order to get its results and then remove the
symbols we include.

Note using this method will not make admin routes compatible with
`polymorphic_path`. Quoting from the Rails documentation:

> This custom behavior only applies to simple polymorphic URLs where a
> single model instance is passed and not more complicated forms, e.g:
> [example showing admin routes won't work]

Also note that now the `admin_polymorphic_path` method will not work for
every model due to inconsistencies in our admin routes. For instance, we
define `groups` and `budget_investments`; we should either use the
`budget_` prefix in all places or remove it everywhere. Right now the
code only works for items with the prefix; it isn't a big deal because
we never call it with an item without the prefix.

Finally, for unknown reasons some routing tests fail if we use
`polymorphic_path`, so we need to redefine that method in those tests
and force the `only_path: true` option.
2020-06-15 11:54:05 +02:00
Javi Martín
a727dcc031 Apply Style/SymbolProc rubocop rule
This style is much more concise.
2019-10-26 20:10:32 +02:00
Javi Martín
db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00
Javi Martín
15c49e0c10 Remove obsolete URL helpers
We now use `polymorphic_hierarchy_path` instead.
2019-10-20 17:23:59 +02:00
decabeza
747aec3506 Improves some code format details 2018-10-31 14:22:10 +01:00
Javi Martín
a64a290392 Extract commentable_path to an initializer
By doing so and including it in ActionDispatch::Routing::UrlFor, we make
it available in controllers, helpers and specs, and so we can remove the
duplication we had there with methods dealing with the same problem.

Even if monkey-patching is ugly, using a different module and executing
ActionDispatch::Routing::UrlFor.send(:include, MyModule) wouldn't make
the method available in the controller.
2018-09-17 20:28:55 +02:00
Bertocq
4a5235f96f Allow notifications with explicit/unexistent links
Notifications usually link to the associated notifiable, but the new
AdminNotifications have a link attribute that may be empty or contain an
external or internal url.
2018-07-25 18:31:41 +02:00
rgarcia
09c44ee583 Extend notifications to be marked as read and unread 2018-03-23 11:47:06 +01:00
decabeza
796fe333e3 adds case when topic on notifications controller 2017-10-20 17:05:23 +02:00
Senén Rodero Rodríguez
fd9bec4d1f Remove uneeded files and rename. 2017-08-01 16:28:01 +02:00
Amaia Castro
289b8e044b Fix url to notifiable when it is a Legislation Question or Annotation 2017-01-20 18:46:57 +01:00
rgarcia
a0ddde16e9 adds notifications for proposals 2016-06-07 22:03:14 +02:00
Juanjo Bazán
a976e16ef3 redirects notification show to notifiable 2016-01-08 13:06:00 +01:00
rgarcia
e2f419e625 destroy notifications when marked as read 2016-01-07 12:02:01 +01:00
rgarcia
b5e9113718 merges activities into notifications 2016-01-06 12:33:37 +01:00
Julian Herrero
9a5f525dc9 marcar notificaciones como leidas despues de ser vistas 2016-01-05 17:43:44 +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