Commit Graph

20065 Commits

Author SHA1 Message Date
Javi Martín
173b1bb07c Make it possible to select investments without JavaScript 2024-10-28 13:41:55 +01:00
Javi Martín
54a48d63e1 Use separate actions to select/deselect investments
This is consistent to what we usually do. Also, we're applying the same
criteria mentioned in commit 72704d776:

> We're also making these actions idempotent, so sending many requests
> to the same action will get the same result, which wasn't the case
> with the `toggle` action. Although it's a low probability case, the
> `toggle` action could result in [selecting an investment] when trying
> to [deselect] it if someone else has [deselected it] it between the
> time the page loaded and the time the admin clicked on the
> "[Selected]" button.
2024-10-28 13:41:50 +01:00
Javi Martín
463112c2ea Use a switch to toggle investment selection
Just like it happened with proposals, the button to select/deselect an
investment wasn't very intuitive; for example, it wasn't obvious that
pressing a button saying "selected" would deselect the investment.

So we're using a switch control, like we do to enable/disable features
since commit fabe97e50.

Note that we're making the text of the switch smaller than in other
places because the text in the investments table it is also smaller
(we're using `font-size: inherit` for that purpose). That made the
button look weird because we were using rems instead of ems for the
width of the button, so we're adjusting that as well.

Also note we're changing the width of the switch to `6em` instead of
`6.25em` (which would be 100px if 1em is 16px). We're doing so because
we used 100 for the minimum width because it's a round number, so
now we're using another round number.
2024-10-28 13:40:27 +01:00
Javi Martín
1b46afc95c Check different content in select investments test
Since we were checking something that was already there, if the form
were submitted using an AJAX request (which is the default with Turbo,
although we don't use it yet), there would be a chance that the request
didn't finish before the test does, leading to potential failures in the
next test.

This way we're also checking that the "Filter" button actually does
something when selecting the "Selected" filter.
2024-10-28 13:39:49 +01:00
Javi Martín
f72daff71f Simplify JavaScript to toggle investment selection
We don't need to replace the whole row, since the changes only affect
the button. Therefore, we don't need to depend on an `inserted` event to
decide which columns to render in that row.
2024-10-28 13:39:49 +01:00
Javi Martín
9e5566cee4 Use a button to toggle investment selection
As mentioned in commit 5311daadf, using buttons for non-GET requests has
several advantages over using links.
2024-10-28 13:39:49 +01:00
Javi Martín
cf0d8258ed Use abilities to allow toggling investment selection
We were checking it in the view, meaning that it was possible to toggle
the selection by sending a custom request even when the investment
wasn't feasible.
2024-10-28 13:39:49 +01:00
Javi Martín
95f36ed52f Simplify code to toggle investment selection
This way it'll be easier to change the link/button used to toggle the
selection.

Note that the conditions in the view seem to be different because we no
longer include the `selected?` condition when rendering the link/button.
However, an investment can only be selected if it's feasible and its
valuation is finished, so writing something like this would have been
redundant:

```ruby
can?(:toggle_selection, investment) &&
  (selected? || investment.feasible? && investment.valuation_finished?)
```

The reason why the previous code was using the `selected?` condition was
to check whether to render the link/button to select or to deselect an
investment. We're now doing that in the Ruby part of the component.
2024-10-28 13:39:42 +01:00
Javi Martín
c78494c100 Extract method to get toggle selection path
This way we simplify the view code.

Since now we only use the `budget` method in one place, we're removing
it.
2024-10-28 13:37:56 +01:00
Javi Martín
fde24870bc Extract component for investment toggle selection
This way it'll be easier to refactor it.
2024-10-28 13:31:34 +01:00
Javi Martín
b9c3e75930 Fix duplicate HTML IDs in investments selection
Since this cell is shown once per row, there were multiple rows with the
same HTML ID on the page.
2024-10-25 17:24:32 +02:00
Javi Martín
73166e164b Simplify HTML for an investment row
Since we define the `data-field` element, we can style each element
individually with CSS.

I'm not sure whether these styles make sense, though. For instance, why
is "Supports" aligned to the center, since it's a number? For now, we're
leaving it as it was.
2024-10-25 17:24:32 +02:00
Javi Martín
607dabbc8a Move admin investments partial to a component
This way it'll be easier to organize the code related to it.
2024-10-25 17:24:32 +02:00
Javi Martín
e4df6426c2 Remove unused JavaScript view in investments admin
This code isn't used since commit c9f31b8e1.

Since we no longer depend on the content of the `#investments` element
being in a separate partial, we're also moving this element to the
partial itself and adding an HTML class to it, like we usually do.

We're also removing the code that loads all the investments in the
`toggle_selection` action, which wasn't needed since commit 3278b3572,
when we stopped rendering all the investments in this action.
2024-10-25 17:24:29 +02:00
Javi Martín
9330cdb304 Extract methods in investment row component
This way we simplify the code a little bit.
2024-10-25 17:19:52 +02:00
Javi Martín
bb42809168 Move investment partial to a component
This way we'll be able to simplify it a little bit.

Note that the original partial didn't include the whole row and only
the cells. Since, most of the time, we include the whole row in
partials, we're slightly modifying the component.
2024-10-25 17:19:42 +02:00
Javi Martín
02b6302f25 Focus the proposal selection switch after pressing it
Since this button is replaced by a new element in an AJAX call, nothing
was focused after pressing it.

So we're reusing the code we used to enable/disable budget phases, which
already dealt with this issue.
2024-10-25 17:15:40 +02:00
Javi Martín
2acaa14705 Make it possible to select proposals without JavaScript
This way, when JavaScript hasn't loaded (for whatever reason),
administrators can still use this functionality.
2024-10-25 17:12:47 +02:00
Javi Martín
4a2fc50c76 Use separate actions to select/deselect proposals
This is consistent to what we usually do. Also, we're applying the same
criteria mentioned in commit 72704d776:

> We're also making these actions idempotent, so sending many requests
> to the same action will get the same result, which wasn't the case
> with the `toggle` action. Although it's a low probability case, the
> `toggle` action could result in [selecting a proposal] when trying to
> [deselect] it if someone else has [deselected it] it between the time
> the page loaded and the time the admin clicked on the "[Selected]"
> button.
2024-10-25 17:12:47 +02:00
Javi Martín
fec44c146c Use a switch to toggle proposal selection
The button to select/deselect a proposal wasn't very intuitive; for
example, it wasn't obvious that pressing a button saying "selected"
would deselect the proposal.

So we're using a switch control, like we do to enable/disable features
since commit fabe97e50.
2024-10-25 17:12:44 +02:00
Javi Martín
b127bd2f51 Use a button to toggle proposal selection
As mentioned in commit 5311daadf, using buttons for non-GET requests has
several advantages over using links.
2024-10-25 17:10:14 +02:00
Javi Martín
43b6ab00e3 Simplify method to get the toggle selection path 2024-10-25 16:40:34 +02:00
Javi Martín
3febe3f0cc Extract methods in toggle selection component 2024-10-25 16:40:34 +02:00
Javi Martín
3cebce9a29 Extract link to toggle selection to a component 2024-10-25 16:40:32 +02:00
Sebastia
5251fbadd9 Merge pull request #5698 from consuldemocracy/dependabot/bundler/omniauth-google-oauth2-1.2.0
Bump omniauth-google-oauth2 from 1.1.1 to 1.2.0
2024-10-24 15:13:56 +02:00
dependabot[bot]
1b0b03d52f Bump omniauth-google-oauth2 from 1.1.1 to 1.2.0
Bumps [omniauth-google-oauth2](https://github.com/zquestz/omniauth-google-oauth2) from 1.1.1 to 1.2.0.
- [Release notes](https://github.com/zquestz/omniauth-google-oauth2/releases)
- [Changelog](https://github.com/zquestz/omniauth-google-oauth2/blob/master/CHANGELOG.md)
- [Commits](https://github.com/zquestz/omniauth-google-oauth2/compare/v1.1.1...v1.2.0)

---
updated-dependencies:
- dependency-name: omniauth-google-oauth2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-24 12:49:35 +00:00
Sebastia
389e2c410e Merge pull request #5567 from consuldemocracy/dependabot/bundler/omniauth-rails_csrf_protection-1.0.2
Bump omniauth-rails_csrf_protection from 1.0.1 to 1.0.2
2024-10-24 14:47:36 +02:00
Sebastia
b299e3a2d6 Merge pull request #5524 from consuldemocracy/dependabot/npm_and_yarn/blueimp-file-upload-10.32.0
Bump blueimp-file-upload from 9.34.0 to 10.32.0
2024-10-24 14:47:20 +02:00
Javi Martín
126e7bb2a9 Merge pull request #5754 from consuldemocracy/wait_for_suggestions
Wait for suggestions in multitenancy and document tests
2024-10-24 11:49:37 +02:00
dependabot[bot]
5b7cceba75 Bump blueimp-file-upload from 9.34.0 to 10.32.0
Dependabot couldn't find the original pull request head commit, d43fa0a66e16638f88de33f362c21d50f527c219.
2024-10-24 07:08:00 +00:00
Javi Martín
9da582cb91 Wait for suggestions in multitenancy and document tests
In commit f638e5017 we introduced some methods to avoid race conditions
in tests that created debates, proposals or investments.

However, since we don't have a way to effectively make sure we use these
methods in new code, we forgot to do so when adding tests in commits
c483c6036 and 84b88c0ec.

So we're using them now.

There's a chance that this is what was causing multitenancy tests to
fail sometimes; if we don't wait for the request to get the suggestions
to finish, the application might still be dealing with this request when
we make another request to a different subdomain, or when the test has
finished and the tenant has already been deleted.

On my machine, the test "Creating content in one tenant doesn't affect
other tenants" failed about 5% of the time without these changes, and I
haven't been able to reproduce this failure after applying them. Having
said that, it's possible that this is a coincidence and that this test
will fail for a different reason in the future (like `login_as` not
working properly with subdomains).
2024-10-23 21:04:06 +02:00
Javi Martín
ea3f3225de Merge pull request #5552 from consuldemocracy/dependabot/bundler/omniauth-facebook-10.0.0
Bump omniauth-facebook from 9.0.0 to 10.0.0
2024-10-23 19:05:22 +02:00
dependabot[bot]
4baa95318f Bump omniauth-facebook from 9.0.0 to 10.0.0
Bumps [omniauth-facebook](https://github.com/simi/omniauth-facebook) from 9.0.0 to 10.0.0.
- [Release notes](https://github.com/simi/omniauth-facebook/releases)
- [Changelog](https://github.com/simi/omniauth-facebook/blob/master/CHANGELOG.md)
- [Commits](https://github.com/simi/omniauth-facebook/commits)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-23 14:05:32 +00:00
dependabot[bot]
93cfb67d15 Bump omniauth-rails_csrf_protection from 1.0.1 to 1.0.2
Bumps [omniauth-rails_csrf_protection](https://github.com/cookpad/omniauth-rails_csrf_protection) from 1.0.1 to 1.0.2.
- [Release notes](https://github.com/cookpad/omniauth-rails_csrf_protection/releases)
- [Commits](https://github.com/cookpad/omniauth-rails_csrf_protection/compare/v1.0.1...v1.0.2)

---
updated-dependencies:
- dependency-name: omniauth-rails_csrf_protection
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-10-23 12:43:27 +02:00
taitus
41f1243379 Bump graphql from 1.13.22 to 2.0.31 2024-10-17 17:18:15 +02:00
Sebastia
0cc6de088e Merge pull request #5743 from consuldemocracy/release_2.2.2
Release version 2.2.2
2024-10-15 16:41:16 +02:00
taitus
64e9d28479 Release version 2.2.2 2024-10-15 16:11:09 +02:00
Javi Martín
a3bdf04a4c Merge pull request #5747 from consuldemocracy/disable_turbolinks_previews_in_tests
Make sure requests finish in ballots back link tests
2024-10-15 16:10:59 +02:00
Javi Martín
27a4dc1471 Check page content in ballots specs
Even after disabling the turbolinks previews in the previous commit
(which is still necessary, even with the changes in this commit), these
tests were still finishing before the "Go back" requests did. To
reproduce an issue caused by this behavior, run:

```
rspec spec/system/budgets/ballots_spec.rb:425 spec/system/users_auth_spec.rb:701 --seed 40358
```

Apparently, a `have_current_path` expectation isn't enough to check that
the request has finished and it only checks that the request to that
path has started or it's being processed.

Adding an additional expectation to check that the content of the page
has changed solves the issue.
2024-10-15 15:55:15 +02:00
Javi Martín
b870e29170 Disable turbolinks previews in the test environment
When clicking the browser's back button, browsers usually don't reload
the page but show a cached version of the page.

Turbolinks takes this one step further. When clicking on a link to a
page that's already cached, turbolinks displays the cached version of
the page and then it reloads it.

I don't really like this behavior but, since it affects the whole
application and we're about to release a patch version :), for now we're
keeping it this way in the development and production environments.

In the test environment, however, we're disabling these previews because
they might lead to requests leaking between tests.

For example, a test that visits the investments index, then goes to
"check my votes", then clicks on "Go back" and finishes by checking some
content on this page will result in those checks being done against the
cached version of the page. If these checks pass before turbolinks
reloads the page, the "Go back" request will finish during the test that
runs immediately after this one, resulting in unpredictable results.

Disabling the previews solves the issue.
2024-10-15 14:44:26 +02:00
Javi Martín
62d2f9e180 Merge pull request #5742 from consuldemocracy/legislation-proposals-videos
Fix crash in legislation proposals with videos
2024-10-15 10:34:29 +02:00
taitus
93189d3ecd Allow use embedded_video_component in legislation proposals
Since the PR "Do not use third-party cookies in embedded videos #5548", the logic from
"embed_videos_helper" was extracted to the "embedded_video_component" and the
"videoable" model concern.

However, during this refactor, the "regex" method, which uses record.class:: to handle
video embeds, was left inaccessible for Legislation Proposals.

This commit fixes the issue by including the concern in the Legislation Proposal model.
2024-10-14 15:24:29 +02:00
Javi Martín
53688863cd Merge pull request #5741 from consuldemocracy/ubuntu-24.04-github-actions
Make github actions workflows compatible with Ubuntu 24.04
2024-10-14 14:36:53 +02:00
Javi Martín
1e6ff7838f Merge pull request #5738 from consuldemocracy/dashboard_factories
Fix default dashboard actions factories
2024-10-14 14:14:53 +02:00
Javi Martín
13481fdf32 Use Ubuntu 24.04 in our workflows
This is what github actions currently uses when using ubuntu-latest, and
what we recommend for new Consul Democracy installations.
2024-10-14 14:02:28 +02:00
Javi Martín
26ebe619e3 Use a specific version of Ubuntu in workflows
Using ubuntu-latest might result in incompatibilities when this image
changes to a different version of Ubuntu. For example, the Ubuntu 24.04
image no longer includes imagemagick, meaning that we'll have to install
it manually when using Ubuntu 24.04.
2024-10-14 13:47:30 +02:00
Sebastia
6876441eaa Merge pull request #5627 from consuldemocracy/dependabot/bundler/savon-2.15.1
Bump savon from 2.15.0 to 2.15.1
2024-10-14 09:28:27 +02:00
Javi Martín
e2d9d0f2b4 Fix default dashboard actions factories
We had a trait called `:admin_request` for actions that are requests to
administrators, but the default factories were also requests to
administrators.

The tests checking that the "Request" button is not present, which
shouldn't pass with the wrong default factories, were passing by
coincidence. The issue was that we weren't checking whether that the
request had finished before checking that the "Request" button wasn't
present. That meant that we were checking that the "Request" button
wasn't there right at the moment we pressed the link, before the request
was finished.

So we're now checking that the request is finished before checking that
the button isn't there.

On the other hand, the tests checking for the "Request resource" link
being present were checking a behavior that's no longer there since
commit 9d85b3935, when we changed the conditions affecting that link.
2024-10-11 15:05:24 +02:00
Sebastia
d3a039040c Merge pull request #5722 from consuldemocracy/dependabot/bundler/rubocop-rails-2.26.2
Bump rubocop-rails from 2.25.1 to 2.26.2
2024-10-10 15:03:08 +02:00
Sebastia
c529fec80f Merge pull request #5705 from consuldemocracy/dependabot/bundler/rubocop-1.66.1
Bump rubocop from 1.64.1 to 1.66.1
2024-10-10 15:01:56 +02:00