Commit Graph

14774 Commits

Author SHA1 Message Date
Javi Martín
4699e767ec Apply Layout/SpaceAfterComma rubocop rule 2019-10-22 18:48:22 +02:00
Javi Martín
38b7307450 Use respond_to? instead of try
Usually when we use `try` we actually mean `try!`, which is the same as
the safe navigation operator. However, there are a few cases where we
actually mean to execute a method if the object responds to that method.

In those cases using `try` would actually be OK, but in order to avoid
confusion as to whether we mean to check for `respond_to?` or we mean to
use safe navigation, I'm removing all usages of `try`.
2019-10-22 17:37:51 +02:00
Javi Martín
1004ac01f8 Add and apply Style/SafeNavigation rubocop rule
We were already using it most of the time, but not always.
2019-10-22 17:37:51 +02:00
Javi Martín
6ceca143b4 Remove redundant check deleting content blocks
The `find` method raises an exception if nothing is found, so there's no
need to check if it found something.
2019-10-22 17:37:51 +02:00
Javi Martín
aace7aea02 Apply Layout/SpaceAroundOperators rubocop rule
We were a bit inconsistent when aligning equal signs vertically.
2019-10-22 17:37:51 +02:00
Javi Martín
cc76432a97 Use Time.current when freezing time
I was using Time.now because that's what Rails actually does, but we get
a warning by rubocop.
2019-10-22 17:37:51 +02:00
Javi Martín
6c45d21626 Avoid using Time.now and Date.today in zone tests
We've got a rubocop rule preventing us from using them, and the tests
are easier to read this way.
2019-10-22 17:37:48 +02:00
Javier Martín
c35546b720 Merge pull request #3749 from consul/sanitize_description
Sanitize descriptions in the views
2019-10-22 13:22:33 +02:00
Javier Martín
67fc73551d Merge pull request #3785 from consul/ruby2.4.9
Upgrade Ruby to 2.4.9
2019-10-21 22:45:40 +02:00
Javi Martín
823162ad39 Upgrade Ruby to 2.4.9
This is the latest Ruby in the 2.4.x series.
2019-10-21 21:39:24 +02:00
Javi Martín
17ae9c96dc Fix typos sanitizing checkbox labels 2019-10-21 21:33:58 +02:00
Javi Martín
68ca29fa8b Convert markdown to HTML on demand
We were converting markdown to HTML every time we saved a record, which
has the same problems as sanitizing HTML before saving it to the
database, particularly because the body of a legislation draft is stored
in a translations table.

Performance-wise this isn't a problem: converting a text with more than
200_000 characters takes about a milisecond on my machine.

Note we need to modify a migration generated by globalize, since the
method `create_translation_table!` would fail now that we don't define
`translates :body_html` in the model.
2019-10-21 21:32:43 +02:00
Javi Martín
7bf4e4d611 Sanitize descriptions in the views
Sanitizing descriptions before saving a record has a few drawbacks:

1. It makes the application rely on data being safe in the database. If
somehow dangerous data enters the database, the application will be
vulnerable to XSS attacks
2. It makes the code complicated
3. It isn't backwards compatible; if we decide to disallow a certain
HTML tag in the future, we'd need to sanitize existing data.

On the other hand, sanitizing the data in the view means we don't need
to triple-check dangerous HTML has already been stripped when we see the
method `auto_link_already_sanitized_html`, since now every time we use
it we sanitize the text in the same line we call this method.

We could also sanitize the data twice, both when saving to the database
and when displaying values in the view. However, doing so wouldn't make
the application safer, since we sanitize text introduced through
textarea fields but we don't sanitize text introduced through input
fields.

Finally, we could also overwrite the `description` method so it
sanitizes the text. But we're already introducing Globalize which
overwrites that method, and overwriting it again is a bit too confusing
in my humble opinion. It can also lead to hard-to-debug behaviour.
2019-10-21 21:32:02 +02:00
Javi Martín
ae2576020e Extract method to use WYSIWYGSanitizer in views
This is similar to methods we use like `sanitize` or `markdown`.
2019-10-21 21:32:02 +02:00
Javier Martín
a8713793a5 Merge pull request #3779 from consul/jquery_xss
Use jQuery's text() instead of html() where safer
2019-10-21 21:18:47 +02:00
Javi Martín
7f1bfc6bd7 Avoid using html() to set languages description
The jQuery html() function does not filter <script> tags, so if somehow
an attacker introduced a <script> in the translation, we would be
vulnerable to a XSS attack.

