Commit Graph

282 Commits

Author SHA1 Message Date
Javi Martín
d5c6d1ffab Open links to images in the same tab
Just like we did for documents in commit cdc5e05d4.
2023-10-24 16:34:29 +02:00
Javi Martín
1a098dfcab Add and apply MultilineMethodCallBraceLayout rule
In order for this rule to work effectively when running `--autocorrect`,
we also need to enable the `ClosingParenthesisIndentation` rule.
2023-08-18 14:56:16 +02:00
Javi Martín
629e208e9d Add and apply ArgumentAlignment rubocop rule
We're choosing the default `with_first_argument` style because it's the
one we use the most.
2023-08-18 14:56:16 +02:00
Javi Martín
8b13daad95 Add and apply rules for multi-line hashes
For the HashAlignment rule, we're using the default `key` style (keys
are aligned and values aren't) instead of the `table` style (both keys
and values are aligned) because, even if we used both in the
application, we used the `key` style a lot more. Furthermore, the
`table` style looks strange in places where there are both very long and
very short keys and sometimes we weren't even consistent with the
`table` style, aligning some keys without aligning other keys.

Ideally we could align hashes to "either key or table", so developers
can decide whether keeping the symmetry of the code is worth it in a
case-per-case basis, but Rubocop doesn't allow this option.
2023-08-18 14:56:16 +02:00
decabeza
717845ff1a Change poll button if results or stats are enabled 2023-01-12 15:19:10 +01:00
decabeza
36e452437e Add questions with mutiple answers to polls public interface
The `reload` method added to max_votes validation is needed because the
author gets here with some changes because of the around_action
`switch_locale`, which adds some changes to the current user record and
therefore, the lock method raises an exception when trying to lock it
requiring us to save or discard those record changes.
2022-10-18 11:04:40 +02:00
Senén Rodero Rodríguez
4eb4851aba Rename component as now it renders all question answers additional information 2022-10-18 10:38:59 +02:00
decabeza
b92b38f48f Show question title before answers additional information 2022-10-18 10:38:59 +02:00
Senén Rodero Rodríguez
8311e7e6b8 Extract component to render answers additional information 2022-10-18 10:38:08 +02:00
Senén Rodero Rodríguez
ed7968349d Extract Poll::Results::Question component to render question results 2022-10-18 10:38:08 +02:00
Senén Rodero Rodríguez
7efd7c89ef Extract Polls::QuestionComponent 2022-10-18 10:38:08 +02:00
Senén Rodero Rodríguez
bd58023a8a Extract polls questions answers partial into a component 2022-10-17 18:03:36 +02:00
Senén Rodero Rodríguez
527d5691f7 Make poll feature work in browsers with javascript disabled
By using the Rails `button_to` helper (which generates a form), and adapting the
response to `html` and `js` formats, the feature works with or without javascript
enabled.
2022-09-22 17:39:57 +02:00
Senén Rodero Rodríguez
64676be246 Remove token column from poll_voters table
As it is no longer used as originally pretended [1][2].

[1] Check consul/consul pull request 1994
[2] Check consul/consul pull request 3539
2022-09-22 10:34:07 +02:00
Senén Rodero Rodríguez
320e1948fc Do not render message when there are zero participants without demographic data 2022-06-14 10:48:48 +02:00
Javi Martín
7212657c02 Remove Paperclip and use just Active Storage 2022-02-23 18:43:48 +01:00
Javi Martín
091abfc944 Use Active Storage to render attachments
This way we fix a bug we mentioned in commit 930bb753c which caused
links to documents to be broken when editing their title because the
title was used to generate the URL of the document.

Note we're still using Paperclip to render cached attachments because
this is the only case where we store files with just Paperclip and not
Active Storage.

With Active Storage, we render attachments just like any other resource,
using `polymorphic_path`. Paperclip included the `url` method in the
model; since the model doesn't have access to the request parameters
(like the host), this was inconvenient because it wasn't possible to
generate absolute URLs with Paperclip.

