Commit Graph

10063 Commits

Author SHA1 Message Date
Sebastia
ebac669fd0 Merge pull request #6125 from consuldemocracy/remove-obsolete-scopes
Add missing investments filter on admin activity page
2025-11-14 15:38:25 +01:00
taitus
4e455578d1 Rename User.by_authors to with_ids
The "by_authors" scope was the last remaining name from the removed
family of `by_author` scopes. It no longer reflects its purpose: it
simply loads users by IDs.
2025-11-14 14:52:52 +01:00
taitus
a3a44f527b Give purpose to previously unused on_budget_investments scope
The "on_budget_investments" scope in Activity has never been used
anywhere in the codebase. It was introduced in commit d9d38482b3
("extends Activity to include Investment valuations") but no references
were ever added.

Instead of removing it, we make use of the scope by adding the missing
"Budget investments" filter to the admin Activity section. This aligns
it with the rest of the activity filters and gives the scope the purpose
it was originally intended for.
2025-11-14 14:31:01 +01:00
taitus
0332160627 Remove unused by_official_level scope from Proposal
The "by_official_level" scope in Proposal is no longer used anywhere in
the code. Its last use was removed in commit 9f1f912d84 ("Remove
official level filter from advanced search").
2025-11-14 13:56:11 +01:00
taitus
4183734468 Remove unused sort_by_most_commented scope from Debate
The "sort_by_most_commented" scope in Debate is no longer used anywhere in
the code. Its last use was removed in commit b89f39bfef ("Removes
unused orders from debates controller")
2025-11-14 13:56:11 +01:00
taitus
8938b781c3 Remove unused created_by scope from Proposal
The "created_by" scope in Proposal is no longer used anywhere in the code.
It was introduced in 77dd604 and its last usage was dropped in commit 64258baf97
("Refactor getting the public activity information").
2025-11-14 13:44:12 +01:00
taitus
29f4edd466 Remove unused scopes from Legislation::Proposal
The "for_render", "sort_by_hot_score" and "sort_by_most_commented"
scopes in Legislation::Proposal are no longer used
anywhere in the code. They were all introduced in commit 335399e571
("Created Legislation Proposals model") and have never been
referenced since.
2025-11-14 13:44:12 +01:00
taitus
c4368b077a Remove unused by_geozone_id scope from Poll
The "by_geozone_id" scope in Poll is no longer used anywhere in the code.
It was first introduced in commit 20cb044015 ("adds search and filter
for poll questions") and later moved to the Poll model in commit
d024505960 ("moves geozones from poll question to poll in models"),
but has never been referenced since.
2025-11-14 13:44:12 +01:00
taitus
151b12bd35 Remove unused by_email scope from VerifiedUser
The "by_email" scope in VerifiedUser is no longer used anywhere in the
code. Its last occurrence was removed in commit 76daee1fb0 ("removes
unmasked emails and phones in forms").
2025-11-14 13:44:12 +01:00
Javi Martín
2c74f9f35b Merge pull request #6123 from consuldemocracy/max_empty_lines
Add and apply stylistic/max-empty-lines rule
2025-11-06 13:25:39 +01:00
Javi Martín
a563108a03 Merge pull request #6124 from consuldemocracy/menu_button_flashing
Don't flash the menu button on desktop screens
2025-11-06 13:25:00 +01:00
Javi Martín
3584ab048c Replace word-break: break-word with overflow-wrap
According to W3C documentation [1]:

> For compatibility with legacy content, the word-break property also
> supports a deprecated break-word keyword. When specified, this has the
> same effect as word-break: normal and overflow-wrap: anywhere,
> regardless of the actual value of the overflow-wrap property.

This is currently *not* detected by the `property-no-deprecated`
stylelint rule. However, since this rule detects other places where we
should use `overflow-wrap`, we're changing it as part of the same pull
request.

Note that, as of November 2025, 98.22% of the browsers support
`overflow-wrap: anywhere`. We're still making this change because we
only use this property in two specific places and it isn't very likely
that long words will really be a problem with the remaining 1.78%.

By the way, I'm not sure why we use this property in the budget
invesment show paragraphs and not in other similar places. It was
introduced in commit e3878ff43, alongside other changes which don't seem
to be related. When in doubt, we leave things as they were, so we're
doing the same thing here.

[1] https://www.w3.org/TR/css-text-3/#word-break-property
[2] https://caniuse.com/mdn-css_properties_overflow-wrap_anywhere
2025-11-05 20:16:19 +01:00
Javi Martín
d063475769 Use CSS instead of utility classes in options table
This way we make it easier to customize this component. In this specific
case, ideally we'd remove some of the CSS as well. For now we're leaving
it as it was for compatibility reasons.
2025-11-05 19:57:33 +01:00
Javi Martín
2d72144048 Extract component to render question options table
This way it's easier to know that the styles for the `break` HTML class
and the JavaScript for sortable elements (which we shouldn't use, by the
way, because of its accessibility issues) are only used here.
2025-11-05 19:57:33 +01:00
Javi Martín
d6f6b94ae4 Fix wrong selector for sortable tables
We renamed the HTML class to `table-sortable` in commit 99f8bb449. It
was incorrectly being applied to the question options table.
2025-11-05 19:57:27 +01:00
Javi Martín
a5e788dde4 Add and apply property-no-deprecated stylelint rule
This rule was introduced in stylelint 16.23. Out of the deprecated
properties it detects, we were only using `word-wrap`.

According to the CSS Working Group [1]:

> For legacy reasons, UAs must treat word-wrap as a legacy name alias of
> the overflow-wrap property.

Since there's universal browser support for `overflow-wrap: break-word`
[2], we can safely replace `word-wrap` with `overflow-wrap`.

[1] https://drafts.csswg.org/css-text/#overflow-wrap-property
[2] https://caniuse.com/mdn-css_properties_overflow-wrap_break-word
2025-11-05 19:56:00 +01:00
Javi Martín
ad654949ab Add and apply stylistic/max-empty-lines rule
We were already using a similar rule in Ruby files.
2025-11-05 14:34:00 +01:00
Javi Martín
8d7deef413 Don't flash the menu button on desktop screens
The button flashed briefly when loading the page. This was even more
obvious when using devices with slow internet connections.

Using CSS instead of JavaScript to hide the menu solves the issue, since
styles are loaded before scripts.
2025-11-05 14:33:09 +01:00
Javi Martín
618fc4b2c0 Move responsive menu styles to its proper file
We forgot to do so in commit 49cb6e010.
2025-11-05 14:33:09 +01:00
Javi Martín
d18c627392 Add and apply Layout/EmptyLinesAfterModuleInclusion rule
This rule was added in rubocop 1.79. We were inconsistent about it, so
we're adding it to get more consistency.
2025-11-05 14:27:12 +01:00
Javi Martín
7f749bb9bb Add and apply Style/CollectionQuerying rubocop rule
This rule was added in rubocop 1.77. We were following it most of the
time. It makes the code more readable in my humble opinion.
2025-11-05 14:27:12 +01:00
dependabot[bot]
1fa3cf8ce7 Bump rubocop from 1.76.1 to 1.81.1
This release includes some updates in the Style/RedundantParentheses and
Naming/PredicateMethod rules. We're changing the code accordingly.

Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.76.1 to 1.81.1.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.76.1...v1.81.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-05 14:27:11 +01:00
Javi Martín
413d0ed9be Return the persisted line in add_investment
This method was returning a boolean value and caused a
`Naming/PredicateMethod` when upgrading rubocop.

So, instead, we're returning the created line when it was successfully
created, and `nil` when it wasn't.

Having said that, I'm not sure why we added the `.persisted?` back in
commit 3eb22ab7b since as far as I can tell we don't use the return
value for anything. The test added in commit da43e9e2e for this change
passes if we simply return `lines.create(investment: investment)`.

For now I'm leaving the `persisted?` check just in case, but removing it
might be fine.
2025-11-05 14:27:11 +01:00
Javi Martín
15f7632f3d Refactor notifiable_available? method
This method was calling `check_availability`, which returned a boolean
value and caused a `Naming/PredicateMethod` when upgrading rubocop.

So we're changing the logic a little bit to remove the
`check_availability` method and merge the tests of `check_availability`
and `notifiable_available?` (which were almost identical) together.
2025-11-05 14:27:11 +01:00
Javi Martín
2fdfefe55d Use Verification::Email.valid_token? instead of .find
This way it's more obvious that the method is supposed to return a
boolean. When upgrading rubocop, we get a `Naming/PredicateMethod` error
due to `.find` returning a boolean.
2025-11-05 14:27:11 +01:00
Javi Martín
0ca94e5443 Add and apply Rails/FindByOrAssignmentMemoization rule
This rule was added in rubocop-rails 2.33.

At first, I wasn't very fond of this rule. It made the code less
readable even if it improved performace in some cases.

Then I realized that in the `Admin::MachineLearning::SettingComponent`
we were using `find_by` when we should be using `find_by!` instead, and
we detected that thanks to this rule.

So, only for that reason, I'm adding this rule, but I'm fine if we
remove it.
2025-11-05 11:51:23 +01:00
Javi Martín
048bdb2e9e Add and apply Rails/OrderArguments rubocop rule
This rule was introduced in rubocop-rails 2.33. We were following it
most of the time.
2025-11-05 11:51:23 +01:00
Javi Martín
1404197014 Merge pull request #6129 from consuldemocracy/fix_mark_featured_debate
Fix mark as featured button being rendered to everyone
2025-11-03 15:55:32 +01:00
Sebastia
7cf5e7fdae Merge pull request #6122 from consuldemocracy/obsolete-meta
Remove obsolete Foundation meta generator tag from layout
2025-11-03 15:21:17 +01:00
Javi Martín
251968ae72 Fix mark as featured button being rendered to everyone
We introduced this issue in commit f8faabf7d.

Since this component didn't have any tests (there are system tests for
it, though), we're also adding tests that check that only the right
buttons are rendered when accessing as administrator.
2025-10-31 16:01:33 +01:00
Javi Martín
a70cc6e5b0 Release version 2.4.0 2025-10-27 13:41:10 +01:00
taitus
1e5c14ba8a Remove unused by_author scope from Poll::Recount
The "by_author" scope in Poll::Recount is no longer used anywhere in the
code. It was introduced in commit 6c297ae789 ("Add Poll Recount model,
factory and spec") but has never been referenced since.
2025-10-24 09:39:27 +02:00
taitus
de1401f8e6 Remove unused by_author scope from Poll::PartialResult
The "by_author" scope in Poll::PartialResult is no longer used anywhere in
the code. Its usage was replaced by Poll::Answer.by_author in commit
6bc4f5b307 ("adds Poll::Answer model for web users").
2025-10-24 09:32:26 +02:00
taitus
837a7af444 Remove unused by_author scope from Poll::Answer
The "by_author" scope in Poll::Answer is no longer used anywhere in the
code. Its last occurrence was removed in commit 69eaf66b93 ("Remove
redundant max_votes validation from Poll::Answer")
2025-10-24 09:21:48 +02:00
taitus
d338417432 Remove obsolete Foundation meta generator tag
This meta tag was added years ago as a workaround for
foundation-sites issue 12167, in commit 791b2e12 from PR 4753
("Fix invalid HTML in application layout").

Since we now use foundation-sites >= 6.8.1 (fixed in 6.7.1),
the workaround is unnecessary.
2025-10-23 16:04:34 +02:00
Javi Martín
361e4e08a6 Explicitly add csv to Gemfile
We were getting a warning on staging and production environments:

```
app/models/local_census_records/import.rb:1: warning: csv was loaded
from the standard library, but will no longer be part of the default
gems starting from Ruby 3.4.0.

You can add csv to your Gemfile or gemspec to silence this warning
```

The reason we weren't getting this warning during development is that we
do have `csv` in our `Gemfile.lock`, but only in development
environments, since it's an indirect dependency of pronto. On production
environments, we don't install pronto or its dependencies, though.

We can reproduce the warning locally by temporarily removing the pronto
gems from the Gemfile, running `bundle install` and starting a rails
console.
2025-10-22 21:15:58 +02:00
Javi Martín
4332637c0f Only access SAML single sign-on URL when necessary
We were calling `parse_remote_to_hash` in the Devise initializer, which
runs when the application starts.

That meant that, if we got an exception when calling that method, the
application wouldn't start. We got exceptions if the single sign-on
(SSO) URL isn't available or we aren't providing the right credentials.

So we're moving the call to `parse_remote_to_hash` to
`OmniauthTenantSetup`, which is only called when actually trying to sign
in with SAML.

Since we're moving the code there, we're also unifying the code so SAML
settings are configured the same way for the main tenant and other
tenants, like we did for OpenID Connect in commit c3b523290.

In order to keep the existing behavior, we're caching the result of
`parse_remote_to_hash` in an instance variable. Not sure about the
advantages and disadvantages of doing so over parsing the remote URL
metadata on every SAML-related request.

Note that the SAML tests in `OmniauthTenantSetup` use the `stub_secrets`
method. But this method is called after the application has started,
meaning it doesn't stub calls to `Rails.application.secrets` in
`config/initializers/`. So, before this commit, the code that parsed the
IDP metadata URL wasn't executed in the tests. Since now we've moved the
code but we don't want to depend on external URLs when running the
tests, we need to stub the call to the external URL. Since we're now
stubbing the call, we're adding expectations in the tests to check that
we correctly use the settings returned in that call.
2025-10-22 12:25:43 +02:00
Javi Martín
75f6bebc30 Don't set issuer and idp_metadata in SAML settings
The `issuer` setting was renamed to `sp_entity_id` in omniauth-saml [1],
and it's been deprecated in ruby-saml since version 1.11.0, released on
July 24, 2019 [2].

The ruby-saml code currently uses:

```
      def sp_entity_id
        @sp_entity_id || @issuer
      end
```

So setting `issuer` to the same value as `sp_entity_id` if
`sp_entity_id` is present, as we were doing, has no effect.

On the other hand, neither omniauth-saml nor ruby-saml use the
`idp_metadata_url` and `idp_metadata` settings.

[1] https://github.com/omniauth/omniauth-saml/commit/74ed8dfb3aed
[2] https://github.com/SAML-Toolkits/ruby-saml/releases/tag/v1.11.0
2025-10-22 11:50:56 +02:00
Anamika Aggarwal
86bbfcaa0c Automatically set the redirect URI in OIDC
When we first added OIDC support, we were configuring the redirect URI
in the devise initializer, just like we did for other providers.

Thanks to the changes in the previous commit, that code is no longer in
the devise initializer, which means we can use `url_helpers` to get the
redirect URI.

This means we no longer need to define this URI in the secrets. This is
particularly useful for multitenancy; previously, we had to define the
redirect URI for every tenant because different tenants use different
domains or different subdomains.
2025-10-17 13:46:46 +02:00
Anamika Aggarwal
c3b5232907 Use the same code to configure OIDC for all tenants
We were following the same pattern as we used for other providers like
twitter or facebook, but for OIDC we aren't passing the key and the
secret as separate attributes but only a hash of options. This means we
don't need to duplicate the same logic in the devise initializer and the
`OmniauthTenantSetup` class.

Thanks to these changes, we'll be able to introduce dynamic redirect
URLs for both the default tenant and the other tenants (see next commit).

Note that we could probably apply similar changes for the SAML provider.
We might do so in the future. For other providers, removing the
references to `Rails.application.secrets` broke their configuration when
we tested it back in 2022 as part of the multitenancy feature. We might
check whether that's no longer the case (or whether we made a mistake
during our tests in 2022) in the future.
2025-10-17 13:29:15 +02:00
Anamika Aggarwal
d9a0887dc9 Fix OIDC parameters for non-default tenants
We were using the `client_options` hash for the default tenant, defined
in the Devise initializer, but we forgot to include that key in the
multitenant code. This means OIDC wasn't working when different tenants
used different configurations.
2025-10-17 13:29:15 +02:00
Sebastia
a73c1184fa Merge pull request #6061 from consuldemocracy/poll_text_answers
Add support for essay poll questions
2025-10-16 15:30:22 +02:00
taitus
b1cb6f8372 Exclude open-ended questions from managing physical votes
Also make the :yes_no factory trait create a votation_type_unique
by default, since yes/no questions should always be unique.
2025-10-16 14:31:16 +02:00
taitus
f3050a1aa5 Manage correctly results and stats for open-ended questions
Note that we are not including Poll::PartialResults for open-ended
questions resutls. The reason is that we do not contemplate the
possibility of there being open questions in booths. Manually
counting and introducing the votes in the system is not feasible.
2025-10-16 14:26:30 +02:00
taitus
2a2edd17d1 Move results specs to Polls::ResultsComponent
Running tests at the component level is faster than at the system level,
so we move tests from system/polls/results_spec.rb to the component.

Note that moving these tests removes vote_for_poll_via_web and the visit
to results_poll_path, but both are already covered in other tests. We
also take the opportunity to reuse the method in another test where
it makes sense.

Additionally, the spec title has been reverted from "Results for polls
with questions but without options" to "renders results for polls with
questions but without answers", as it was before commit 8997ed316c.
2025-10-16 11:09:36 +02:00
taitus
5a69ffc619 Reduce duplicated code and simplify code related with link_to_poll method 2025-10-16 11:09:36 +02:00
taitus
5944bb85c5 Use a loop instead of with_collection to render questions
This is what we usually do in components.
2025-10-16 11:09:36 +02:00
taitus
83b206f0b7 Enable voting for open-ended questions in public section 2025-10-16 11:09:36 +02:00
taitus
62e1c13e7e Use option instead of answer text to find multiple answers 2025-10-16 11:09:36 +02:00
taitus
b4b00487cc Add validations for changing votation type 2025-10-16 11:09:34 +02:00