Note using $.parseHTML wouldn't solve the problem, since it doesn't
filter attributes in image tags.

Since changing the text of the part which doesn't have the count wasn't
very clean, I've added another <span> tag for the part with the
description, and so we can use jQuery's text() function to replace it.
2019-10-21 20:24:50 +02:00
Javi Martín
d61e8cb6a6 Use text() instead of html()
Using html() makes it possible to insert <script> tags in the DOM, and
in this case we aren't supposed to be inserting any HTML.

I haven't found a way to focus on a field with Capybara, then add a
character, and focus on another field. So I've manually triggered the
change event in the test.
2019-10-21 20:24:50 +02:00
Javi Martín
31c2379a4e Don't sanitize <span> tags in HTML attributes
Doing so will cause the `<span>` tag to be rendered in the document,
instead of being rendered as a data attribute.
2019-10-21 20:24:50 +02:00
Javier Martín
cb8bb6216e Merge pull request #3782 from consul/title_or_id_integer
Fix investments search with numbers in their title
2019-10-21 20:17:39 +02:00
Javi Martín
9340d189cb Fix investments search with numbers in their title 2019-10-21 19:27:16 +02:00
Javi Martín
8aa4c630d7 Make search_by_title_or_id behave like a scope
There's no need to pass the collection of results when we use methods
like `where`.
2019-10-21 19:27:15 +02:00
taitus
7e779bf68b Remove eval from remote_census_api
The use of eval is a serious security risk, so we change by JSON.parse method
2019-10-21 16:52:20 +02:00
Javier Martín
8a752b5e09 Merge pull request #3775 from rockandror/census-caller-endpoint-check-simpler
Do not call CensusAPI when endpoint is not defined
2019-10-21 15:29:40 +02:00
Senén Rodero Rodríguez
ba6b2f4940 Refactor specs
Improve readability, simplify, reorganize and cover missing cases.
2019-10-21 14:30:03 +02:00
Senén Rodero Rodríguez
a733bc7b2e Avoid calls to remote census api (legacy) when endpoint is not defined
Also keep the same behavior for test and development environments.
2019-10-21 14:30:03 +02:00
Javier Martín
2f9995f566 Merge pull request #3766 from consul/relative_urls
Use relative URLs where possible
2019-10-20 18:33:13 +02:00
Javier Martín
143c9c5e27 Merge pull request #3783 from consul/budget-heading-groups-timestamps
Add timestamps to budget headings and groups
2019-10-20 18:22:59 +02:00
Javier Martín
c1d6cd4e4b Merge pull request #2151 from consul/feature-flag-api
Feature flag api
2019-10-20 18:21:28 +02:00
Javier Martín
a9110d23e0 Merge pull request #2214 from consul/related-content-tests
Add tests for related content score
2019-10-20 18:15:45 +02:00
Shaun Schwartz
04b1bc9fca Add timestamps to Budget::Heading & Budget::Group 2019-10-20 17:36:36 +02:00
Javi Martín
27468b0b7b Use relative URLs where possible
In general, we always use relative URLs (using `_path`), but sometimes
we were accidentally using absolute URLs (using `_url`). It's been
reported i might cause some isuses if accepting both HTTP and HTTPS
connections, although we've never seen the case.

In any case, this change makes the code more consistent and makes the
generated HTML cleaner.
2019-10-20 17:26:14 +02:00
Javi Martín
11e52dbe98 Remove kaminari_path
The main reason to use it was the `rel` attribute for previous/next
pages not being indexed correctly by certain search engines when using a
relative URL. However, AFAIK that only applied to `<link>` tags, not to
`<a>` tags, and only if a `<base>` tag was defined.

In any case, it looks like the same search engines don't use the `rel`
attribute for previous/next to index pages anymore.
2019-10-20 17:26:14 +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
María Checa
c8966b99b0 Added relation score specs 2019-10-20 15:03:05 +02:00
Juanjo Bazán
0063e7b4d8 Add feature flag for the GraphQL API 2019-10-20 14:52:07 +02:00
Javier Martín
11f1beed62 Merge pull request #3776 from consul/valuator_edit_investment
Don't let valuators update investments
2019-10-18 21:32:55 +02:00
Javi Martín
f5b60e03e1 Don't let valuators update investments
There were some confusing definitions regarding the valuation of budget
investments.