In order to simplify the code and make it similar to the way we used
Paperclip, we're adding a `variant` method accepting the name of a
variant and returning the variant.
2022-02-23 18:21:38 +01:00
decabeza
9709b267a2 Always show order poll questions by created at
PostgreSQL doesn't guarantee the order of the records, so we have to
specify it if we want the questions to be displayed in a consistent
order.
2021-10-18 13:31:34 +02:00
Javi Martín
6d26ce57cb Show answers with attachments in additional info
We weren't showing the details of answers without a description, even if
they had images, videos or documents. Some users found that behavior
unexpected since the description isn't a mandatory field and so they
left it blank, but they added images to that answer and they didn't
appear on the poll page.

Note we had a condition not to show the title of an answer when it had
no description. I think that condition was redundant because answers
without a description weren't loaded in the first place. Anyway, that
condition doesn't make sense anymore because we're displaying answers
with images but no description.
2021-10-06 16:52:23 +02:00
Javi Martín
c3e0a6b089 Remove duplication rendering comments
We were using the same code 5 times, with the only slight variation
being the extra heading in the debates section.
2021-06-27 23:22:00 +02:00
Javi Martín
6ea9383743 Allow toggling elements with the keyboard
Using `<a>` tags with no `href` means these elements cannot be activated
by keyboard users, so we're replacing them with buttons.

In the future we probably want to add more consistency so all toggle
buttons use the same code. We might also add styles depending on the
`aria-expanded` property.
2021-03-31 13:38:38 +02:00
Javi Martín
f864156b21 Add and apply ClosingErbTagIndent ERB Lint rule
Note this rule does still allow us to add new lines after opening tags;
it just makes sure that if we do, we also add it in closing tags.
Likewise, if we don't add it in the opening tag, it forces us not to add
it in the closing tag either.

I don't have a strong preference about either style; in these cases I've
chosen the latter because it seemed more common in our code.
2021-02-05 17:39:42 +01:00
Javi Martín
19bab5a9dc Add related SDG and targets tags to polls 2021-01-31 13:33:27 +01:00
Javi Martín
0d3c4c8154 Simplify styling tags
This way we won't have to add the `inline-block` and `no-bullet` classes
to other elements and we can define the styles in one place.

Note we're using the `ul.tags` selector instead of just `.tags` to avoid
conflicts with a `div.tags` selector which is used to select tags in a
form. Renaming the selector to `.tag-list` would be better, but we
aren't doing so because it would break custom stylesheets using that
selector.

Also note we're keeping the %tags placeholder selector in `.tags`
selector in the participation.scss file. This is so styles are not
overwritten by selectors like `.debate-show ul li`, which has the same
specifity as `ul.tags li`.
2021-01-27 15:55:21 +01:00
Javi Martín
e5f71d33d0 Fix poll answer images not being displayed
After updating foundation-rails in commit 58071fd6, the orbit slider
stopped working properly. That's because the `.orbit-slide` elements now
use a `position: absolute` rule, and so our rule for `.orbit-container`
elements making their height 100% (which we added in order to be able to
add images with different heights) makes them have a height of 0px,
since now the `.orbit-slide` elements are not part of the document flow
anymore.

Making the `.orbit-slide` elements have relative position fixes this
issue, but introduces a different one, producing a really bad-looking
animation when changing a slide.

So we're disabling the animation as well in order to avoid this jump.

This change also fixes another issue introduced in commit 58071fd6 which
caused slide controls to stop working when changing slides back and
forth.
2020-08-12 17:18:49 +02:00
decabeza
0896701b57 Remove unused document section on polls
This section is not used because it's only possible to add documents to the poll's answers not to the poll itself.
2020-06-18 09:30:25 +02:00
Javi Martín
ae41becd3a Use CSS to hide reply forms
We were using inline styles and passing local variables around, while
the rule we were following is very simple: it's only hidden if it's a
form to reply to a comment.
2020-05-12 23:57:57 +02:00
Javi Martín
4627372a62 Use a <ul> tag for a list of comments
We were using a <ul> tag for a single comment, where the first element
of the list was the comment itself and the second element was the list
of replies.

IMHO it makes more sense to have a list of all comments, where every
element is a comment and inside it there's a list of replies.

