Commit Graph

19438 Commits

Author SHA1 Message Date
Javi Martín
82b73e5ddc Merge pull request #5587 from consuldemocracy/zeitwerk_docs
Update documentation to load custom code
2024-06-28 14:24:18 +02:00
Javi Martín
f78e2bed94 Update documentation to load custom code
Just like mentioned in commit 6552e3197d, we need to use `load` instead
of `require_dependency` since we started using zeitwerk.
2024-06-28 03:49:20 +02:00
Javi Martín
20c55da48b Merge pull request #5539 from consuldemocracy/add_option_id_to_poll_answers
Avoid duplicate records in poll answers
2024-06-27 15:35:24 +02:00
Javi Martín
5dbd2ede14 Delete duplicate records in different languages 2024-06-27 15:22:02 +02:00
Javi Martín
58f88d6805 Add task to add option_id to existing answers
Note: to avoid confusion, "answer" will mean a row in the poll_answers
table and "choice" will mean whatever is in the "answer" column of that
table (I'm applying the same convention in the code of the task).

In order make this task perform reasonably on installations with
millions of votes, we're using `update_all` to update all the answers
with the same choice at once. In order to do that, we first need to
check the existing choices and what are the possible option_ids for
those choices.

Note that, in order for this task to work, we need to remote the
duplicate answers first. Otherwise, we will run into a RecordNotUnique
exception when trying to add the same option_id to two duplicate
answers.

So we're making this task depend on the one that removes duplicate
answers. That means we no longer need to specify the task to remove
duplicate answers in the release tasks; it will automatically be
executed when running the task to add an option_id.
2024-06-27 15:05:56 +02:00
Javi Martín
d2ec73e92c Add task to delete duplicate poll answers 2024-06-26 20:20:24 +02:00
Javi Martín
81abbd5021 Remove unused block variable in poll ABC factory 2024-06-26 20:20:24 +02:00
Javi Martín
5033691666 Avoid duplicate records in poll answers
Until now, we've stored the text of the answer somebody replied to. The
idea was to handle the scenarios where the user voters for an option but
then that option is deleted and restored, or the texts of the options
are accidentally edited and so the option "Yes" is now "Now" and vice
versa.

However, since commit 3a6e99cb8, options can no longer be edited once
the poll starts, so there's no risk of the option changing once somebody
has voted.

This means we can now store the ID of the option that has been voted.
That'll also help us deal with a bug introduced int 673ec075e, since
answers in different locales are not counted as the same answer. Note we
aren't dealing with this bug right now.

We're still keeping (and storing) the answer as well. There are two
reasons for that.

First, we might add an "open answer" type of questions in the future and
use this column for it.

Second, we've still got logic depending on the answer, and we need to be
careful when changing it because there are existing installations where
the answer is present but the option_id is not.

Note that we're using `dependent: nullify`. The reasoning is that, since
we're storing both the option_id and the answer text, we can still use
the answer text when removing the option. In practice, this won't matter
much, though, since we've got a validation rule that makes it impossible
to destroy options once the poll has started.

Also note we're still allowing duplicate records when the option is nil.
We need to do that until we've removed every duplicate record in the
database.
2024-06-26 20:20:24 +02:00
Javi Martín
03f89c9ca2 Move action to create answers to AnswersController
It was confusing to have the action to create an answer in
`QuestionsController#answer` while the action to destroy it was
`AnswersController#destroy`.
2024-06-26 20:20:24 +02:00
Javi Martín
9a840bb8d1 Remove unused code in poll questions controller
This code wasn't used since commit d9ad65875.
2024-06-26 20:20:24 +02:00
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