Commit Graph

61 Commits

Author SHA1 Message Date
Javi Martín
f2613aa5ae Allow symbols in YAML columns
Without this change, we were getting errors when manually creating an
annotation using symbols in the ranges hash (that is, `ranges: [{ start:
"/p[1] }]` instead of `ranges: [{ "start" => "/p[1] }]`.

Using symbols isn't really supported and it might cause strange issues
with code like: `@draft_version.annotations.find_by(range_start: ...)`.
However, this might be an extreme case and using symbols might work
properly most of the time (if not all the time), and we've been using
them in our demo for years.

So I'm not writing a test for this case because I'm not sure we should
support it, but I'm still allowing symbols so we don't get exceptions in
cases where everything might be working fine. Rails already adds Symbol
by default to column permitted classes [1], so it's safe to enable it.

[1] https://github.com/rails/rails/pull/45584/commits/c2b96e3e8
2022-08-23 12:09:06 +02:00
Javi Martín
241dd53411 Bump rails from 5.2.7.1 to 5.2.8.1
This release introduces an incompatibility in order to fix a security
issue when using YAML for serialization. We use YAML to serialize the
`ranges` column in the `legislation_annotations` table, so we have to
allow the `ActiveSupport::HashWithIndifferentAccess` class in order to
properly read this column.

Ideally we'd use a JSONB column for the ranges (like we do in other
places), but that would require migrating existing data.

