Commit Graph

420 Commits

Author SHA1 Message Date
Javi Martín
2b962f2789 Use a <main> tag on every page
Many pages had this tag, but many other didn't, which made navigation
inconsistent for people using screen readers.

Note that there are slight changes in two pages:

* The homepage now includes the banner and the content of the
  `shared/header` element inside the <main> tag
* The budgets index now includes the banner inside the <main> tag

I see both potential advantages and disadvantages of this approach,
since banners aren't necessarily related to the main content of a page
but on the other hand they aren't the same across pages and people using
screen readers might accidentally skip them if they jump to the <main>
tag.

So I'm choosing the option that is easier to implement.

Note we're adding a `public-content` class to the <main> element in the
application layout. This might be redundat because the element could
already be accessed through the `.public main` selector, but this is
consistent with the `admin-content` class used in the admin section, and
without it the <main> element would sometimes have an empty class
attribute and we'd have to use `if content_for?(:main_class)` or
`tag.main` which IMHO makes the code less consistent.

The Capybara::DSL monkey-patch is only done on the `visit` method
because it's the only reliable one. Other methods like `click_link`
generate AJAX requests, so `expect(page).to have_css "main", count: 1`
might be executed before the AJAX request is finished, meaning it
wouldn't properly test anything.
2024-03-23 00:35:43 +01:00
taitus
fd5fa2da79 Refactoring: Move 'vote' action to Votes Controllers
As far as possible I think the code is clearer if we use CRUD actions
rather than custom actions. This will make it easier to add the action
to remove votes in the next commit.

Note that we are adding this line as we need to validate it that a vote
can be created on a debate by the current user:

```authorize! :create, Vote.new(voter: current_user, votable: @debate)```

We have done it this way and not with the following code as you might
expect, as this way two votes are created instead of one.

```load_and_authorize_resource through: :debate, through_association: :votes_for```

This line tries to load the resource @debate and through the association
"votes_for" it tries to create a new vote associated to that debate.
Therefore a vote is created when trying to authorise the resource and
then another one in the create action, when calling @debate.vote_by (which
is called by @debate.register_vote).
2023-10-09 07:21:49 +02:00
taitus
c96e3b027f Replace Partials with Direct Component Rendering
In this commit, we have performed a refactoring to enhance code organization.
Several partials that were solely responsible for rendering components have been removed.

Instead, we are now directly rendering the components within the views where these
partials were previously used.
2023-10-06 18:13:45 +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
taitus
af00dd94db Unify the order in which we display information
In the rest of the similar sections of the application we show the date first
and then the information of the comments.
2022-08-19 15:40:51 +02:00
taitus
2865ee286f Add comments count component
Remove all the translations that are left over after having unified them
in the component.
2022-08-19 15:40:51 +02:00
taitus
a32e249919 Remove &nbsp; after icon-comments
At some other time we will try to remove all the &nbsp;

For now we start with what we added after the comments icon.
2022-08-19 14:25:30 +02:00
Javi Martín
5c0aa42351 Remove duplication in search results summary
We were using very similar code for proposals, debates and investments,
so we might as well share the code between them.

Note we're using the `proposals.index.search_results` key even for
debates and investments. This will still work because the translations
shared the same text, but IMHO we should rename the key to something
like `shared.search_results_summary`. We aren't doing so because we'd
lose all the existing translations.
2022-04-12 14:23:14 +02:00
Javi Martín
3752fef6bf Remove map page in debates
The map feature was never implemented for debates (only for proposals
and budget investments) and it was crashing for debates because the page
didn't load the geozones. And we don't have a "geozone" field in the
debates form either.

So we're removing the map page alongside its (pending implementation)
tests.
2022-04-07 15:34:07 +02:00
Javi Martín
b98244afd9 Remove votes query optimizations
Just like we did in commit 0214184b2d for investments, we're removing
some possible optimizations (we don't have any benchmarks proving they
affect performance at all) in order to simplify the code.

