Commit Graph

15065 Commits

Author SHA1 Message Date
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
Javier Martín
3f7c50f081 Merge pull request #3757 from consul/fix_answers_given_order
Fix duplicate given order creating answers
2019-10-10 20:56:27 +02:00
Javi Martín
6a6a8bf365 Fix milestone publication date comparison
We're storing the publication date as datetime in the database, and we
were comparing it to a date, meaning today's milestones were not being
found.
2019-10-10 02:35:20 +02:00
Javi Martín
0f2a96979e Don't use UTC as application zone in time zone tests
It was a bit confusing, since Travis uses UTC as the system zone, while
most application zones are not UTC.
2019-10-10 02:35:20 +02:00
Javi Martín
211398bd9d Use a more expressive name for time zone tests
"With different time zone" didn't clarify which time zone was different
nor what it was different to.
2019-10-10 02:34:51 +02:00
Javi Martín
56e62a41b6 Fix duplicate given order creating answers
It's possible to have a given order greater than the number of answers;
we don't have any validation rules for that. So the check for the number
of answers isn't enough.

Checking the maximum given order in the answers is safer. Another option
would be to reorder the answers every time we add a new one, but I'm not
sure whether that's the expected behaviour.

Note even after this change the action is not thread-safe, as it is
possible to create two questions with the same given order with two
simultaneous requests.
2019-10-10 00:36:57 +02:00
Javier Martín
706a16d1fa Merge pull request #3756 from consul/fix_duplicate_usernames_in_dev_seeds
Fix duplicate usernames in dev seeds task
2019-10-10 00:24:00 +02:00
Javier Martín
575b4bf978 Merge pull request #3755 from consul/fix_typos
Fix typos in translatable spec
2019-10-09 23:35:23 +02:00
Javi Martín
18d386c1ad Fix duplicate usernames in dev seeds task
Sometimes Faker::Name.name generated the same name for two different
users, causing the task to crash in development or a test to fail while
testing.
2019-10-09 22:59:15 +02:00
Javi Martín
2f569002cf Fix typos in translatable spec
We want to create a new investment for a budget, and not for another
investment.
2019-10-09 22:22:44 +02:00