Commit Graph

37 Commits

Author SHA1 Message Date
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
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
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
9fe8c47528 Apply Rails/SafeNavigation rubocop rule 2019-09-10 21:43:39 +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
lalo
7c9c50f4c6 Add Model changes to work with votation_types 2019-06-12 19:32:41 +02:00
Julian Herrero
8e0bbf54f6 Replace harcoded images and documents settings 2019-06-04 11:50:09 +02:00
Bertocq
b8dbdaf9a7 Move question most voted answer from boolean to a enumerable max by total_votes 2019-05-21 13:26:44 +02:00
Bertocq
f4260788eb Add Partial Results counts to question answers 2019-05-21 13:26:44 +02:00
decabeza
cb22e6cbfb Merge branch 'master' into proposal-dashboard 2019-04-23 17:12:47 +02:00
Angel Perez
01c1ac2b10 Replace all occurrences of ActiveRecord::Base with ApplicationRecord 2019-04-17 17:40:56 +02:00
decabeza
eda6ea7f12 Merge branch 'master' into dashboard 2019-03-26 16:45:48 +01:00
Senén Rodero Rodríguez
c73aae9663 Remove before validation callback
This was breaking nested poll_questions_answers when submitting
more than one new answer at a time.
2019-03-21 14:51:17 +01:00
Julian Herrero
3ba961a2d7 Use double quotes in models 2019-03-14 17:25:43 +01:00
Juanjo Bazán
4cccb93677 fix poll accuracy results using floats 2018-11-11 14:54:35 +01:00
Javi Martín
863b326142 Validate both the model and its translations
This way we guarantee there will be at least one translation for a model
and we keep compatibility with the rest of the application, which
ideally isn't aware of globalize.
2018-10-22 16:30:28 +02:00
Javi Martín
2ab49a1832 Refactor globalize models code using a concern
I've chosen the name "Globalizable" because "Translatable" already
existed.
2018-10-22 16:28:53 +02:00
Javi Martín
e0b9c1bfdd Update poll question answers translatable fields
We needed to bring back support for CKEditor in our translatable form,
which we had temporarily remove.

And now we support CKEditor in our translatable specs, and so we can
remove the duplicated specs for poll question answers.
2018-10-22 16:13:48 +02:00
Julian Herrero
46030c72e8 remove unnecessary parameter 2018-09-21 20:53:20 +02:00
Julian Herrero
673ec075eb Make answers translatable 2018-09-20 17:13:40 +02:00
Bertocq
db54273dad Replace == 0 comparisions for .zero? 2017-11-13 02:27:38 +01:00
Bertocq
cd66ba5d54 Rubocop autocorrections 2017-11-13 02:22:00 +01:00
María Checa
e85c98f4b4 Improved results and stats percentages 2017-10-20 17:18:54 +02:00
María Checa
9bbf0b1ef9 Improved most_voted method 2017-10-20 16:48:54 +02:00
María Checa
6e680c187f Added new column most_voted to Poll::Question::Answers 2017-10-19 12:17:20 +02:00
María Checa
610aea2c72 Added new methods to Poll question and Poll answers 2017-10-17 18:30:20 +02:00
Bertocq
34c278db74 Small fixes for Poll Question Answer ordering 2017-10-11 12:05:20 +02:00
iagirre
644d09ebd2 PR comments applied and poll_question_answer default name changed in factory. 2017-10-11 09:42:52 +02:00
iagirre
943c1f23af Spects added to test the order of answers. Default order for question_answers set. 2017-10-10 16:38:55 +02:00
iagirre
2b10b59e2a Order in the admin page using jquery-ui sortable widget. 2017-10-10 16:38:29 +02:00
decabeza
de9b599578 Merge branch 'master' into question-answer-documents 2017-10-06 13:55:49 +02:00
María Checa
6192ea8b78 Added documents to Poll::Question::Answer 2017-10-06 01:17:23 +02:00
Raimond Garcia
c72f95c72b Merge branch 'master' into aperez-admin-question-videos 2017-10-06 01:12:22 +02:00
rgarcia
1cf9bc4ad1 adds images to anwers 2017-10-04 23:56:09 +02:00
Angel Perez
32f3b643b0 Create 'poll_question_answer_videos' table and model 2017-10-04 17:25:51 -04:00
rgarcia
4aaf681d2d uses new answer model in user facing interface 2017-10-04 17:45:51 +02:00
rgarcia
461410a79d adds consistency to answer's namespace 2017-10-04 17:06:29 +02:00