The investement votes component `delegate` code was accidentally left
but isn't used since commit 0214184b2, so we're removing it now that
we're removing the `voted_for?` helper method.
2022-02-21 18:47:13 +01:00
Javi Martín
78f372fd0b Move votes partials to components
We're going to change the code quite a bit, and with components we can
easily extract methods when necessary.
2022-02-21 18:47:13 +01:00
Javi Martín
cac24b0159 Extract component to show moderation actions
Note that in proposal notifications we're writing the call to
render the component in the same line as the <div class="reply">
definition in order to be able to use the `:empty` selector when the
component renders nothing. No browser matches whitespace with the
`:empty` selector, so we can't add newline characters inside the tag. A
more elegant solution would be extracting the proposal notification
actions to a component and only rendering it if the moderation actions
component is rendered.
2021-12-30 15:50:03 +01:00
rhian-cs
b27a05cbfd Make confirmation alert message inform the triggering action 2021-12-22 12:32:45 +01:00
Javi Martín
a0ea206d15 Move new debate view to a component 2021-07-13 15:27:14 +02:00
Javi Martín
b162ad512a Remove row and column divs in debate/proposal form
We don't need any row classes anymore because the <body> already has a
maximum width. As for columns, we only have one column in this form, so
we don't need them either. Besides, the form's parent element already
has a padding.
2021-07-13 15:27:13 +02:00
Javi Martín
7bc55f78c0 Rename debate-form HTML classes
So they follow the same convention used in proposals.

Note the styles are for elements which appear in the "new" view but not
in the "edit" view, so we only have to include them in one place.
2021-07-13 15:25:31 +02:00
Javi Martín
755ad330a2 Move debate form partial to a component
We're going to rewrite most of the code, so we might as well treat it
like we treat new files.
2021-07-10 00:14:06 +02:00
Javi Martín
4c47eab608 Move search summary styles to a stylesheet 2021-07-07 15:10:29 +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
1632540984 Remove redundant placeholders in forms
Using placeholders having similar (or identical) text as already present
as a label has a few issues.

First, it's a distraction. Reading the same information twice is
useless, requires an extra effort, and might even frustrate users.

Second, if users start typing before reading the placeholder and see it
disappear, they might think they're missing relevant information,
delete what they typed, and read the placeholder. That will get them
nowhere.

Finally, we display placeholders using a text offering very low contrast
against the background, so users don't think the placeholder is an
actual value entered in the field. Using such low contrast makes the
text hard to read, particularly for users with visual impairments.

So we're removing these placeholders.

This commit only deals with placeholder texts with similar (or
identical) texts as the label text. There might be other places where we
should replace placeholder texts with labels, but that's a different
topic.
2021-06-23 19:52:45 +02:00
taitus
56d3840c40 Extract to help method to fill in the data for the suggestions 2021-04-12 11:04:32 +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
e96f45ba39 Merge pull request #4325 from consul/add_related_list_selector
Add related list selector component to forms
2021-01-22 16:34:10 +01:00
taitus
e6bfeef58d Add SDG::RelatedListSelectorComponent to Debates 2021-01-22 16:04:40 +01:00
Javi Martín
a7bbdb1bd0 Simplify rendering a banner
Now the banner component accepts either a banner or a section and loads
the banner if it's a section, so we don't have to add the `@banners`
variable in several controllers.
2021-01-20 17:22:05 +01:00
Javi Martín
2faf99c54b Extract advanced search into a component 2021-01-10 15:54:23 +01:00
Javi Martín
dda79a9224 Remove unnecessary advanced search path parameter
We can use the current path as URL instead of passing it every time.
Passing the `page: 1` parameter is also redundant since by default the
index goes to the first page and the search form does not send any page
parameter.
2021-01-10 15:54:23 +01:00
Javi Martín
1a902a9671 Use polymorphic_path instead of taggables_path
We forgot to make this change when we started using "resolve" to
generate polymorphic nested resources.

The taggables_path method can be replaced with the polymorphic_path of a
class. It even works with nested resources, given the current page
already has the nested resources params (in this case, `budget_id` for
investments).
2021-01-09 14:17:21 +01:00
Javi Martín
a5f1245b7e Extract partial to refresh flag actions
Now that we're rendering `shared/flag_actions` everywhere, we can use
the same code in all cases.
2020-07-08 11:58:03 +02:00
Javi Martín
31b65679c3 Extract partial to render flag actions
The main obstacle to extract this partial was probably the paths for the
flag and unflag actions.

Now that we use Rails 5.1 `resolve` method to handle nested resources,
we can use `polymorphic_path`.

Also note the code is a bit ugly because comments render a divider. We
should probably use a CSS border instead.

