Commit Graph

270 Commits

Author SHA1 Message Date
decabeza
e3539544a8 Remove google plus share button 2020-07-17 16:24:20 +02:00
Javi Martín
9318c4f1e9 Bump pg_search from 2.0.1 to 2.3.0
Using pg_search 2.0.1 with Rails 5.2 results in deprecation warnings:

DEPRECATION WARNING: Dangerous query method (method whose arguments used
as raw SQL) called with non-attribute argument(s):
"pg_search_978c2f8941354cf552831b.rank DESC, \"tags\".\"id\" ASC".
Non-attribute arguments will be disallowed in Rails 6.0. This method
should not be called with user-provided values, such as request
parameters or model attributes. Known-safe values can be passed by
wrapping them in Arel.sql().

We're not upgrading to the latest pg_search because it only supports
ActiveRecord >= 5.2.
2020-07-14 13:16:08 +02:00
Javi Martín
f6351819fa Simplify SQL using DISTINCT
Using `pluck("DISTINCT")` was raising a warning in Rails 5.2:

DEPRECATION WARNING: Dangerous query method (method whose arguments are
used as raw SQL) called with non-attribute argument(s): "DISTINCT
taggings.tag_id". Non-attribute arguments will be disallowed in Rails
6.0. This method should not be called with user-provided values, such as
request parameters or model attributes. Known-safe values can be passed
by wrapping them in Arel.sql().

Since there was only one other use of distinct, I've decided to change
both of them in the same commit, even if the second one wasn't raising a
warning.
2020-07-08 18:34:58 +02:00
Javi Martín
d7d421b88f Rename columns with a slash in their names
These columns were causing Rails 5.2 to throw a warning when ordering by
them, as if they weren't valid column names:

DEPRECATION WARNING: Dangerous query method (method whose arguments are
used as raw SQL) called with non-attribute argument(s):
:"budget/investments_count". Non-attribute arguments will be disallowed
in Rails 6.0. This method should not be called with user-provided
values, such as request parameters or model attributes. Known-safe
values can be passed by wrapping them in Arel.sql().

This change also makes their names consistent with the rest of our
tables and columns.
2020-07-08 18:34:58 +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
199d8ff609 Bump rubocop from 0.75.0 to 0.83.0
Recent versions introduce the `Layout/SpaceAroundMethodCallOperator`,
which we are going to use. We aren't upgrading to the latest rubocop
version because it conflicts with the version of Capybara we're using
and because it isn't supported by Hound.

Some rules have been renamed:

Layout/IndentAssignment is now Layout/AssignmentIndentation
Layout/IndentHeredoc is now Layout/HeredocIndentation
Layout/LeadingBlankLines is now Layout/LeadingEmptyLines
Layout/Tab is now Layout/IndentationStyle
Layout/TrailingBlankLines is now Layout/TrailingEmptyLines
Lint/StringConversionInInterpolation is now Lint/RedundantStringCoercion
Metrics/LineLength is now Layout/LineLength

Note after upgrading we get a new "offense" in the `StartWith` rule, so
we're changing the code in order to fix it.
2020-06-16 13:47:38 +02:00
Javi Martín
65604a92c2 Add non-prefixed polymorphic admin routes
These routes are solved in a different way because of an inconsistency:
we define `groups` and `budget_investments`; we should either use the
`budget_` prefix in all places or remove it everywhere.

We can now share code using `polymorphic_path` even with these models.
2020-06-15 11:54:05 +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
334b57501b Simplify uses of polymorphic admin nested routes 2020-06-11 18:39:57 +02:00
Javi Martín
3526aef1e4 Remove callback terminator initializer
We no longer need it since this is the default behavior in Rails 5.1.
2020-04-23 18:49:43 +02:00
Senén Rodero Rodríguez
103726f24a Add ckeditor tabletools plugin
This plugin provides more control over tables and solves a JS error thrown
when user clicks on "Cell properties" ckeditor feature.

