Commit Graph

20593 Commits

Author SHA1 Message Date
dependabot[bot]
66c50a3964 Bump rack from 2.2.17 to 2.2.18
Bumps [rack](https://github.com/rack/rack) from 2.2.17 to 2.2.18.
- [Release notes](https://github.com/rack/rack/releases)
- [Changelog](https://github.com/rack/rack/blob/main/CHANGELOG.md)
- [Commits](https://github.com/rack/rack/compare/v2.2.17...v2.2.18)

---
updated-dependencies:
- dependency-name: rack
  dependency-version: 2.2.18
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-25 17:35:03 +00:00
taitus
bc6506da5a Unify Officing and Admin results views
Unify the code from app/views/officing/results/index.html.erb with
app/views/admin/poll/results/_result.html.erb. This prepares the ground
to extract a component in the next commit and avoid duplication.
2025-09-22 14:28:25 +02:00
Javi Martín
3ad2d770e5 Merge pull request #6075 from consuldemocracy/dependabot/bundler/rexml-3.4.2
Bump rexml from 3.4.1 to 3.4.2
2025-09-18 09:20:46 +02:00
dependabot[bot]
f5372f6267 Bump rexml from 3.4.1 to 3.4.2
Bumps [rexml](https://github.com/ruby/rexml) from 3.4.1 to 3.4.2.
- [Release notes](https://github.com/ruby/rexml/releases)
- [Changelog](https://github.com/ruby/rexml/blob/master/NEWS.md)
- [Commits](https://github.com/ruby/rexml/compare/v3.4.1...v3.4.2)

---
updated-dependencies:
- dependency-name: rexml
  dependency-version: 3.4.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-17 19:21:51 +00:00
taitus
896ebc82fd Remove unused go_back_to_new calls and unused error_create key
- Remove two redundant go_back_to_new calls in build_results, since
  @poll.questions.find already raises RecordNotFound if a question
  does not exist.
- Drop the fallback flash translation error_create, which is no longer
  used since commit 592fdffe4e and only remained as a default in
  go_back_to_new.
- Move check_officer_assignment from Officing::BaseController to
  Officing::ResultsController, its only place of use.
2025-09-15 09:49:12 +02:00
Sebastia
086c79993f Merge pull request #6067 from consuldemocracy/update-contribution-docs
Update CONTRIBUTING and README with latest links and suggestions
2025-09-03 14:21:13 +02:00
Lucía Luzuriaga
9120b20d41 Delete .codeclimate.yml 2025-09-02 15:26:12 +00:00
Javi Martín
3cf6e9b1ca Merge pull request #6046 from Anamika1608/oidc_auth
Add support for OIDC authentication
2025-09-01 19:55:10 +02:00
Anamika Aggarwal
5e263baed2 Add OIDC section for sign in and sign up page
- name: :oidc → Identifier for this login provider in the app.
- scope: [:openid, :email, :profile] → Tells the provider we want the user’s ID (openid), their email, and basic profile info (name, picture, etc.).
- response_type: :code → Uses Authorization Code Flow, which is more secure because tokens are not exposed in the URL.
- issuer: Rails.application.secrets.oidc_issuer → The base URL of the OIDC provider (e.g., Auth0). Used to find its config.
- discovery: true → Automatically fetches the provider’s endpoints from its discovery document instead of manually setting them.
- client_auth_method: :basic → Sends client ID and secret using HTTP Basic Auth when exchanging the code for tokens.

Add system tests for OIDC Auth

Edit the oauth docs to support OIDC auth
2025-08-29 12:20:16 +02:00
Javi Martín
bde25273bc Merge pull request #5762 from consuldemocracy/unique_index_on_poll_voters
Add unique index to poll voters table
2025-08-28 15:20:02 +02:00
Javi Martín
6da53b5716 Add unique index to poll voters table
Note that Rails 7.1 changes `find_or_create_by!` so it calls
`create_or_find_by!` when no record is found, meaning we'll rarely get
`RecordNotUnique` exceptions when using this method during a race
condition.

Adding this index means we need to remove the uniqueness validation.
According to the `create_or_find_by` documentation [1]:

> Columns with unique database constraints should not have uniqueness
> validations defined, otherwise create will fail due to validation
> errors and find_by will never be called.

We're adding a test that checks what happens when using
`create_or_find_by!`.

Note that we're creating voters combining `create_with` with
`find_or_create_by!`. Using `find_or_create_by!(...)` with all
attributes (including non-key ones like `origin`) fails when a voter
already exists with different values, e.g. an existing `origin: "web"`
and an incoming `"booth"`. In this situation the existing record is not
matched and the unique index raises an exception.

`create_with(...).find_or_create_by!(user: ..., poll: ...)` searches by
the unique key only and applies the extra attributes only on creation.
Existing voters are returned unchanged, which is the intended behavior.

For the `take_votes_from` method, we're handling a (highly unlikely, but
theoretically possible) scenario where a user votes at the same time as
taking voters from another user. For that, we're doing something similar
to what `create_or_find_by!` does: we're updating the `user_id` column
inside a new transaction (using a new transactions avoids a
`PG::InFailedSqlTransaction` exception when there are duplicate
records), and deleting the existing voter when we get a
`RecordNotUnique` exception.

On `Poll::WebVote` we're simply raising an exception when there's
already a user who's voted via booth, because the `Poll::WebVote#update`
method should never be called in this case.

We still need to use `with_lock` in `Poll::WebVote`, but not due to
duplicate voters (`find_or_create_by!` method will now handle the unique
record scenario, even in the case of simultaneous transactions), but
because we use a uniqueness validation in `Poll::Answer`; this
validation would cause an error in simultaneous transactions.

[1] https://api.rubyonrails.org/v7.1/classes/ActiveRecord/Relation.html#method-i-create_or_find_by
2025-08-28 14:42:30 +02:00
Javi Martín
03c5533cf0 Don't allow users who voted in a booth to vote via web
For the longest time, we've disabled the buttons to vote via web when
people had already voted in a booth. However, we were still allowing
HTTP requests to the actions to vote via web.

So we're adding a condition to prevent it.

The reason why we're changing the controller instead of the abilities
model (which is what we usually do) is that there might be side-effects
to the change. For instance, in the `Polls::PollComponent` class,
there's an `elsif cannot?(:answer, poll)` condition which would have a
different behavior if we changed the abilities model.
2025-08-28 14:42:30 +02:00
Javi Martín
b5d4a32e63 Merge pull request #5897 from consuldemocracy/replace_equalizer_with_flex
Use flex and grid layouts instead of data-equalizer
2025-08-28 14:40:53 +02:00
Javi Martín
29622dcb91 Extract mixin to create a grid layout
We were using similar code and three places. And all of them used
`15rem`, which looked a lot like a magic number. So we're making it the
default value of a mixin, which means replacing it with a less arbitrary
value will be easier.

Note that, for the column gap, we're now using the standard
grid-column-gutter we use in most places. We were using `$line-height`
in a couple of places only because writing it is less verbose.

Since we're now, for the first time, using a very long mixin definition
that we need to split in several lines, we're adding the `param`
exception to the indentation rule. As far as I know, there's no way to
define a rule in Stylelint that requires parameters in multiple lines to
be aligned with the first parameter, which is what we define in Rubocop.
2025-08-28 14:04:03 +02:00
taitus
3b08fa2e05 Use grid instead of Equalizer in dashboard polls 2025-08-27 17:40:45 +02:00
Javi Martín
de303aa1df Extract component to render dashboard polls
Just like we usually do when reorganizing code.
2025-08-27 17:40:45 +02:00
taitus
fc0d79b47b Move dashboard poll partial to component 2025-08-27 17:40:45 +02:00
Javi Martín
150af75e3e Make resources component tests more readable
We're testing things from the user's point of view by finding elements
given their texts, instead of checking for elements with a certain ID.
2025-08-27 17:40:45 +02:00
taitus
1e06e676a4 Move dashboard system tests to resources component specs
We're making the `new_actions_since_last_login` parameter optional in
order to simplify the tests.
2025-08-27 17:40:45 +02:00
taitus
1dc4f1c534 Use grid instead of equalizer in dashboard resources
Move resource cards layout inside #available-resources-section and switch
from equalizer alignment to a responsive grid layout.

Note that using `grid-auto-rows: 1fr` requires us to change the CSS of
the card itself so the "see resource" link remains at the bottom of the
card.
2025-08-27 17:40:45 +02:00
taitus
1f97a996f8 Move resource partial to a component
We're renaming it to ActiveResource in order to better differentiate it
from the DefaultResource component.
2025-08-27 17:40:45 +02:00
taitus
9b0675aa06 Unify dashboard default resources partials to a component 2025-08-27 17:40:45 +02:00
taitus
048c8ce917 Move dashboard resources partial to a component
We're renaming the HTML class (and removing the id attribute, which was
only used in tests) in order to follow our naming conventions.
2025-08-27 17:40:45 +02:00
Javi Martín
4e129e7d9c Use grid instead of equalizer in recommendations
It's August 2025 and support for grid layout has been available in about
99% of the browsers for some time now. All major browsers added support
for grid layouts in 2017, which means our rule to support browsers that
are 7 years old allows us to start using `display: grid`.

Using a grid layout allows displaying a dynamic number of rows while
keepin all of them the same height, the same foundation's equalizer
does, by setting `grid-auto-rows: 1fr`.

And the `grid-template-columns` property lets us use dynamic columns for
all screen sizes, always filling the available space. No need to use
breakpoints.
2025-08-27 17:38:37 +02:00
Javi Martín
34d87dff98 Use a list of links to display recommendations
We were using an <h3> tag with no content associated to it. This is like
having a chapter in a book with only the title.
2025-08-22 13:45:04 +02:00
Javi Martín
054fbf585e Simplify recommended index component parameters
We can get the path if we know the namespace, so we don't need to pass
both of them.
2025-08-22 13:42:41 +02:00
Javi Martín
3347e85017 Use a different parameter name in recommendex index
The problem with "recommended" is that it had identical singular and
plural, which means it wasn't clear whether we were using it to refer to
an item of a collection or to refer to the collection itself.
2025-08-22 13:40:45 +02:00
Javi Martín
34c8559065 Remove helper that returned a polymorphic path
This is similar to what we did in commits 1a902a967 and fa3781059.
2025-08-22 13:38:03 +02:00
Javi Martín
f5793013c9 Remove unused block parameter in recommended index 2025-08-22 13:37:52 +02:00
Javi Martín
a548c497fc Move recommended index partial to a component
Thanks to it, we can slightly simplify the debates view rendering it.
2025-08-22 13:32:04 +02:00
Javi Martín
d34c9905a4 Use flex instead of equalizer in following
We're also removing the padding in the (now called) followables element,
since it caused a gap on the right side of the border of the
`.menu.simple` element.
2025-08-22 13:31:55 +02:00
Javi Martín
909272d879 Move users following partial to a component 2025-08-22 13:25:50 +02:00
Javi Martín
c4d69416ca Use flex instead of equalizer in polls results
Note that the sidebar class isn't used since commit b91b766e9, so we're
removing it.
2025-08-22 13:25:30 +02:00
Javi Martín
22b0c04cf4 Use a component to render poll results
We're also renaming the `poll-results-stats` class to `poll-results`.
The former name was confusing because it had nothing to do with stats.
2025-08-22 13:19:04 +02:00
Javi Martín
8ca941ab02 Use flex in a poll in the polls index
Note we aren't using flex-with-gap because currently (until we decide to
use the `gap` property) this mixin sets a negative margin that would
move the border of this element to the left.
2025-08-22 13:12:10 +02:00
Javi Martín
b00ddfc931 Move helper method to the component 2025-08-22 13:12:10 +02:00
Javi Martín
edfea8f06b Move image-container CSS to the polls component
This is the only place where we use the `image-container` HTML class.
2025-08-22 13:12:10 +02:00
Javi Martín
1b9d321c4e Extract methods in poll status component
This way we remove duplication in the HTML.

We're also adding a test checking what happens when users can vote in
order to test the `render?` method we've added.
2025-08-22 13:09:49 +02:00
Javi Martín
b2a49cd291 Extract component to render the status of a poll
We're renaming the existing HTML class in order to be consistent with
the name of the component.
2025-08-22 12:13:41 +02:00
Lucía Luzuriaga
42dda087a3 Update CONTRIBUTING and README with latest links and suggestions 2025-08-21 09:45:24 +02:00
Javi Martín
6f87a0912c Merge pull request #6063 from consuldemocracy/dependabot/bundler/activestorage-7.1.5.2
Bump activestorage from 7.1.5.1 to 7.1.5.2
2025-08-15 12:51:48 +02:00
dependabot[bot]
4f4bd0f715 Bump activestorage from 7.1.5.1 to 7.1.5.2
Bumps [activestorage](https://github.com/rails/rails) from 7.1.5.1 to 7.1.5.2.
- [Release notes](https://github.com/rails/rails/releases)
- [Changelog](https://github.com/rails/rails/blob/v8.0.2.1/activestorage/CHANGELOG.md)
- [Commits](https://github.com/rails/rails/compare/v7.1.5.1...v7.1.5.2)

---
updated-dependencies:
- dependency-name: activestorage
  dependency-version: 7.1.5.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-15 10:21:10 +00:00
Javi Martín
7a76b30909 Merge pull request #6062 from consuldemocracy/allow_rails_security_updates
Relax Rails dependency to allow security updates
2025-08-15 12:19:06 +02:00
Javi Martín
24dcff3c1d Relax Rails dependency to allow security updates
Currently dependabot is failing to upgrade some gems that are part of
Rails. For example, when there's a security issue in ActiveRecord or
ActiveStorage, we get messages like:

```
Dependabot cannot update activestorage to a non-vulnerable version.

The latest possible version that can be installed is 7.1.5.1 because of
the following conflicting dependencies:

rails (7.1.5.1) requires activestorage (= 7.1.5.1) via actionmailbox (7.1.5.1)
rails (7.1.5.1) requires activestorage (= 7.1.5.1) via actiontext (7.1.5.1)
rails (7.1.5.1) requires activestorage (= 7.1.5.1)

The earliest fixed version is 7.1.5.2.
```

So we're relaxing the dependency in order to make it easier for
dependabot to upgrade gems that are part of Rails.

Note that, with this configuration, Dependabot wouldn't be able to
upgrade to Rails 7.1.6 if this releases fixed a security issues in a gem
that is part of Rails. We might still need to upgrade Rails manually in
this case.
2025-08-15 12:01:27 +02:00
Javi Martín
1108c61f01 Merge pull request #5540 from consuldemocracy/poll_form
Use checkboxes and radio buttons on poll forms
2025-08-14 14:13:26 +02:00
Javi Martín
4b7700b6f5 Add a border for each question in the poll form
This way polls look more similar to the way they did when the answers
were buttons instead of checkboxes or radio buttons.

Note the styling is tricky because we need to add a `float` property to
the legend so it's actually inside the fieldset. This forces us to add a
`::before` pseudo-element in order to add margin between the legend and
the first label. Another option would be:

```
legend {
  &:has(+ label) {
    margin-bottom: calc($line-height / 2);
  }

  + label {
    clear: $global-left;
  }
}
```

But the `:has` pseudo-class isn't universally supported yet, and we'd
still have to add `margin-top` to the first label when it comes after a
`.help-text` element.

Due to the presence of the border, we're increasing the margin between
elements a little bit.

Note that adding a pseudoelement to the label is a consequence of adding
the `float` property to the legend, so we're changing the order of the
code so the styles for `legend` appear before the styles in `label`.
2025-08-14 13:59:07 +02:00
Javi Martín
8deb1964bd Show errors when submitting too many answers
This could be the case when JavaScript is disabled.

Note that, in `Poll/WebVote` we're calling `given_answers` inside a
transaction. Putting this code before the transaction resulted in a test
failing sometimes, probably because of a bug that might be possible to
reproduce by doing simultaneous requests.
2025-08-14 13:06:43 +02:00
werdenktwas-gmbh
abf02808bf Disable other answers when reaching maximum votes
This is similar to the way we were disabling buttons in the old design.

Co-authored-by: Javi Martín <javim@elretirao.net>
2025-08-14 13:06:43 +02:00
Javi Martín
7ea4f63b07 Allow blank votes in polls via web
With the old interface, there wasn't a clear way to send a blank ballot.
But now that we've got a form, there's an easy way: clicking on "Vote"
while leaving the form blank.
2025-08-14 13:06:43 +02:00
Javi Martín
cd134ed44f Remove unused HTML class in polls callout
This class was added in commit 3d22c556e but was never used.
2025-08-14 13:06:43 +02:00