Co-Authored-By: taitus <sebastia.roig@gmail.com>
2020-07-07 23:39:21 +02:00
Javi Martín
bd7beed8a1 Remove no longer necessary flag/unflag HTML IDs
They were added in commit 015fe704 because we used them in the specs,
but we don't use them anymore and they make the code hard to read.
2020-07-07 23:39:21 +02:00
Javi Martín
9937e94fcd Fix flagging debates and comments with AJAX
We weren't using `foundation()` in these cases, so after flagging a
debate or a comment, we had to reload the page before we could unflag
it.

We're also adding a test for the fix in commit ea85059d. This test shows
it's necessary to filter the elements with JavaSctipt using `first()` if
we want the same code to work with comments.

Co-Authored-By: taitus <sebastia.roig@gmail.com>
2020-07-07 22:56:17 +02:00
Javier Martín
e7d557a95c Merge pull request #4004 from consul/shared-banner
Move conditional into shared banner partial
2020-06-18 23:39:32 +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
decabeza
8e01b11569 Move conditional into shared banner partial
To avoid always writing if has_banners? every time the partial is used it has been moved within this partial.
2020-05-08 12:00:03 +02:00
Javi Martín
b483d50d30 Remove unused tag filter
This filter was added in commit 4285ba4b, it was changed in commit
002d8688, and most of the code from the original commit has disappeared
without a trace (maybe due to a merge conflict?).

This filter could actually be useful if we started using it when users
click on a tag. Since we don't, I'm removing it. We might add it back if
we decide to actually use it.
2020-04-08 13:49:48 +02:00
Javi Martín
82b0a6a92d Remove new CSV report generation
The new CSV report was more configurable and could work on proposals,
processes and comments. However, it had several issues.

In the public area, by default it generated a blank file.

In the admin section, the report was hard to configure and it generated
a file with less quality than the old system.

So until we improve this system, we're bringing back the old investment
CSV exporter.

This commit reverts most of commit 9d1ca3bf.
2019-11-06 00:04:02 +01:00
Javi Martín
e844b0b2db Remove CKEditor divs
This way the HTML does not depend on CKEditor, and changing the editor
we use in textareas will require very few changes.
2019-10-25 17:00:18 +02:00
Javi Martín
6ef07f8a54 Use text_area instead of cktext_area
We're going to change CKEditor to an inline editor, and the "ckeditor"
gem doesn't provide an option to do so.

Since using `cktext_area` would automatically generate a "classic"
iframe CKEditor, we need to use `text_area` and load the editor using
JavaScript. Personally I prefer this option anyway.

Note in the jQuery selector we need to use `textarea.html-area`; using
just `.html-area` would fail if there's an error message associated to
the textarea, since Rails will add the `.html-area` class to the error
message.
2019-10-25 16:34:25 +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
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
75a28fafcb Sanitize label texts automatically
This way we can remove all those `html_safe` calls and we avoid
potential XSS attacks in label texts.
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
55a190f44a Remove unneeded _html suffix in I18n keys
This suffix does the same thing as calling `.html_safe` on them. So we
don't need to use it in texts that don't use HTML.
2019-10-08 13:20:22 +02:00
Javi Martín
6fa67b5e53 Use active record translations for labels
This way we can simplify the way we generate form fields. In some cases,
we also use the human attribute in table headers, which IMHO makes
sense.

I haven't moved all of them: for example, sometimes a label is
different depending on whether it's shown to administrators, valuators,
or users. And I haven't touched the ones related to devise, since I
wasn't sure about possible side effects.

Note I've also removed placeholders when they had the same text as their
labels, since they weren't helpful. On the contrary, the added redundant
text to the form, potentially distracting users.
2019-10-07 01:56:23 +02:00
Javi Martín
8d9cb4d8e3 Simplify generating checkboxes in forms
Using the block syntax to generate the label with a <span> tag inside
isn't necessary after upgrading foundation_rails_helpers. Before the
upgrade, we couldn't do so because the <span> tag was escaped.
2019-10-06 19:32:04 +02:00
Javi Martín
4f5de5be3b Add aria-describedby attribute automatically
We were manually adding the attribute in many places, but not
everywhere. I'm assuming adding it where we didn't have it is doing no
harm.
2019-10-06 19:32:03 +02:00