Bumps [rails](https://github.com/rails/rails) from 5.2.7.1 to 5.2.8.1.
- [Release notes](https://github.com/rails/rails/releases)
- [Commits](https://github.com/rails/rails/compare/v5.2.7.1...v5.2.8.1)

---
updated-dependencies:
- dependency-name: rails
...
2022-07-26 22:58:43 +02:00
Javi Martín
4eea69faee Make it possible to customize GraphQL types 2022-06-02 16:22:25 +02:00
Javi Martín
95c1999cca Make it easier to customize JavaScript functions
When there was a custom JavaScript file, we weren't loading the original
one, meaning that, in order to customize it, it was necessary to copy
the whole original file and then changing it.

Now we're loading both the original and the custom file, so the custom
file can simply add more functions or overwrite the ones we'd like to
customize, without copying the whole file.

Existing copies of original files will still overwrite the whole file
and won't be affected.
2022-03-18 16:43:14 +01:00
Javi Martín
73a0a21001 Configure Active Storage 2021-09-24 13:39:15 +02:00
Javi Martín
886006d497 Enable ActiveStorage
This reverts commit 7496c1bcb9.
2021-09-24 13:39:15 +02:00
Javi Martín
e01a94d7bd Use mem_cache_store instead of dalli_store
`dalli_store` is deprecated since dalli 2.7.11.

We can now enable cache_versioning. We didn't enable it when upgrading
to Rails 5.2 because of possible incompatibility with `dalli_store` [1],
even though apparently some the issues were fixed in dalli 2.7.9 and
dalli 2.7.10 [2].

Since using cache versioning makes cache expiration more efficient, and
I'm not sure whether the options we were passing to the dalli store are
valid with memcache store (documentation here is a bit lacking), I'm
just removing the option we used to double the default cache size on
production.

[1] https://www.schneems.com/2018/10/17/cache-invalidation-complexity-rails-52-and-dalli-cache-store
[2] https://github.com/petergoldstein/dalli/blob/master/History.md
2021-08-15 19:42:22 +02:00
Javi Martín
7bb7548d00 Respond with 403 when features are disabled
When administrators disabled features and users tried to access them
with the browser, we were responding with a 500 "Internal Server Error"
page, which in my humble opinion was incorrect. There was no error at
all; the server worked exactly as expected.

I think a 403 "Forbidden" code is better; since that feature is
disabled, we're refusing to let users access it.

We could also respond with a 404 "Not found", although I wonder whether
that'll be confusing when administrators temporarily or accidentally
disable a feature.

A similar thing might happen if we responded with a 410 "Gone" code.
Actually this case might be more confusing since users aren't that
familiar with this code.

In any case, all these options are better than the 500 error.
2021-06-16 20:45:15 +02:00
Senén Rodero Rodríguez
77c75add3d Enable Ukrainian language by default 2021-04-27 10:53:47 +02:00
Javi Martín
7275fc9aa2 Add and apply RedundantFileExtensionInRequire rule
This rule was added in Rubocop 0.88.0.
2020-10-23 12:01:39 +02:00
Javi Martín
baefc249f0 Allow using components with view_component
While Rails provides a lot of functionality by default, there's one
missing piece which is present in frameworks like Django or Phoenix: the
so-called "view models", or "components".

It isn't easy to extract methods in a standard Rails view/partial, since
extracting them to a helper will make them available to all views, and
so two helper methods can't have the same name. It's also hard to
organize the code in modules, and due to that it's hard to figure out
where a certain helper method is supposed to be called from.
Furthermore, object-oriented techniques like inheritance can't be
applied, and so in CONSUL customizing views is harder that customizing
models.

Components fix all these issues, and work the way Ruby objects usually
do.

Components are also a pattern whose popularity has increased a lot in
the last few years, with JavaScript frameworks like React using them
heavily. While React's components aren't exactly the same as the
components we're going to use, the concept is really similar.

I've always liked the idea of components. However, there wasn't a stable
gem we could safely use. The most popular gem (cells) hasn't been
maintained for years, and we have to be very careful choosing which gems
CONSUL should depend on.

The view_component gem is maintained by GitHub, which is as a guarantee
of future maintenance as it can be (not counting the Rails core team),
and its usage started growing after RailsConf 2019. While that's
certainly not a huge amount of time, it's not that we're using an
experimental gem either.

There's currently a conflict between view_component and wicked_pdf.
We're adding a monkey-patch with the fix until it's merged in
wicked_pdf.
2020-10-19 18:56:02 +02:00
Javi Martín
7496c1bcb9 Disable ActiveStorage routes
We aren't using ActiveStorage, but Rails was including its routes
anyway.

In Rails 6.1 there will be an option to disable these routes [1], but
for now we're changing the line requiring "rails/all" to the values
generated by a new Rails application with the --skip-active-storage
flag.

[1] https://github.com/rails/rails/commit/3cf65bcb8
2020-10-15 14:57:42 +02:00
Javi Martín
f42effe9fe Use Rails 5.2 defaults and overwrite them
We can remove the `new_framework_defaults_5_2` file by using Rails 5.2
default options and overwriting the ones we haven't enabled.

We're disabling `use_authenticated_message_encryption` because, even if
we don't use it, some CONSUL installations might be using it, and
enabling this options would make it harder to decrypt existing encrypted
messages.

And we're disabling `cache_versioning` until we verify our cache keeps
working and expires as expected on production environments, particularly
for stats.
2020-10-15 14:57:42 +02:00
Javi Martín
5c0ba0b04c Generate local forms with form_with by default
We're not replacing `form_for` with `form_with` for now, and even if we
did, most of our forms are not remote, so making them remote by default
would be inconvenient.
2020-10-04 15:47:20 +02:00
Javi Martín
905ac48bb9 Raise an exception when an asset is not found
This is the default in Rails 5.1 applications. If we want to use an
asset in the public folder, we need to add the `public_folder: true`
option, making it clear that we don't expect the asset to be in the
asset pipeline.

Since we don't use `asset_path` to reference assets in the public
folder, we can safely disable the `unknown_asset_fallback` option.
2020-10-04 15:47:20 +02:00
Javi Martín
00dc58f8b3 Use Rails 5.1 defaults and overwrite them
This way we know what we need to do to fully upgrade to Rails 5.1.
2020-10-04 15:47:20 +02:00
Javi Martín
32f06ea7d9 Keep belongs_to optional by default
Changing it would mean reviewing and changing all our existing models,
and some of them might be tricky (like our Document and Image models,
which only validate certain associations in some cases), so we're
keeping it the way it's been until now.
2020-10-04 15:47:20 +02:00
Javi Martín
b1c112952f Use Rails 5 default SSL options
The default options (which apply when `force_ssl` is set, which is the
default in CONSUL) are `{ hsts: { subdomains: true } }`, which means we
tell browsers to apply our SSL settings to subdomains as well [1].
CONSUL installations implementing multitenancy with subdomains will
benefit from this change.

[1] https://api.rubyonrails.org/classes/ActionDispatch/SSL.html
2020-10-04 15:47:20 +02:00
Javi Martín
0734e788bd Preserve timezone when calling to_time
Quoting the Rails DateAndTime::Compatibility module:

> With Ruby 2.4+ the default for +to_time+ changed from
> converting to the local system time, to preserving the offset
> of the receiver. For backwards compatibility we're overriding
> this behavior

We don't need backwards compatibility in our application because we
aren't converting any time objects to the local system timezone but use
the application timezone all the time instead.
2020-10-04 15:47:20 +02:00
Javi Martín
f1b38d20c1 Enable Origin header check in forgery protection
This is the default in Rails 5 applications.

This option is not enabled by default in existing applications because
it would break applications running on several domains and doing POST
requests between them or running a reverse proxy that rewrites the Host
header. Since those aren't our cases, it's safe to enable it.
2020-10-04 15:47:20 +02:00
Javi Martín
611d729080 Enable per form CSRF tokens
This is the default for new Rails application, and adds an extra layer
of security since now the token will only be valid for its action, and
so attackers managing to change the form action will not do any harm
since the CSRF token will not work for the attackers' action.

Note that we've had InvalidAuthenticityToken exceptions for years; if we
keep getting them, chances are this change is *not* related.
2020-10-04 15:47:20 +02:00
Javi Martín
53ddd046d9 Add "load_defaults" method and undo what it does
The goal here is to have a notion on what the defaults are in a Rails 5
application, know why our application is working in a different way
(it's because these defaults aren't loaded in an application which was
originally developed using Rails 4), and have an explicit list of things
we are overwriting.

Furthermore, running the `app:update` rake task to upgrade to Rails 5.2
will by default add the line loading default options for Rails 5.0, so
by adopting those default options we prevent accidental mistakes when
upgrading.

We'll have to review these items and see which ones can be changed to
their default values for Rails 5 applications.
2020-10-04 15:47:20 +02:00
Senén Rodero Rodríguez
9694def11a Enable Serbian (Cyrillic)
Consul uses two variants of Serbian: Serbian (Cirylic), and
Serbian (Latin) so wee need to use different locale codes for each of
them to avoid collisions.

The folder names of both languages were correct but the locale code within
the files was the same for both languages "sr" so translations were mixed.

This commit changes the locale code within Serbian (Latin) translations
files to "sr-CS", also adds a new language mapping to the Crowdin config
file so next ConsulBot commits with Serbian (Latin) translations will be
done using the locale code defined at new language mapping.
2020-09-15 17:53:54 +02:00
Senén Rodero Rodríguez
795290bf24 Enable languages with higher translation ratio
Following locales are now available by default:

* "bg" (Bulgarian):              98,5% translated
* "ca" (Catalan):               100  % translated
* "es-PE" (Spanish from Perú):   64,8% translated
* "eu" (Euskara):                67,8% translated
* "ka" (Georgian):               98,9% translated
* "oc" (Occitan):                98,9% translated
* "ro" (Romanian):               99,1% translated

Spanish and Euskara were enabled becuase both are near the 70% and its
fallback language (Spanish) is complete.

Add custom fallbacks:

* Catalan (ca)                 => Español (es).
* Español de Perú (es-PE)      => Español (es).
* Euskara (eu)                 => Español (es).
* Portuguese-Brazilero (pt-BR) => Español (es).
* Occitan (oc)                 => French (fr)
2020-09-15 17:53:54 +02:00
Javi Martín
6fd9a286d7 Don't access the database in after_initialize
Rails 5.2 crashes in the `db:create` task because it tries to run the
`after_initialize` block before the database is created.

The easiest way to solve it is to move the code out of the initializer
and calculate the API type definitions on demand. Note results are still
cached using a class instance variable (not to be confused with a class
variable), and so once definitions are obtained, they will remain
constant until the application is restarted, even in the development
environment.
2020-07-08 18:34:58 +02:00
Javi Martín
0b1a4907ac Load custom locales after everything is loaded
The line:

```
config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**", "*.{rb,yml}")]
```

Was adding every locale under the `config/locales` folder, including the
ones inside `config/locales/custom/`. The files were loaded in the same
order as listed using `ls -f`.

So if the custom locales were loaded before the folder
`config/locales/#{I18n.locale}`, the default locales would override the
custom ones, and we want the custom locales to override the default
ones so CONSUL is easier to customize.
2019-08-07 22:05:01 +02:00
Senén Rodero Rodríguez
5d0b74cb07 Initialize graphql after application initialization
Proposal, Debate and Comment "globalize_accessors" class method were
loaded before application available locales initialization because of
graphql initializer. This will cause unexpected translation errors at
any translatable classes declared at graphql api definition (api.yml).

Doing GraphQL initialization after application initialization should
solve this issue.
2019-06-27 09:19:35 +02:00
voodoorai2000
78f3cec133 Add Bosnian, Czech, Danish, Greek, Croatian and Turkish locales 2019-05-31 14:49:38 +02:00
decabeza
cb22e6cbfb Merge branch 'master' into proposal-dashboard 2019-04-23 17:12:47 +02:00
Javi Martín
4adf712c26 Prepend custom assets to CONSUL assets
Rails 5 changed the initialization order, and now our initializers were
running before the `append_assets_path` initializer for each engine,
which prepended application assets to the custom assets we prepended in
the initializer.

Moving the code to the `config.after_initialize` code didn't work
either, since the paths added there were ignored by the application.

Adding another initializer to the Rails Engine is a hack, but solves the
problem.
2019-04-17 17:40:57 +02:00
alejandro
b7a9995b38 fixes deprecation warning relate to raise_in_transactional_callbacks
As described in
http://edgeguides.rubyonrails.org/5_0_release_notes.html#active-record-notable-changes
2019-04-17 17:40:55 +02:00
Juanjo Bazán
eb36b7e2e5 updates config files 2019-04-16 17:28:06 +02:00
decabeza
eda6ea7f12 Merge branch 'master' into dashboard 2019-03-26 16:45:48 +01:00
Julian Herrero
c9cdc72537 Use double quotes in config/ 2019-03-15 10:29:07 +01:00
voodoorai2000
4db07a3341 Update available locales
Add locales for Indonesian, Russian, Slovak and Somali.
2019-02-15 15:25:40 +01:00
Javi Martín
2e6644d513 Fix crash with no translation for default locale
When we were visiting a page showing the content of a record which uses
globalize and our locale was the default one and there was no
translation for the default locale, the application was crashing in some
places because there are no fallbacks for the default locale.

For example, when visiting a legislation process, the line with
`CGI.escape(title)` was crashing because `title` was `nil` for the
default locale.

We've decided to solve this issue by using any available translations as
globalize fallbacks instead of showing a 404 error or a translation
missing error because these solutions would (we thinkg) either require
modifying many places in the application or making the translatable
logic even more complex.

Initially we tried to add this solution to an initializer, but it must
be called after initializing the application so I18n.fallbacks[locale]
gets the value defined in config.i18n.fallbacks.

Also note the line:

fallbacks[locale] = I18n.fallbacks[locale] + I18n.available_locales

Doesn't mention `I18n.default_locale` because the method
`I18n.fallbacks[locale]` automatically adds the default locale.
2018-10-22 16:36:18 +02:00
decabeza
546105d989 Merge branch 'master' into dashboard-master 2018-10-19 01:48:37 +02:00
voodoorai2000
8eb399150e Remove fallback rules for locales not yet added 2018-10-17 12:47:35 +02:00
voodoorai2000
3b8bb5038d Add fallback i18n locales
All other languages will fallback to the default locale

Rails also, seems to pick up dialect fallbacks, for locales with this format: es-CO, es-PE, etc, which will fallback to "es", so that is great 😌
2018-10-17 12:47:35 +02:00
voodoorai2000
f2fe230a15 Add all available locales
Only addding those with significant number of translations
2018-10-17 12:47:35 +02:00
Juan Salvador Pérez García
921d567110 Implements #175
General menu has been refactored to look like the mockups.
The progress menu has been refactored as well.
2018-07-17 17:57:30 +02:00
Alberto Calderón Queimadelos
0e1d5d95a7 Revert "Make config.time_zone configurable at secrets.yml" 2018-03-08 17:12:00 +01:00
Bertocq
f9909573a3 Make config.time_zone configurable at secrets.yml 2018-03-05 11:17:25 +01:00
Bertocq
18a5bc6642 Make English the default locale 2018-01-24 11:37:43 +01:00
decabeza
5949f7abf0 uppercase all consul name 2017-09-01 12:51:31 +02:00
Bertocq
552661f0e4 Add to i18n load path files in nested folders 2017-07-05 13:30:05 +02:00
Tom Demeyer
3ba5e25801 enable dutch translation 2017-04-28 15:53:15 +02:00
rgarcia
d540be333a Makes tolk aware of french and portuguese translations 2016-10-31 11:54:26 +01:00
rgarcia
aeec264b8b makes fallback locale spanish 2016-10-31 11:50:16 +01:00
rgarcia
04ca5f7ae8 adds french and brazilian portuguese locales 2016-10-31 11:50:07 +01:00