Commit Graph

20028 Commits

Author SHA1 Message Date
Javi Martín
9fbd7eec8f Remove obsolete routes for poll questions
The routes for poll questions were accidentally deleted in commit
5bb831e959 when deleting the `:show` action, and restored in commit
9871503c5e. However, the deleted code was:

```
resources :questions, only: [:show], controller: 'polls/questions' (...)
```

While the restored code was:

```
resources :questions, controller: 'polls/questions' (...)
```

Meaning we forgot to add the `only: []` option when restoring the
routes.

We also forgot to remove the `before_action` code when deleting the
`:show` action, so we're removing it now.
2024-06-26 20:20:24 +02:00
Javi Martín
e9377c1536 Merge pull request #5532 from consuldemocracy/poll_duplicate_voters
Avoid creating duplicate voters in polls
2024-06-26 20:19:53 +02:00
Javi Martín
b327275d18 Add a log file to track deleted duplicate records
It might be interesting in some cases to check the information related
to those records.
2024-06-26 15:41:44 +02:00
Javi Martín
b013a5b1b6 Add task to delete duplicate voters
Note that, since poll answers belong to a user and not to a voter, we
aren't doing anything regarding poll answers. This is a separate topic
that might be dealt with in a separate pull request.

Also note that, since there are no records belonging to poll voters, and
poll voters don't use `acts_as_paranoia` and don't have any callbacks on
destroy, it doesn't really matter whether we call `destroy!` or
`delete`. We're using `delete` so there are no unintended side-effects
that might affect voters with the same `user_id` and `poll_id` on
Consul Democracy installations customizing this behavior.
2024-06-26 15:41:44 +02:00
Javi Martín
9a8bfac5bd Prevent creation of duplicate poll voters
Note that, when taking votes from an erased user, since poll answers
don't belong to poll voters, we were not migrating them in the
`take_votes_from` method (and we aren't migrating them now either).
2024-06-26 15:41:44 +02:00
Javi Martín
175e990bb4 Remove unused answer_id field in poll_voters table
This field isn't used since commit 51be80eed, right after being
added in commit 5806d86e3.
2024-06-26 15:41:44 +02:00
Javi Martín
5f12db899f Remove no longer needed call to Poll::Answer#touch
This call was added in commit 81f65f1ac, and the test for its need was
added in commit cb1542874. However, both the test and the helper method
relying on the `touch` call were removed in commit f90d0d9c4.
2024-06-26 15:41:44 +02:00
Javi Martín
fb9156f9b8 Use with_lock instead of lock!
That way the record is only locked while necessary.
2024-06-26 15:41:44 +02:00
Javi Martín
a54d424aed Add missing validation rule to poll answers
We were checking we didn't have more votes than allowed in the case of
questions with multiple answers, but we weren't checking it in the case
of questions with a single answer. This made it possible to create more
than one answer to the same question. This could happen because the
method `find_or_initialize_user_answer` might initialize two answers in
different threads, due to a race condition.
2024-06-26 15:41:44 +02:00
Javi Martín
6aafc107ae Remove Questionable concern
Since we were only using it in one place, it made the code harder to
follow.

We'll extract it again if we ever find a way to reuse it.
2024-06-26 15:41:44 +02:00
Javi Martín
0c650c423d Fix exception creating an answer without an author
We were getting `undefined method `lock!' for nil:NilClass` when the
question allowed multiple answers.
2024-06-26 15:41:44 +02:00
Javi Martín
bcaf05f78f Merge pull request #5585 from consuldemocracy/authorize_resource_in_locales_controller
Adjust permissions in admin locales
2024-06-26 15:41:26 +02:00
Javi Martín
12e49ff607 Hide languages link when there's only one language
Most existing Consul Democracy installations will have changed their
`config.i18n.available_locales` option so only a few locales are
available. In many cases, only one locale will be available. In these
cases, rendering a form that only offers one option is useless.

We've considered adding a text in this case mentioning that, in order to
enable more languages, they need to configure their
`config.i18n.available_locales`. However, we haven't done it for two
reasons.

First, if they've changed the available locales to just one, there's a
good chance they aren't interested at all in configuring the locales.

And, second, if there's only one available locale, administrators will
learn to ignore the "languages" link, so they won't realize that locales
can be configured if developers change the available locales. If we hide
the link, on the other hand, they will notice that locales can now be
configured once developers change the available locales.

Note we're still allowing access by entering the URL. This is harmless,
though, since people accessing it this way will see a form with only one
possible option and won't be able to modify anything.
2024-06-25 18:58:57 +02:00
Javi Martín
8c8c99eb2c Correctly check permissions in locales controller
We were using `authorize_resource`, passing it an unnamed parameter.
When that happens, CanCanCan only checks permissions to read that
resource. But, in this case, we want to check the permission to update
that resource before the `update` action.

Most of the time, it doesn't really matter, but, for example, in our
demo we're going to restrict the locales configuration so locales cannot
be updated on the main tenant (but they can be updated on other
tenants).
2024-06-25 18:23:50 +02:00
Javi Martín
5b9fab0387 Merge pull request #5582 from consuldemocracy/run_mdl_in_github_actions
Run MDL in GitHub actions
2024-06-25 16:00:24 +02:00
Javi Martín
df37ce69ab Check markdown rules in github actions
This way we'll notice syntax inconsistencies in pull requests. We
weren't doing it until now because there's no Pronto runner for MDL and
we weren't running linters individually.

Note we aren't checking the templates in the `.github` folders, since
these templates don't have a top level header in the beginning (they'll
be displayed on a page which already has a top level header) and MDL
doesn't provide a way to ignore certain rules on certain files. So we're
specifying which files to include instead of running `mdl .` (which
would also include the `node_modules` folder) or running `mdl -g .`
(which would exclude the `node_modules` folder but would include the
`.github` folder).
2024-06-21 16:46:51 +02:00
Javi Martín
5920ba7a70 Remove rule MD033 Inline HTML
We aren't following this rule in the `docs/es/features/graphql.md` file
because we need to specify the HTML ID attribute of an element (since by
default markdown generates IDs based on the text, and the text contains
accented letters).