https://ckeditor.com/cke4/addon/tabletools
2020-04-23 18:18:26 +02:00
Senén Rodero Rodríguez
9fd9ef8a54 Explicitly disable not used ckeditor plugins
All of these plugins are not used anywhere.

Change introduced at ckeditor initializer will ommit unneeded
precompilation of plugins assets on production environments.

Change introduced at ckeditor config file adresses the problem with assets
pipeline fallback on testing environments described here: #2711. Now plugins
that are explicitly disabled will not be precomiled when running ckeditor
javascript enabled feature specs.
2020-04-23 10:37:26 +02:00
Senén Rodero Rodríguez
58645d0146 Enable pastefromword plugin 2020-04-20 22:12:28 +02:00
Javier Martín
06bc72cc66 Merge pull request #3959 from consul/i18n-custom-translations
Fix custom translations with options
2020-04-10 12:51:23 +02:00
decabeza
af1e11838c Fix custom translations with options 2020-04-10 12:17:27 +02:00
Javi Martín
03c135e5fd Apply escape_javascript security patch
This patch was included in the Rails 5.2.x series, but since we haven't
upgraded yet, we need to apply it manually.
2020-04-06 16:19:44 +02:00
Julian Herrero
193e51d42f Enable Wordpress Oauth login and registration 2020-02-07 12:23:41 +07:00
Javi Martín
a08d42d3f8 Enable/disable delayed jobs in the secrets file
While this is not a secret and in theory should be in a file under
version control, currently the CONSUL installer disables delayed jobs by
default, meaning we were keeping two versions of the delayed jobs
configuration file, and some existing configurations have their settings
defined in a file in capistrano's `shared` folder.

So we're moving existing settings to the secrets file.
2019-11-12 14:58:35 +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
ec1502ee00 Update CKEditor plugins to be precompiled
The new version of CKEditor loads the balloonpanel and balloontoolbar
plugins. Even if we don't need them, I haven't found a way to prevent
them from loading, meaning we have to precompile them.
2019-11-07 01:24:49 +01:00
Javi Martín
f240e0073f Bump ckeditor from 4.2.4 to 4.3.0
This version solves a security issue:

https://ckeditor.com/cke4/release/CKEditor-4.11.0

Note this version adds a `ckeditor/samples` folder, which is
automatically added to the application's assets manifest even if we
remove all CKEditor references in our application. One of the files in
that folder makes ExecJS raise a syntax error, causing every page to
raise a 500 error.
2019-11-06 22:05:44 +01:00
Javi Martín
04cd3b460e Audit changes in investment translations
Note the user interface could certainly be improved, as it doesn't show
which languages have changed.
2019-11-05 13:09:38 +01:00
Javi Martín
e0c2468bd2 Use a different controller for investment audits
The same way we do for milestones. We also make the code more consistent
since the view was already in a separate folder.
2019-11-05 13:03:45 +01:00
Javi Martín
ddb37f89ae Apply Style/Proc rubocop rule
While I tend to use `Proc.new`, using `proc` is shorter and more
consistent since we also use `lambda`.
2019-10-26 13:22:49 +02:00
Javi Martín
70da5a3801 Apply Style/ColonMethodCall rubocop rule
This rule seems to be an obvious one, but we weren't following it in one
place.
2019-10-26 13:03:49 +02:00
Javi Martín
a5def0cdb5 Apply Style/AndOr and Style/Not rubocop rules
The `and` and `or` keywords are not equivalent to `&&` and `||` and its
use is counterintuitive. Here's an example

```
good = true && false # good if false
bad = true and false # bad is true
```

The reason is `and` and `or` are control flow operators. So the code:

```
bad = true and false
```

Is equivalent to:


