Commit Graph

17301 Commits

Author SHA1 Message Date
Javi Martín
48cbb934c1 Bump parser to 2.6.5.0
This version is compatible with Ruby 2.4.9.
2019-10-23 17:46:47 +02:00
Javi Martín
13793d89c3 Fix extra parameter in have_link
The second parameter was ignored. Besides, we changed the place where
the link pointed to in commit fcbb11b2.
2019-10-23 17:46:47 +02:00
Javier Martín
794857c31c Merge pull request #3790 from consul/codeclimate_rubocop
Use rubocop 0.74 with code climate
2019-10-23 17:31:25 +02:00
Javier Martín
181163f2ab Merge pull request #3789 from consul/duplicate_rule
Remove duplicate rubocop rule
2019-10-23 16:57:33 +02:00
Javi Martín
d20af1225c Use rubocop 0.74 with code climate
It looks like rubocop 0.75 isn't available yet on code climate, and
their default rubocop version isn't compatible with our configuration.
2019-10-23 16:28:03 +02:00
decabeza
974064a742 Update icons scss to use fontawesome icons 2019-10-23 15:49:15 +02:00
decabeza
18975a3963 Add font-awesome-sass gem
Now can use all icons from https://fontawesome.com.
2019-10-23 15:49:15 +02:00
Javier Martín
b31f853bc6 Merge pull request #3780 from consul/bang_save
Apply `Rails/SaveBang` rubocop rule
2019-10-23 15:40:03 +02:00
Javi Martín
262fdd846c Remove duplicate rubocop rule
It was left by accident in commit b1b449b1.
2019-10-23 15:30:09 +02:00
Javi Martín
49c3402833 Use update! instead of update_attributes!
It's what we use almost everywhere, and it's shorter.
2019-10-23 14:39:31 +02:00
Javi Martín
7ca55c44e0 Apply Rails/SaveBang rubocop rule
Having exceptions is better than having silent bugs.

There are a few methods I've kept the same way they were.

The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.

We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").

Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.

There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.

For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
2019-10-23 14:39:31 +02:00
Javi Martín
777fb55399 Don't try to save invalid resources
We were saving the resource after checking it was valid, but it will
always return false if the model isn't valid.
2019-10-23 14:32:42 +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
431074c99f Add save! method to ActiveModel models
This way we make it clear we expect records to be valid when we save
them, just like we do with ActiveRecord models.
2019-10-23 14:32:42 +02:00
Javi Martín
b4b20e0295 Assign attributes to test invalid updates
Using `update` is a bit ambiguous; when we do it we aren't expressing
whether we expect the update operation to succeed or fail.
2019-10-23 14:32:42 +02:00
Javier Martín
0070b73304 Merge pull request #3787 from consul/fix_blank_comments_in_annotations
Fix adding blank comments to existing annotations
2019-10-23 14:09:57 +02:00
Javier Martín
3a0871d7aa Merge pull request #3784 from rockandror/improve-security-risk
Reduce security risk on remote_census_api
2019-10-23 14:01:54 +02:00
taitus
432e8233d2 Rename methods with same name 2019-10-23 10:21:50 +02:00
taitus
08957b70c2 Add Security/Eval rubocop rule to rubocop_basic.yml 2019-10-23 10:21:41 +02:00
Javi Martín
35bbd87093 Fix adding blank comments to existing annotations
We were using the `present?` method, which will always return true for a
comment object.
2019-10-23 04:28:08 +02:00
Javier Martín
7a9fefb933 Merge pull request #3707 from consul/dependabot/bundler/ancestry-3.0.7
Bump ancestry from 3.0.2 to 3.0.7
2019-10-23 01:29:42 +02:00
Javier Martín
ef6c7ee3bb Merge pull request #3286 from PierreMesure/replace-sass-by-sassc
Replace sass-rails gem by sassc-rails
2019-10-23 01:19:42 +02:00
dependabot-preview[bot]
4dbf38195a Bump ancestry from 3.0.2 to 3.0.7
Bumps [ancestry](https://github.com/stefankroes/ancestry) from 3.0.2 to 3.0.7.
- [Release notes](https://github.com/stefankroes/ancestry/releases)
- [Changelog](https://github.com/stefankroes/ancestry/blob/master/CHANGELOG.md)
- [Commits](https://github.com/stefankroes/ancestry/compare/v3.0.2...v3.0.7)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-10-22 22:32:10 +00:00
Javier Martín
b7a99a262e Merge pull request #3786 from consul/obsolete_method
Remove obsolete method to recalculate counter
2019-10-23 00:24:42 +02:00
Pierre Mesure
213903ad45 Replace sass-rails gem by sassc-rails 2019-10-22 21:59:14 +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
Javier Martín
d29d5ede5a Merge pull request #3764 from consul/rubocop_basic
Apply rubocop basic rules
2019-10-22 18:49:23 +02:00
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