Ideally we would simply ignore this rule on this file, but it isn't
currently possible with Markdownlint, so, until we find a better
solution, we're removing this rule.

We've considered keeping the rule and using heading IDs like:

```
 ## Características {#caracteristicas}
```

However, this syntax isn't supported by every application rendering
markdown. For instance, github doesn't support it, and we're aiming to
have a documentation that can be read on either github or gitbook.
2024-06-21 15:57:52 +02:00
Javi Martín
819485eb80 Re-add and apply MDL rule MD040
We were following it about half of the time and we even added it to our
former `.mdlrc` file. However, for some reason, MDL doesn't detect this
rule when specified in the `.mdlrc` file, so we didn't notice we weren't
following it in many cases.

Now that we're using a style file to configure MDL, we can enable this
rule again and apply it, since now MDL correctly includes it in its
report.
2024-06-21 15:57:52 +02:00
Javi Martín
cf23de2f8b Allow headings ending in question marks in markdown
Not sure whether it's a good idea to end a heading with a question mark.
When in doubt, we usually keep the code as it is now, so that's what
we're doing.
2024-06-21 15:57:52 +02:00
Javi Martín
3a173fdb0b Use two spaces to indent lists in markdown
We were already doing it in the `docs/` folder, and this is consistent
with the indentations we use in prettly much every programming language.
2024-06-21 15:57:52 +02:00
Javi Martín
da1bac3638 Add a Markdownlint style file
This way we'll be able to customize some of the rules, which doesn't
seem to be possible when using the `.mdlrc` file.

For simplification purposes, instead of including all rules one by one,
we're excluding the few rules we don't use.
2024-06-21 15:57:52 +02:00
Javi Martín
035bfeb3b1 Add and apply MD047 MDL rule
We weren't adding a newline character at the end of a couple of files.
2024-06-21 15:57:52 +02:00
Javi Martín
ad66334446 Remove MDL rules that weren't being applied
I've no idea why, but these rules were ignored by the `mdl` command, so
we weren't following them. We might add them again in the future.
2024-06-21 15:57:52 +02:00
Javi Martín
504fa1b5e7 Remove non-existing rules in MDL configuration file
These rules (MD008, MD015, MD016 and MD017) were removed almost 10 years
ago, before we started this project [1].

[1] https://github.com/markdownlint/markdownlint/commit/71333042
2024-06-21 15:57:52 +02:00
Javi Martín
b0a29ca528 Apply rule MD034 Bare URL in github templates 2024-06-21 15:57:52 +02:00
Javi Martín
f59b0475b2 Adjust heading levels in github templates
Since the page contains an <h1> tag (the title of the issue), the main
headings of this file should be level 2 headings.

We're removing the "How" section in the flaky specs template for
simplicity (and because we usually don't use this template at all).

Note that MDL reports that the first heading should be a level 1
heading, but, as mentioned earlier, this doesn't make sense in the
context of a github issue. We'll probably exclude these files from MDL
checks in order to avoid this issue.
2024-06-21 15:57:52 +02:00
Javi Martín
b2d9d37070 Apply MDL spacing rules in github templates 2024-06-21 15:57:52 +02:00
Javi Martín
55e060424c Merge pull request #5544 from consuldemocracy/import_docs
Import code and commit history from the docs repository
2024-06-21 15:56:05 +02:00
Javi Martín
a5f134a10c Merge pull request #5584 from consuldemocracy/between_ages_spec
Fix typo in between_ages spec
2024-06-20 15:05:55 +02:00
Javi Martín
3f3d1dec17 Fix typo in between_ages spec
The test was failing sometimes because there's no guarantee that the
`.between_ages` scope will return the records in a specific order.
2024-06-19 18:42:14 +02:00
Javi Martín
777781f361 Update documentation README files
These files are essentially the same as our README files, only our
README files contain information that only makes sense in the context
of a repository.
2024-06-18 23:39:42 +02:00
Javi Martín
0b9be27c8c Use one SUMMARY.md file per language
On GitBook, currently Spanish and English belong in different spaces, so
we're going to provide two different github integrations (one per
language).

