6215 Commits

Author SHA1 Message Date
Javi Martín
5a432da498 Update old usages of investments JSON data
We aren't using these properties since commit 3fa3c90db. An old test was
failing when checking for Axe accessibility issues because of this.
2025-11-17 15:45:28 +01:00
Javi Martín
288f62cdd2 Use coordinates as marker labels when there's only one mappable
When editing/showing a proposal or an investment, the most relevant
information regarding the marker are the coordinates. The title of the
proposal or investment is redundant because we already know the marker
is about that proposal/investment.

There's one problem with this approach, though: when editing a proposal
or an investment, the aria-label of the marker isn't updated
automatically when we move the marker to a different place. This
behaviour will only affect people who use both a screen reader and a
mouse, since keyboard users can't change the position of the marker in
the first place. We'll deal with this issue when we make it possible to
change the position of a marker using the keyboard.
2025-11-17 15:39:36 +01:00
Javi Martín
99696cb302 Add aria-label to markers in admin map settings
We forgot to do so in commit b896fc4bb. Back then, we said:

> Note that we aren't providing a proper aria-label for markers on the
> map we use in the form to create a proposal or an investment. Adding
> one isn't trivial given the current code, and keyboard users can't add
> a marker in the first place. We'll have to revisit this issue when we
> add keyboard support for this.

However, in the admin section, the marker is already there, so it should
have a label. In this case, we're using the coordinates as label because
it's the most relevant text for the marker in the context of a form. We
could also use "Default map location" instead, but that information is
already present on the page.

Axe was reporting the same accessibility error we mentioned in commit
b896fc4bb in this situation.
2025-11-17 15:39:36 +01:00
Javi Martín
1693aa5d9c Use render_map to render the admin settings map
This way we remove duplication.

Note that to check whether to render the button to remove a marker,
we're checking whether the map location belongs to a mappable. This
means we're changing the code that renders the map in the "new proposal"
and "new investment" forms so the map location belongs to a proposal or
investment. We're association the map location to a new record because
writing something like:

```
def map_location
  proposal.map_location || MapLocation.new(proposal: proposal)
end
```

Would change the `proposal` object because of the way Rails treats
non-persisted `has_one` associations. Although probably safe in this
case, changing an object when rendering a view could have side effects.

Also note that we're changing the HTML ID of the map element from
`admin-map` to `new_map_location` (the latter is returned by the
`dom_id` method).  We were only using this ID in tests since commit
289426c1c, so changing it doesn't really affect us.
2025-11-17 15:39:36 +01:00
Javi Martín
8a575ae83c Remove duplicate map location translations
We were using the same texts twice. For the remove marker label text,
however, we were using the text defined in proposals for both proposals
and investments.

Ideally the translation keys for these texts would go in another
namespace, since they no longer refer to just proposals. However,
renaming the translation keys would mean losing the existing
translations in every language we manage through Crowdin. So we aren't
doing so.
2025-11-17 15:39:31 +01:00
Javi Martín
29e5adc233 Move map location fields partial to a component
This way it'll be easier to test it and refactor it.
2025-11-17 15:37:06 +01:00
Javi Martín
8b3ac5ac97 Use a legend instead of a label in map location fields
The label was invalid HTML since it wasn't referencing any existing
element.
2025-11-17 15:28:52 +01:00
Javi Martín
86a12b23ad Test admin map settings from the user's point of view
People using these settings don't know about the hidden fields, but they
do know about the fields that are actually displayed on the page. So we
check that these fields are updated when the marker is updated.
2025-11-17 15:14:20 +01:00
Javi Martín
a6908f2017 Group similar map tests together
We're about to change some of these tests, and we usually group similar
system tests in order to make the test suite a bit faster.
2025-11-17 15:14:16 +01:00
Javi Martín
d0b57868af Move settings map inside the form
That's what we usually do, and it makes sense since clicking on the map
changes the content of hidden fields in the form.
2025-11-17 02:04:11 +01:00
Javi Martín
dd2fb6469f Merge pull request #6144 from consuldemocracy/serious_accessibility_issues
Fix most Axe serious accessibility issues
2025-11-14 15:49:51 +01:00
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
Sebastia
2e4a05f6b9 Merge pull request #6040 from consuldemocracy/remove-redundant-tests
Remove redundant tests
2025-11-14 15:38:08 +01:00
taitus
873968ee0a Unify related tests in wizard phases spec 2025-11-14 15:11:50 +01:00
taitus
3dc0de34bc Unify related tests in wizard headings spec 2025-11-14 15:11:50 +01:00
taitus
d43654be42 Unify related tests in wizard groups spec 2025-11-14 15:11:50 +01:00
taitus
42ef5b65bd Unify similar tests in wizard budgets spec
We are unifying the test "Create budget - Knapsack voting (default)" with
"A new budget is always created in draft mode" because they are almost the same.