In the controller, `CommentableActions` was included, which includes the
update action.

In the abilities, a valuator was given permission to update an
investment.

However, the action to update an investment didn't work because there is
no route defined to do so.

The ability was defined so valuators could access the "edit" action,
which will not call the "update" action but the "valuate" action. Since
internally "edit" and "update" use the same permission, it worked.

But then we added permission for regular users to update budget
investments, and these permissions were allowing valuators to update
another user's investment.

After this change, everything seems to work properly since we check
authorization in the controller itself instead of using abilities.
2019-10-18 16:24:27 +02:00
denialtorres
bb627a7117 Edit Budget Investment only in accepting phase (#3716)
This way users who made a typo can fix it before the investment is reviewed.
2019-10-18 13:59:14 +02:00
Javier Martín
970c3238fb Merge pull request #3627 from consul/upgrade_to_ruby2.4
Upgrade ruby to 2.4.6
2019-10-13 01:00:00 +02:00
Javi Martín
a8331c956f Upgrade to Ruby 2.4.6
Many gems have dropped support for Ruby 2.3, including Rails 6.

We've already tested the upgrade on production environments; no issues
so far.
2019-10-13 00:31:13 +02:00
Javi Martín
41d252bf10 Simplify syntax to execute RMV
We use `:rvm` just as we use `:rake` in other places.
2019-10-13 00:31:13 +02:00
Javi Martín
48dd4be851 Use .ruby-version to detect our Ruby version
Travis and Rubocop and rmv1-capistrano3 automatically detect the version
based on the `.ruby-version` file.
2019-10-13 00:31:13 +02:00
Javi Martín
19f8e3ac8e Enable tasks to install Ruby and bundler
We're going to upgrade our ruby version, and we need these tasks.

Note we now get a warning caused by `rvm1:install:ruby` invoking
`deploy:updating`. It doesn't seem to be an issue because we don't add
any hooks to `deploy:updating`, and neither do the rest of the gems we
use.
2019-10-13 00:28:33 +02:00
Javier Martín
b30aaed13e Merge pull request #3694 from consul/puma
Use puma instead of unicorn
2019-10-12 17:47:00 +02:00
Javi Martín
f26f8b3c3e Add support for legacy unicorn installations
Old CONSUL nginx configurations will probably have a reference to a
unicorn socket. Making that file a symbolic link to a puma socket makes
it possible for the application to keep working without updating the
nginx configuration file.
2019-10-12 17:01:15 +02:00
Javi Martín
3b79a1a3db Add compatibility between puma and RMV1
Puma was adding commands to `rvm_map_bins`, which meant RMV1 wasn't
using the default value of `rvm1_map_bins`.

Changing the order we use to require `rmv1/capistrano3` and
`capistrano/puma` did not fix the issue.
2019-10-12 16:51:28 +02:00
Javi Martín
b36e659f4e Use puma instead of unicorn
Puma is the server we use in the development environment, so this way we
don't need to maintain two servers. Furthermore, puma seems to offer a
few advantages over unicorn (like multithreading) and no disadvantages.
2019-10-12 16:50:49 +02:00
Javi Martín
94a7e13dce Update capistrano's restart unicorn task
Our current unicorn task wasn't working in some cases. We also had a
version in the `capistrano` branch, which was the one we recommended.
However, that version assumed RVM, a certain ruby version and a certain
deploy folder were used. This version uses `bundle exec` and variables
like `release_path`, so it does not depend on any specific
configuration.

Even if we're replacing unicorn with puma, I wanted to make this change
in case we need it as a reference in the future.
2019-10-10 21:01:42 +02:00
Javier Martín
dd8bc5cea7 Merge pull request #3760 from consul/fix_milestone_published
Fix milestone publication date comparison
2019-10-10 20:58:22 +02:00
Javier Martín
dd6e603d9e Merge pull request #3754 from consul/flaky_results_spec
Fix flaky officing results spec
2019-10-10 20:56:51 +02:00