So we're using a different SUMMARY.md file per language.

For consistency, since there was a link to the README file in the
Spanish summary, we're also adding it to the English one. It was working
in any case because on our current gitbook page the summary was
generated through gitbook.

Since we no longer have any of the files referenced in the
`.gitbook.yaml` file, we're removing it as well.

Note that there was a typo in the English summary, which pointed to the
Spanish license. It didn't matter, though, since the license file is
actually in English in both cases.
2024-06-18 23:38:46 +02:00
Javi Martín
0710e3d542 Remove redundant files in docs subfolder
These files were both in the Consul Democracy repository and the
documentation repository. Since now both repositories have been merged
into one, we can remove the duplicate files.

Note there was a small difference in the `.mdlrc` file because we
changed it in commit b3a718ae6. We're keeping this change so we don't
get these syntax warnings in the documentation.
2024-06-18 20:33:01 +02:00
Javi Martín
3875503ea5 Update rbenv installation script URL
Their master branch was renamed to main.
2024-06-18 20:33:01 +02:00
Javi Martín
a76d2bba11 Fix broken link on translations page 2024-06-18 20:33:01 +02:00
cronopioelectronico
b536548cec Remove unnecessary texts in the README 2024-06-18 20:33:01 +02:00
cronopioelectronico
a4dbe1b413 Remove reference to old project team email address 2024-06-18 20:33:01 +02:00
Javi Martín
532c3dda1f Merge remote-tracking branch 'docs/master' into import_docs 2024-06-18 20:33:01 +02:00
Javi Martín
cc3268b968 Merge pull request #5578 from consuldemocracy/dependabot/npm_and_yarn/braces-3.0.3
Bump braces from 3.0.2 to 3.0.3
2024-06-18 20:32:07 +02:00
dependabot[bot]
70445ae43e Bump braces from 3.0.2 to 3.0.3
Dependabot couldn't find the original pull request head commit, 5654724f66010c1a52a4518cb2a8442277f368ed.
2024-06-18 18:07:10 +00:00
Javi Martín
d5dfb6ce7c Merge pull request #5583 from consuldemocracy/dependabot_pronto
Fix linters workflow on Dependabot pull requests
2024-06-18 20:06:27 +02:00
Javi Martín
e2a8b3caae Fix linters workflow on Dependabot pull requests
The name of the actor is not dependabot but dependabot[bot] [1].

[1] https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#responding-to-events
2024-06-18 19:54:06 +02:00
Javi Martín
961d7d9efa Merge pull request #5545 from consuldemocracy/linters_in_github_actions
Run every linter separately in Github Actions
2024-06-18 19:33:53 +02:00
Javi Martín
995f7036de Run every linter separately in Github Actions
The main reason for this change is that Pronto doesn't run in pull
requests opened by external contributors, and we haven't found how to
fix this issue.

Another reason is that Pronto only detects issues in the lines where the
changes are done, but sometimes we introduce issues related to other
lines and those aren't detected by Pronto. Also, when adding or changing
Rubocop rules, or when we update Rubocop, Pronto doesn't check whether
those rules are applied in every Ruby and ERB file, and we sometimes
forget to do so (particularly in ERB files).

So, from now, the linters will check all the code in every pull request.

Note we're now excluding the `vendor` folder in our linters because the
`setup-ruby` action actions generates a `vendor/bundle/` folder with all
our gem dependencies, and we don't want to check those files.
2024-06-18 19:11:55 +02:00
Javi Martín
61a6ba26b1 Simplify dependabot condition in pronto workflow
We had the `*` because, in the past, pull request could be opened by
either dependabot or dependabot-bot. That's no longer the case since we
started using dependabot v2.
2024-06-18 19:01:31 +02:00
Javi Martín
e646689535 Rename linters workflow to pronto
We're going to add a linters workflow, so the name would be confusing.
2024-06-18 18:27:32 +02:00
Javi Martín
444b8c3390 Ignore stylelint false positive in datepicker overrides
We can't simply remove the nesting selector in this case since it's
inside a `:not` pseudo-class. Removing the nesting selector would cause
a syntax error.
2024-06-18 18:27:32 +02:00
Javi Martín
6f9de94013 Extract stylesheet for social share button styles
This way we can ignore the selector-class-pattern stylelint rule error
due to the `.ssb-whatsapp_app` selector.
2024-06-18 18:27:32 +02:00
Javi Martín
b2be64848c Ignore legislation_process nesting in stylelint
This file was generated by a different developer who ignored the nesting
rules. Refactoring it has been in our TODO list for years, but we
haven't done it yet.

Since we want stylelint to check that there are no errors after the
changes in a pull request, but we've still got errors in this file,
we're ignoring them for now.
2024-06-18 18:27:32 +02:00
Javi Martín
3d5696aff5 Apply no-redeclare ESLint rule
This rule is part of the `eslint:recommended` package. It was the only
rule we weren't following 100% of the time (other than the line length).
2024-06-18 18:27:32 +02:00