On the other hand, we also merged the test "update budget" with "submit the
form with errors and then without errors". Just like in the previous case, there
were two ways to access the edit page, so we removed the one that is already
tested in other specs.
2025-11-14 15:11:22 +01:00
taitus
a9129158c1 Make moderation tests easier to read
- reuse aria-labels instead of DOM selectors when checking moderation checkboxes
- drop redundant 'first' in the within
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
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
Javi Martín
b896fc4bba Add aria-label to map markers
Axe was reporting an accessibility error:

```
Found 1 accessibility violation:

1) aria-command-name: ARIA commands must have an accessible name
   (serious)
   https://dequeuniversity.com/rules/axe/4.11/aria-command-name?application=axeAPI
   The following 1 node violate this rule:

     Selector: .leaflet-marker-icon
     HTML: <div class="leaflet-marker-icon map-marker
                       leaflet-zoom-animated leaflet-interactive"
                tabindex="0" role="button">
                <div class="map-icon"></div>
           </div>
     Fix any of the following:
     - Element does not have text that is visible to screen readers
     - aria-label attribute does not exist or is empty
     - aria-labelledby attribute does not exist, references elements
       that do not exist or references elements that are empty
     - Element has no title attribute
```

Using the title of the proposal/investment as the text of the marker is
definitely a good solution when there are several markers on the map.
Not sure whether there's a better option when there's only one marker,
though.

Note that we aren't providing a proper aria-label for markers on the map
we use in the form to create a proposal or an investment. Adding one
isn't trivial given the current code, and keyboard users can't add a
marker in the first place. We'll have to revisit this issue when we add
keyboard support for this.

We're also changing a test to make sure that titles with quotes in their
names don't break the markup due to an invalid aria-label attribute.
2025-11-14 12:53:37 +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
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
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
4ec2e87c2c Add and apply RSpec/IncludeExamples rubocop rule
This rule was added in rubocop-rspec 3.6. We were already following it
most of the time.
2025-11-05 11:23:49 +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
be6f5857d7 Merge pull request #6113 from consuldemocracy/saml_on_demand
Only access SAML single sign-on URL when necessary
2025-10-22 15:17:04 +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
0cb5d253f8 Use match_array in notifications scopes tests
The scopes don't define the order in which the records are returned, so,
when using `eq`, the tests failed sometimes.
2025-10-22 12:18:37 +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
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
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
taitus
b3f8ba819b Adapt 'show' view for open questions without options
- Prevent creating options for open questions
- Skip rendering the options table when none exist
2025-10-15 15:52:14 +02:00
taitus
d3f32978c8 Hide "Maximum number of votes" message for unique and open-ended questions
The "Maximum number of votes" text in poll question show was unnecessary.
It appeared for both unique and open-ended questions, but it only makes
sense for questions that allow multiple answers.
2025-10-15 15:52:14 +02:00
taitus
69eaf66b93 Remove redundant max_votes validation from Poll::Answer
Since commit 8deb1964b, the `WebVote` class enforces the maximum vote
validation, making the `max_votes` method in `Poll::Answer` redundant.
2025-10-15 15:52:14 +02:00
taitus
4e57e311dc Add support for open-ended questions in admin section
Introduce a new "open" votation type for poll questions in the admin
interface. This type allows open answers provided by the user.
2025-10-15 15:52:12 +02:00
Javi Martín
6d30e2d34e Don't display public activity by default when requiring consent
Just as we mentioned in the previous commit, there are places where we
aren't sure whether explicit consent is strictly required. So, when the
"require consent" setting is enabled, we're taking the safe approach.
This means that, in this case, we're only displaying a user's activity
if they've given explicit consent.
2025-10-09 10:56:21 +02:00
Johann
92a76dd46e Disable recommendations by default when requiring consent
The GDPR is open for interpretation, and it isn't clear whether showing
users recommended proposals and debates while browsing the site is
considered a notification that needs to be explicitly accepted.

Since we aren't sure whether this is necessary, we're taking the safe
approach and disabling recommendations by default.
2025-10-09 10:54:36 +02:00
Javi Martín
a1714fea58 Use the "#" convention in user preferences methods tests
This is a convention we follow most of the time, particularly in the
last few years.
2025-10-09 10:53:04 +02:00
Johann
e7f2210380 Add setting to require consent for notifications
Ensure GDPR compliance by default (Article 25 GDPR – privacy by design
and by default). Under GDPR, consent must be freely given, specific,
informed and unambiguous [1]. We were subscribing users without
explicity consent, which goes against the "No pre-ticked boxes"
principle.

For compatibility with existing installations, we're using a setting,
disabled by default. Once we release version 2.4.0 we will enable it by
default, which won't affect existing installations but only new ones.

[1] https://gdprinfo.eu/best-gdpr-newsletter-consent-examples-a-complete-guide-to-compliant-email-marketing
2025-10-09 10:53:00 +02:00
Johann
208dc01d3b Add tests for newsletter and email digest scopes
These methods didn't have proper model tests.
2025-10-08 15:33:25 +02:00
taitus
2a5985f6ef Update tests for votation type form behavior
Ensure the form toggles descriptions and fields correctly depending on the selected
votation type.
2025-09-26 15:41:09 +02:00