```
if bad = true
  false
end
```
2019-10-26 13:03:49 +02:00
Javi Martín
033f3c33e3 Add SpaceAroundEqualsInParameterDefault rule
We were using it in most places, but not everywhere.
2019-10-24 17:56:03 +02:00
Javi Martín
d0d681a44b Add and apply EmptyLineAfterGuardClause rule
We were inconsistent on this one. I consider it particularly useful when
a method starts with a `return` statement.

In other cases, we probably shouldn't have a guard rule in the middle of
a method in any case, but that's a different refactoring.
2019-10-24 17:56:03 +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
49e55b4dc4 Apply Rails/DynamicFindBy rubocop rule
We were already using `find_by` most of the time.

Since there are false positives related to our `find_by_slug_or_id!` and
`find_by_manger_login` methods, which cannot be replaced with `find_by`,
I'm adding it indicating the "refactor" severity.
2019-10-23 20:05:40 +02:00
Javi Martín
0671c72c98 Don't halt callbacks on return false
This will be the default behaviour in Rails 5.1, and it's a much better
approach.

I've checked the code and luckily there doesn't seem to be a single
place where we could accidentally stop the callback chain by returning
false in (for example) a `before_save` callback.
2019-10-23 14:32:42 +02:00
Javi Martín
985eeca21e Remove obsolete method to recalculate counter
This method isn't used since commit deffc7f8.
2019-10-22 20:51:56 +02: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
9d627f2db9 Remove redundant I18nContent scope
Since two records cannot have the same key, having a scope that will
always return just one record is the same as using `find_by_key`.
2019-09-24 19:29:46 +02:00
Javi Martín
738e9ebc8b Remove code specific to Internet Explorer 8
Internet Explorer 9 was released eight years ago. Besides that, we don't
really support IE8 anyway, since we show a popup to IE8 users saying
we don't support it, we haven't maintained the IE8-specific CSS file for
years, and we don't test our JavaScript against IE8.
2019-09-10 22:43:37 +02:00
Javi Martín
a5ba13b599 Apply Rails/Presence rubocop rule 2019-09-10 21:43:38 +02:00
Javi Martín
f9ed186909 Add rubocop spacing rules
We were following these rules in most places; we just didn't define them
anywhere.
2019-09-10 21:04:56 +02:00
Javi Martín
b5b07bccd3 Apply PercentLiteralDelimiters rubocop rule 2019-09-10 20:02:15 +02:00
Javi Martín
71d9ddd849 Apply rule to end files with a newline character 2019-09-10 20:02:15 +02:00
Javi Martín
347fc21cf0 Fix trailing whitespace 2019-09-10 19:21:03 +02:00
Javi Martín
66da02f1de Evaluate mailer from address at runtime
We're reading the value from the database, but the
`ApplicationMailer.default` method is evaluated when the application is
started. So if we don't use a Proc, we'll need to restart the server
every time we change the value in the database, or else the old value
will still be used.

Using a Proc makes sure the mailer from address is evaluated at runtime,
so emails are sent using the from address currently defined in the
database.

The same situation took place using the devise mailer. Now we don't need
to check for the settings table being present because the Proc in the
devise initializer won't be evaluated before the settings table is
created and populated.
2019-09-10 15:59:59 +02:00
Javi Martín
b05e881eee Precompile CKEditor dialog plugins
In some cases, in the production environment the dialogs for links,
images and tables didn't work, because these plugins were not
precompiled.
2019-09-06 22:20:22 +02:00
Senén Rodero Rodríguez
96d1666899 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:36 +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
d0b8fef6b3 Delete spending proposals 2019-05-31 18:22:59 +02:00
decabeza
c2acd53a06 Change devise configuration
This change don't let the user know if the email address exists when asking to resend confirmation or password reset instructions.
2019-05-28 14:23:37 +02:00
rgarcia
11437a1d40 add budget investment stats 2019-05-16 13:41:49 +02:00
rgarcia
94a3e7e61a does not exclude ahoy events 2019-05-16 13:37:47 +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