Commit Graph

273 Commits

Author SHA1 Message Date
Javi Martín
9972066b0a Merge pull request #5271 from consuldemocracy/dependabot/bundler/rubocop-rails-2.21.2
Bump rubocop-rails from 2.20.2 to 2.21.2
2023-11-20 17:54:30 +01:00
Javi Martín
0aee568977 Add and apply Rails/RedundantActiveRecordAllMethod
This rule was introduced in rubocop-rails 2.21.0.
2023-11-20 14:22:12 +01:00
dependabot[bot]
21d39bac62 Bump rubocop-rails from 2.20.2 to 2.21.2
Bumps [rubocop-rails](https://github.com/rubocop/rubocop-rails) from 2.20.2 to 2.21.2.
- [Release notes](https://github.com/rubocop/rubocop-rails/releases)
- [Changelog](https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop-rails/compare/v2.20.2...v2.21.2)

---
updated-dependencies:
- dependency-name: rubocop-rails
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Note version 2.21.0 relaxes the default `Include` path for
`Rails/FindEach`, and so this version can find and correct offenses
outside the `app/models/` folder [1].

Also note this version replaces `unless something.include?` with `if
something.exclude?`; since we don't use the `exclude?` method anywhere,
we're removing the `include?` method from the list of methods checked by
this cop.

Finally, the Rails/HttpStatus method now returns a false positive when
rendering a dashboard partial and passing the `status` variable. In
order to avoid this issue, we could change the name of the local
variable or move the partial to a component, but for now we're simply
excluding these files for this cop.

[1] https://github.com/rubocop/rubocop-rails/pull/1059/commits/0066b3505

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-20 14:22:09 +01:00
Javi Martín
0cec581ec0 Add and apply Capybara/RSpec/HaveSelector rule
This rule was added in rubocop-capybara 2.19.0. We were following it
about 85% of the time.

Now we won't have to check both have_css and have_selector when
searching the code.
2023-11-08 14:18:16 +01:00
Sebastia
c1e0d58291 Merge pull request #5274 from consuldemocracy/last-sign-in
ENS: Add security secret "last_sign_in"
2023-10-24 18:57:18 +02:00
Javi Martín
5aa56c054f Mark external links using the "rel" attribute
This will help search engines know these links point to external sites
and it'll make it possible to style these links using the
`[rel~=external]` selector. AFAIK, assistive techonologies don't use
this attribute to notify people about external links, though.
2023-10-24 16:41:03 +02:00
Javi Martín
79c1aa0755 Fix "rel" attribute in footer description links
We were accidentally filtering this attribute when sanitizing the text
since commit 928312e21.
2023-10-24 16:41:03 +02:00
Javi Martín
8053cc5e1c Open footer description links in the same window
This is a funny one, because we were accidentally opening them in the
same window without intending to do so since commit 928312e21, since the
`sanitize` method removes the `target` attribute. So the test we're
adding already passed without these changes.
2023-10-24 16:41:03 +02:00
Javi Martín
56d834783c Open links to social networks in the same window
As mentioned in earlier commits, opening external links in a new
tab/window results in usability and accessibility issues.

Since these links are usually at the top or bottom of the page and
contain icons of well-known sites, IMHO there's no need to even notify
people that these are external links.

Since we're no longer using the `shared.target_blank` translation inside
a sentence, we can remove the space and parenthesis in the translations.
2023-10-24 16:41:03 +02:00
Javi Martín
e19c16d4e2 Indicate that links inside labels open in a new window
Most screen readers don't notify when a link is about to open in a new
window [1], so we're indicating it, like we were already doing in most
places with similar links.

We could also add a visual indicator, but since links inside labels
already have accessibility issues, giving more attention to these links
might make matters worse.

[1] https://www.powermapper.com/tests/screen-readers/navigation/a-target-blank/
2023-10-23 18:19:48 +02:00
Javi Martín
cdf859621e Allow links in forms to open in new tabs
We used to open these links in new tabs, but accidentally stopped doing
so in commit 75a28fafc.

While, in general, automatically opening a link in a new tab/window is a
bad idea, the exception comes when people are filling in a form and
there are links to pages that contain information which will help them
fill in a form.

There are mainly two advantages of this approach. First, it makes less
likely for people to accidentally lose the information they were filling
in. And, second, having both the form and a help page open at the same
time can make it easier to fill in the form.

However, opening these links in new tabs also has disadvantages, like
taking control away from people or making it harder to navigate through
pages when using a mobile phone.

So this is a compromise solution.
2023-10-23 18:19:48 +02:00
Javi Martín
7c6134fdee Unify the way we display document information
We were displaying documents in five places, and in five different ways.
Sometimes with the metadata in parenthesis after the title, sometimes
with the metadata below the title, sometimes without metadata, sometimes
with an icon in front of the document, and sometimes with a separate
link to download the file.

So we're now displaying the same thing everywhere. Not sure whether this
is the best solution, but at least it's consistent.

We aren't unifying the way we display a list of documents, though, since
different sections look pretty different and I'm not sure whether the
same style would look well everywhere.

Note that we're renaming the `document` HTML class in the documents
table to `document-row` so the styles for the `document` class don't
apply here.
2023-10-23 18:15:54 +02:00
taitus
87fc3c572b Add security secret "last_sign_in"
In order to comply with the security measure for the
ENS: "[op.acc.5.r5.2] The user shall be informed of
the last access made with his identity".

We have added a new secret to display the last
access made to the user on the "My account" page.
2023-10-20 08:03:24 +02:00
taitus
718fcba6d8 Allow undo votes in comments votes component 2023-10-09 07:38:01 +02:00
taitus
108a05a66d Allow undo votes in favor against component 2023-10-09 07:21:49 +02: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
5009bf6c37 Add aria-pressed to in comments votes component
In order to the users using screen readers know whether the button is pressed
or not.
2023-10-06 18:13:45 +02:00
taitus
daf9692753 Add aria-pressed to in favor against component
In order to the users using screen readers know whether the button is pressed
or not.
2023-10-06 07:14:07 +02:00
Javi Martín
ea913f9332 Use Capybara methods to find/click/check links
We applied the Capybara/SpecificMatcher in commit f52a86b46.  However,
this rule doesn't convert methods finding <a> tags to methods finding
links because <a> tags only count as links when they've got the `href`
attribute. For instance, in the `xss_spec.rb` file we check what happens
when clicking on an anchor tag because we're testing that the `href`
attribute has been removed and so we can't use `click_link`.

So, basically, we can't enable a rule to automatically detect when we're
using `have_css` instead of `have_link`, but we should still do it
because `have_link` adds an extra check which affects accessibility
since it makes sure the tag has the `href` attribute and so it's
recognizable as a link by screen readers.
2023-09-11 14:10:41 +02:00
Javi Martín
1d5f03be8c Add and apply RSpec/ReceiveMessages rubocop rule
This rule was added in rubocop-rspec 2.23.0. I didn't know this method
existed, and it makes the code more readable in some cases.
2023-09-08 13:31:42 +02:00
Javi Martín
daa35845da Add and apply Style/RedundantStringEscape rule
This rule was added in rubocop 1.37.0. It's particularly useful in the
background image spec, since now there's one less backslash to decipher
when reading the code :).
2023-09-07 13:09:11 +02:00
Javi Martín
f52a86b465 Apply (but don't add) Capybara/SpecificMatcher rule
This rule was added in rubocop-rspec 2.12.0, and we were already
following it most of the time.

However, the rule isn't working correctly in some cases, such as input
selectors, so we aren't enabling it.
2023-09-06 19:00:56 +02:00
dependabot[bot]
af0128860f Bump view_component from 2.78.0 to 3.5.0
Note version 3.0 removed the `controller` and `request` methods used in
component tests, introducing `vc_test_controller` and `vc_test_request`
instead.

Bumps [view_component](https://github.com/viewcomponent/view_component) from 2.78.0 to 3.5.0.
- [Release notes](https://github.com/viewcomponent/view_component/releases)
- [Changelog](https://github.com/ViewComponent/view_component/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/viewcomponent/view_component/compare/v2.78.0...v3.5.0)

---
updated-dependencies:
- dependency-name: view_component
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-05 14:17:36 +02:00
Javi Martín
a1439d0790 Apply Layout/LineLength rubocop rule
Note we're excluding a few files:

* Configuration files that weren't generated by us
* Migration files that weren't generated by us
* The Gemfile, since it includes an important comment that must be on
  the same line as the gem declaration
* The Budget::Stats class, since the heading statistics are a mess and
  having shorter lines would require a lot of refactoring
2023-08-30 14:46:35 +02:00
Javi Martín
b8ed81c5b8 Simplify setting up admin component tests 2023-08-30 14:46:34 +02:00
Javi Martín
cbda85c48d Add and apply Style/LineEndConcatenation rule
We were already using it in most places.

Note that enabling this rule means we've got to change a few lines in
order to follow the LineEndStringConcatenationIndentation rule. In the
link list tests, the easiest way to do so was to use heredoc instead,
which IMHO improves readability over the previous version.
2023-08-18 14:56:17 +02:00
Javi Martín
96a0aa2a88 Add and apply LineContinuationSpacing rubocop rule
So now we're consistent when separating multiline strings.
2023-08-18 14:56:17 +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
32b1fc53e1 Add and appy MultilineOperationIndentation rule
This way it's easier to see when lines are part of multiline
statements and when they belong to `if` statements.
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
Javi Martín
dc3a28675e Use custom translations in components
In the `i18n_translation` initializer, we're overwriting the `t` helper
so calling it uses custom translations if they're available.

However, ViewComponent doesn't use the `t` helper but implements its own
`t` method. So, when calling the `t` method in a component, we weren't
using our implementation of the `t` helper, and so we weren't loading
custom translations.

Using the `t` helper in components solves the issue.

There was a test where we were directly testing a method in a component,
and that method uses the `t` helper. This caused an error when running
the test:

ViewComponent::Base::ViewContextCalledBeforeRenderError:
`#helpers` can't be used during initialization, as it depends on the
view context that only exists once a ViewComponent is passed to the
Rails render pipeline.

Using `render_inline` in the test and testing the generated HTML, as
recommended in the ViewComponent documentation, solves the issue.
2023-08-05 15:28:20 +02:00
Javi Martín
054aef3854 Change URLs to use the new domain 2023-07-12 16:05:33 +02:00
Senén Rodero
37417e5829 Merge pull request #5129 from consul/geozones
Do not show geozones when there are no geozones defined
2023-06-30 17:21:20 +02:00
Javi Martín
286a128a71 Merge pull request #5106 from consul/fix_budget_background_image
Render background images with brackets in their names
2023-06-30 17:20:56 +02:00
karim-semmoud
3a623c070f Add tests for budget images with brackets / quotes 2023-06-27 13:57:51 +02:00
Max Stevens
13bf866c95 Disable the create booths button when the polls function is disabled 2023-06-23 14:33:19 +02:00
Senén Rodero Rodríguez
ca12388005 Do not render proposals geozones when empty 2023-06-19 14:37:01 +02:00
Matheus Miranda
de13e789dd Add polygon geographies to Budgets' map
Note that in the budgets wizard test we now create district with no
associated geozone, so the text "all city" will appear in the districts
table too, meaning we can't use `within "section", text: "All city" do`
anymore since it would result in an ambiguous match.

Co-Authored-By: Julian Herrero <microweb10@gmail.com>
Co-Authored-By: Javi Martín <javim@elretirao.net>
2023-05-31 16:56:15 +02:00
Javi Martín
106dee0040 Remove redundant HTML map classes
The `map` class is applied to the map element by LeafletJS; using it in
the container led to hacks like adding an `inline` class to fix the fact
that the container was using the `height` rule of the `.map` elements.

Even though we don't add styles for them, I'm adding the `budgets-map`
and `budget-investments-map` HTML classes so these elements can still be
easily selected with CSS and JavaScript.
2023-05-31 16:56:12 +02:00
taitus
306e7356c3 Allow translate locales that need to be mapping
It has been detected that for the :pt-BR, :zh-CN and :zh-TW locales,
the translate button was being displayed, but when requesting the
translation, the remote translation validation failed due to:

'''
validates :locale, inclusion: { in: ->(_) {
     RemoteTranslations::Microsoft::AvailableLocales.available_locales }}
'''

That available_locales method did not contemplate these 3 languages
in the format used by the application.

To solve this problem the api response is mapped to return all
locales in the format expected by the application.

Add remote translation model test to ensure that a remote translation
is valid when its locale is pt-BR.

Co-Authored-By: Javi Martín <35156+javierm@users.noreply.github.com>
2023-03-15 15:52:51 +01:00
Sebastia
8f01a25ced Merge pull request #4900 from consul/ballot_hidden_money
Do not show money with hidden money
2023-02-23 15:22:24 +01:00
decabeza
9ef90b1e49 Do not show money with hidden money 2023-02-22 19:27:28 +01:00
Javi Martín
45b9eccfd8 Show valuator group investments to their valuators
When accessing the valuation area, we were only displaying the
investments directly assigned to the current valuator, but we weren't
displaying the investments assigned to that valuator's group.

Using the `assigned_investments_ids` method, which takes the valuator
group into account, solves the issue.

We've also found an issue on our development machines: since we don't
have a unique index per `investment_id` and `valuator_id` in the
`budget_valuator_assignments` table, we've found duplicate records on
this table. When that happened, we were displaying the same investment
several times.

Since now we no longer join this table in the query returning the
investment, this issue is also solved, and we're adding a test for it.
We can now remove the call to the `distinct` method when calculating the
number of investments per heading.
2023-02-20 14:59:31 +01:00
Javi Martín
f7dfe30675 Merge pull request #5078 from consul/link_to_evaluate
Show link to evaluate investments with valuation finished
2023-02-20 14:42:58 +01:00
Javi Martín
b536a7cb77 Extract component for supporting budget admin stats
This is consistent with the component for balloting stats. We're about
to change both components, and the changes are easier to follow if
they're similar.

We're also using consistent names in methods.
2023-02-20 14:21:22 +01:00
Javi Martín
dd28163be7 Show admin heading stats for the current budget
To get the heading where a user voted, we were relying on the
`balloted_heading_id` field.

Our guess is this was done so the total number of users is the same as
the sum of users who voted on a heading. That is, if 2000 people voted
just on the "All city" heading, 1000 voted just on the "North district"
heading, and 500 people voted on both, instead of showing "3500 people
voted in total, 2500 voted in all city, 1500 voted in north district",
we show something like "3500 people voted in total, 2250 voted in all
city, and 1250 voted in north district".

However, this approach has some disadvantages.

The first disadvantage is, the stats aren't correct. In the case above,
2500 voted on the "All city heading", so the statistics for this heading
don't show reality.

The second one is we weren't considering the last heading where users
voted inside the budget being displayed, but the last heading where
users voted, period. That means that, if all the people above voted on a
later budget, the stats for the budget above would become "3500 people
voted in total, 0 voted in all city, and 0 voted in north district".
That also means we were including headings from previous budgets in the
statistics for more recent budgets when people hadn't voted on the
recent ones.

So we're removing the `balloted_heading_id` since its data is lost once
people vote on a new budget. And, in order to show the right stats and
simplify the code, we're no longer trying to add votes just to one
heading when users vote on several headings.

Co-Authored-By: Julian Nicolas Herrero <microweb10@gmail.com>
2023-02-20 14:21:03 +01:00
Javi Martín
76b08398cf Extract component for balloting budget admin stats
We're also moving the tests, but we're keeping one system test in order
to test the controller and the navigation to get to this page.

Note we're slightly changing the order of the methods in the component;
the order of the instance variables was `user_`, `vote_`, `vote_`,
`user_`, which was hard to follow.
2023-02-20 14:20:50 +01:00
Javi Martín
ed4b03c3ed Show link to evaluate after evaluation has finished
This way it's still possible to access the "evaluation finished" filter
in the valuation investments index.
2023-02-17 15:26:49 +01:00
Javi Martín
d5cb01bf98 Split test in budget valuation component
We're going to add more cases and the test for the link to the evaluate
would become too big, so we're splitting it.
2023-02-17 15:25:25 +01:00