We're also rendering the list even if it has no children so it's easier
to add comments through JavaScript. Then we use the :empty CSS selector
to hide the list if it's empty. However, since ERB adds whitespace if we
structure our code the usual way and current browsers don't recognize
elements with whitespace as empty, we have to use the `tag` helper so no
whitespace is added.
2020-05-12 23:57:16 +02:00
Javi Martín
573f861ad1 Don't use comment_flags to cache comments
Flagging a comment automatically updates the comment, so the cache
expires anyway, making the `comment_flags` variable redundant.
2020-05-11 16:09:23 +02:00
Javi Martín
864f750d92 Remove duplication in poll permissions
We were checking for `expired?` and `results_enabled?` in views and
helpers, when we've already defined a rule for accessing stats and
results for a poll.

This way we also fix a bug when stats were enabled but the poll wasn't
finished. In this scenario, the link pointed to the stats page, but when
clicking it we'd get a "you don't have permission" message.

Now the link doesn't point to the stats page anymore.
2019-11-09 19:33:02 +01:00
Javi Martín
af7c37634d Remove poll votation types
Unfortunately this feature wasn't properly reviewed and tested, and it
had many bugs, some of them critical and hard to fix, like validations
being skipped in concurrent requests.

So we're removing it before releasing version 1.1. We might add it back
in the future if we manage to solve the critical issues.

This commit reverts commit 836f9ba7.
2019-10-30 18:48:55 +01: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
Javi Martín
6b1864fbcd Sanitize translations instead of using _html
Using the `_html` suffix in an i18n key is the same as using `html_safe`
on it, which means that translation could potentially be used for XSS
attacks.
2019-10-09 19:46:47 +02:00
Javi Martín
928312e218 Use sanitize in translations with links
Sometimes we're interpolating a link inside a translation, and marking
the whole translations as HTML safe.

However, some translations added by admins to the database or through
crowdin are not entirely under our control.

Although AFAIK crowdin checks for potential cross-site scripting
attacks, it's a good practice to sanitize parts of a string potentially
out of our control before marking the string as HTML safe.
2019-10-08 18:46:21 +02:00
Javi Martín
2aabf79fb4 Rename methods to add auto links to HTML
The name `safe_html_with_links` was confusing and could make you think
it takes care of making the HTML safe. So I've renamed it in a way that
makes it a bit more intuitive that it expects its input to be already
sanitized.

I've changed `text_with_links` as well so now the two method names
complement each other.
2019-10-08 18:46:20 +02:00
Javi Martín
f8bd3d4f39 Extract links to signin and signup to methods 2019-10-05 14:07:24 +02:00
Javi Martín
f5d8badeb6 Extract partial to show "login to comment" message 2019-10-05 14:07:24 +02:00
Javi Martín
78c6f6f7e9 Use the same key for "signin" and "signup" texts
We were using the same texts in several places
2019-10-05 14:07:23 +02:00
Javi Martín
ae64458fce Use the same I18n key for "login to comment" text
We were using several different keys, all of them having the same
translations.
2019-10-05 14:07:23 +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
ee8426c5b5 Indent with spaces instead of tabs 2019-09-10 20:02:15 +02:00
Javi Martín
c62da726b8 Apply SpaceAroundErbTag ERB Lint rule 2019-09-10 20:02:15 +02:00
Javi Martín
cf9e36c767 Replace single quotes with double quotes
Most of these quotes were in the dashboard branch before we added the
rule for double quotes.
2019-09-10 19:21:03 +02:00
Javi Martín
911fe4e481 Simplify calls to render partial
We're also adding a bit of consistency, since most of our calls to
partial rendering omit the `partial` and `locals` keys.
2019-09-04 15:00:36 +02:00
Javi Martín
06be5e132f Fix label in form to add own answer
The label text was always in English, and it wasn't associated with any
input field.

The `SecureRandom` part is a quick hack so we don't get duplicate IDs.
Using "your_answer_#{question.id}" might work as well, but right now I'm
not sure if the form is sometimes rendered twice for the same question.
2019-08-27 17:22:22 +02:00
lalo
c6e4b2480f Add public changes to create and vote Poll:Questions with votation type 2019-06-12 19:44:14 +02:00
decabeza
585f9ea5ab Remove token on views temporally 2019-05-29 15:49:28 +02:00
Javi Martín
45a3d8daf0 Add option to enable advanced stats 2019-05-22 11:50:03 +02:00
Javi Martín
a34b97e843 Extract partials to show advanced stats 2019-05-22 11:50:03 +02:00