Commit Graph

15767 Commits

Author SHA1 Message Date
Javi Martín
8c389b3dd9 Apply trailing spaces mdl rule 2020-08-11 12:13:23 +02:00
Javi Martín
864e991047 Apply mdl link definition rule 2020-08-11 12:13:23 +02:00
Javi Martín
5bdf09844e Apply mdl bare URL rule 2020-08-11 12:13:23 +02:00
Javi Martín
e48c748e97 Apply mdl blank lines rules 2020-08-11 12:13:23 +02:00
Javi Martín
cbc8d2fb62 Remove "headers with the same content" mdl rule
This rule would be fine if it only applied to headers within the same
section, but the way we structure our CHANGELOG.md file, each release
has the "Added", "Changed" and "Fixed" headers.
2020-08-11 12:13:23 +02:00
Javi Martín
44f6d43212 Bump mdl from 0.5.0 to 0.10.0
This contains a security fix since we're upgrading kramdown.
2020-08-11 12:13:17 +02:00
Julian Herrero
d720826e59 Add feature flag exception for the module polls 2020-08-11 11:10:10 +07:00
Javier Martín
5d43b632e9 Merge pull request #4067 from consul/links_and_images_on_legislation
Allow links and images on legislation drafts
2020-08-10 13:45:48 +02:00
Julian Herrero
151aa6009d Allow links and images on legislation drafts
Note we're using a new sanitizer. Ideally we'd reuse the
`AdminWYSIWYGSanitizer`, but then code that would be correctly shown by
markdown-it (like the <h1> tag) wouldn't be shown on the web, which is
confusing. Ideally we would configure markdown-it to only allow the tags
present in the `AdminWYSIWYGSanitizer` and provide some kind of help
showing which tags are allowed.
2020-08-10 12:20:59 +02:00
dependabot-preview[bot]
9c54825d3b Bump acts-as-taggable-on from 5.0.0 to 6.5.0
Bumps [acts-as-taggable-on](https://github.com/mbleigh/acts-as-taggable-on) from 5.0.0 to 6.5.0.
- [Release notes](https://github.com/mbleigh/acts-as-taggable-on/releases)
- [Changelog](https://github.com/mbleigh/acts-as-taggable-on/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mbleigh/acts-as-taggable-on/compare/v5.0.0...v6.5.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-08-10 09:53:52 +00:00
Javier Martín
b2a07121e3 Merge pull request #4035 from consul/dependabot/bundler/geocoder-1.6.3
[Security] Bump geocoder from 1.4.5 to 1.6.3
2020-08-08 18:42:18 +02:00
Javier Martín
0d82ac871d Merge pull request #4076 from consul/legislation_keys
Use complete keys on legislation translations
2020-08-07 20:54:57 +02:00
Javier Martín
71cee9a785 Merge pull request #4047 from consul/poll-skip-verification
Allow voting when skip verification is enabled
2020-08-07 20:31:29 +02:00
Javi Martín
096f546c24 Make sure users only vote once in the same poll
When skipping verification, we cannot apply the validation rule saying
the document number and document type must be unique, because they'll be
`nil` in many cases. So we were skipping the rule, but that makes it
possible for the same user to vote several times (for instance, once in
a booth and once via web).

So we're changing the scope of the uniqueness rule: instead of being
unique per document number, voters are unique per user. The reason we
made them unique per document number was that back in commit 900563e3
(when we added the rule), we hadn't added the relation between users and
poll voters yet.
2020-08-07 13:40:25 +02:00
decabeza
4367b2054a Allow voting when skip verification is enabled 2020-08-07 11:52:24 +02:00
Javi Martín
24ccf23ed8 Don't save the answer if the voter is not recorded
Up until now, we were assuming the voter was valid, but were not raising
an exception if it wasn't. And in the user interface everything seemed
to be working properly.

We were having this issue when skipping verification, when there could
be voters without a document number, which would be considered invalid.

Raising an exception when failing to save the voter and making sure the
answer and the voter are saved inside a transaction solves the problem.
2020-08-07 11:52:24 +02:00
decabeza
bcfb9b7a18 Use complete keys on legislation translations 2020-08-07 10:29:39 +02:00
Javier Martín
2fbb224374 Merge pull request #4070 from consul/remove-redundant-calls
Remove redundant calls to load resources
2020-08-06 14:18:39 +02:00
Javier Martín
50372f4370 Merge pull request #4066 from consul/oauth_buttons
Show Wordpress login button if it's the only one enabled
2020-08-06 13:53:57 +02:00
Javier Martín
5fb951eeac Merge pull request #4063 from consul/approval_voting
Add approval voting to budgets
2020-08-06 13:52:19 +02:00
Ziyan Junaideen
1e3e8c1304 Add approval voting to budgets
Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-08-06 12:38:18 +02:00
Javi Martín
6bb9ebf12f Move before-cache event calls to application.js
Turbolinks 5 handles page caching differently; it saves the current HTML
and, when the page is restored using the browser's back button, it
copies it and triggers the `turbolinks:load` event, which, in our case,
triggers our `initialize_modules` function.

This isn't a problem regarding event handlers, since they're removed
when caching the page (except fot the ones attached to the `document`).
However, it is a problem for functions that, once the document is ready,
scan the DOM and add certain elements. In this case, an element might be
added a second time when the page is restored.

So we need to either check an item has already been added before adding
it or remove it before caching the page. Since this is going to be a
common pattern, we're adding a function to handle these non-idempotent
parts of the application, so it mirrors our `initialize_modules`
function.

We're also moving the `destroy` function definition after the
`initialize` function definition, which makes more sense since we
initialize things before destroying them.
2020-08-05 14:10:22 +02:00
Javi Martín
0270c4c962 Hide unsaved changes warning after undoing them
This way showing the warning is consistent with warning users when
they're leaving the page.
2020-08-05 14:10:22 +02:00
Javi Martín
cfc60b5de4 Warn for changes just in markdown editor
This is the reason why this feature was implemented in the first
place: it's easy to open the editor, make some changes, close it, and
continue without realizing the changes have not been saved.

In the rest of the forms, this functionality is quite lacking. For
starters, some forms warn if there are unsaved changes, while some forms
don't, which is highly inconsistent and disorients users.

Furthermore, we were having problems with this feature after upgrading
Turbolinks, particularly in forms using CKEditor. In these cases, a lot
of hacking needs to be done in order to make this feature work properly,
since CKEditor adds some formatting automatically, and if this is done
after the form is serialized, we'll get some unexpected behavior. On the
other hand, comparing the value of a textarea against its `defaultValue`
property will work on every edge case, including using the browser's
back button or reloading the page.

Finally, users are used to the way web forms work, and aren't used to be
asked for confirmation when they change their mind and decide to leave
the page without saving the changes. Asking them for confirmation will
be annoying in most cases. Besides that, if they accidentally leave the
page, they can use the browser's back button and they'll recover the
unsaved changes.

It's true this won't happen it they accidentally close the browser's
window, but our WatchFormChanges functionality didn't work in this case
either. Using the "beforeunload" event adds more problems than it
solves, since it doesn't support custom messages (or, to be more
precise, modern browsers ignore custom messages), and it doesn't get
along with turbolinks.

Co-Authored-By: Senén Rodero Rodríguez <senenrodero@gmail.com>
2020-08-05 14:10:22 +02:00
Javi Martín
f68553dc00 Extract method to fill in markdown editor in specs 2020-08-05 14:10:22 +02:00
Javi Martín
f8c9f09887 Prevent default event on JavaScript-only links
These links point to "#" and don't do anything without JavaScript
activated, and they were causing the browser to scroll to the top of the
page.
2020-08-05 14:10:22 +02:00
Javi Martín
ae2b4b16c6 Prevent AJAX requests to anchor links
Turbolinks 5 doesn't follow the browser's standard behaviour of ignoring
links pointing to "#", so we're preventing the turbolinks events in this
situation:
2020-08-05 14:10:22 +02:00
Javi Martín
7b96180a76 Upgrade Turbolinks to version 5.2.1
We didn't upgrade Turbolinks when we upgraded to Rails 5 so we didn't
upgrade too many things at the same time, and postponed it... until now
:).

Note upgrading Turbolinks fixes an issue with foundation's sticky when
using the browser's back and forward buttons. We're adding tests for
these scenarios.

Co-authored-by: Senén Rodero Rodríguez <senenrodero@gmail.com>
2020-08-05 14:10:22 +02:00
Javier Martín
a8f261ed95 Merge pull request #4073 from rockandror/javascript_fixes
Javascript fixes
2020-08-05 14:07:16 +02:00
Javi Martín
017eeda3d4 Remove redundant call to $(document).ready()
The `$()` function is a shortcut for `$(document).ready()`, and we were
attaching events to `$(document).ready()` inside the `$()` function.

In a similar way, we were handling the `page:load` and `ajax:complete`
events inside the `$()` function. But when those events trigger, the DOM
is already ready.

Besides, we don't have to wait for the DOM to be ready before attaching
events to the `document` element. Quoting jQuery's `.on()`
documentation:

> The document element is available in the head of the document before
> loading any other HTML, so it is safe to attach events there without
> waiting for the document to be ready.

Co-Authored-By: Senén Rodero Rodríguez <senenrodero@gmail.com>
2020-08-05 11:34:57 +02:00
Javi Martín
983bf49b38 Simplify code related to Foundation's sticky
In the past we had huge problems trying to make it work with Turbolinks.
However, after updating foundation-rails in commit 58071fd6, these hacks
aren't necessary anymore.

We're adding a test for the scenario of visiting a page using
Turbolinks, which was missing, so we're sure we aren't breaking
anything.

Note the sticky will still not work after using the browser back button.
We haven't been able to make it work with turbolinks-classic; we'll fix
this issue when upgrading turbolinks.
2020-08-05 11:34:57 +02:00
Senén Rodero Rodríguez
fde6fb4d97 Initialize only visible maps when page is loaded
Its known that initializing a map when it is inside a hidden element
wont work when hidden element is shown, so its makes sense to
avoid initialization of hidden maps.

When a map lives within a hidden layer we need to initialize the
map after the event of showing that hidden layer, in our case when
admin settings tab is shown.
2020-08-05 11:34:57 +02:00
Senén Rodero Rodríguez
99f8bb4491 Fix collission with sortable.js script
TableSortable and Sortable javascripts were using the same CSS
class name to define completely different and separated
behaviours causing unexpected errors. Now `sortable.js` script
will use `.sortable` class and `table_sortable.js` will use
`.table-sortable` instead.
2020-08-05 10:28:13 +02:00
Senén Rodero Rodríguez
cda545f2fc Remove uneeded lines
There is no elements with class `js-participation-allowed` within all
application code.
2020-08-04 20:32:14 +02:00
Senén Rodero Rodríguez
149ce945c0 Simplify initialization code for tags links
By using an event delegation handler on document body there is no need
to check if element was already initialized (idempotency) anymore.
2020-08-04 20:32:14 +02:00
Senén Rodero Rodríguez
45a80af793 Do not remove click event definition before defining it
Use delegated handlers instead so there is not risk to run method
multiple times.
2020-08-04 20:31:52 +02:00
Javier Martín
009c33d4e5 Merge pull request #4062 from consul/voting_styles
Refactor ballot / ballot line voting logic
2020-07-30 22:01:43 +02:00
Javi Martín
82ef5149c5 Remove redundant progress bar
We were displaying two progress bars for the same thing, and hiding one
of them.

Displaying just one of them and readjusting the styles accordingly is a
bit more intuitive IMHO.

We're also getting the text inside the progress bar out of it; its
purpose inside an element with the `progressbar` role is to provide the
same information as the progress bar (which we aren't exactly doing,
although it could be argued that we do), and in order to be accessible
we should provide the same text in the `aria-valuetext` field, which we
aren't doing. This also simplifies our CSS, which was working because we
defined a padding which covered the height of the hidden extra progress
bar and would have needed quite a few changes if we kept just one
progress bar with text inside it. We can also remove a few CSS rules
which we added to override foundation's rules for the
`progress-meter-text` class.
2020-07-30 16:20:00 +02:00
Javi Martín
2216cb91d1 Use local variables in progress bar partial
We were even passing the `ballot` local variable in some places, which
was ignored because we were using instace variables.
2020-07-30 16:20:00 +02:00
Javi Martín
8edcbcfd3b Fix aria-valuenow attibute in ballot progress bar
We were setting it to 0, and so screen reader users might be confused by
it.

The easiest way to reuse the code and using it for both this attribute
and the width of the progress bar is to move this method to the voting
style, just like the other methods used in this view.

Note the progressbar ARIA role might not be right, since this isn't a
task which is "progressing", but an indicator of the amount spent and
amount available, which is exactly what the <meter> HTML5 tag was
designed for.

We might use a <meter> tag in the future. For now, I'm leaving it as it
is because I'm not certain about how well <meter> is supported in
accessibility tools, and because it's definitely not supported in
Internet Explorer 11, which we haven't officially dropped support for.
2020-07-30 16:20:00 +02:00
Javi Martín
ceee25fdc9 Don't re-render the ballot twice
We were rendering an individual ballot, and then rendering all ballots
(including the already rendered one). So we can skip the first part, as
pointed out by microweb10 in the comments of pull request 3036.
2020-07-30 16:20:00 +02:00
Javi Martín
160964fcdc Make method to check a line can be added generic
In the Knapsack voting style, we can't add an investment if its cost is
greater than the money we've got left, but in other voting styles money
might not be the issue.

So we're introducing the term "resources" and adapting the code
accordingly.
2020-07-30 16:20:00 +02:00
Javi Martín
5f726df8be Extract methods showing voting style information
The idea is that different voting styles will display different
information messages.
2020-07-30 16:19:58 +02:00
taitus
46d17e8aa7 Remove redundant calls to load resources 2020-07-28 13:19:48 +02:00
Javi Martín
ad6d830c1f Make translations more consistent
We're passing the amount as a paramenter to the "remaining" text, so it
makes sense to pass it to the "amount spent" text as well.

Here we're also changing the I18n key to the text saying users can
change their vote, so it's easier to note the text is about changing
their vote, and not about the projects they have voted so far.
2020-07-28 13:06:31 +02:00
Javi Martín
ad094e5063 Extract class to handle voting style logic
Since we're going to introduce a new voting style which will not be
based on money, we're extracting the logic specific to the current
voting style to a new class.

This way adding new voting styles will be easier.
2020-07-28 13:06:31 +02:00
Javi Martín
c22e800329 Remove code duplication
We were calling the same method three times.
2020-07-28 13:06:31 +02:00
Javi Martín
a38cdb4df3 Remove unnecessary safe navigation operator
The heading is used with `find_by_slug_or_id`, which raises an exception
if it isn't found, so executing `@heading.group` after it does not need
the safe navigation operator.
2020-07-28 13:06:31 +02:00
Javi Martín
a9900e3f27 Remove duplication calculating insufficient funds
We were using the same logic twice.

I've moved the logic to the Ballot model, which to me is a more natural
place to calculate whether there's enough money left than the Investment
model. After all, the remaining money is in the ballot, and not in the
investment.
2020-07-28 13:06:31 +02:00
Javi Martín
a32c0f8154 Remove unused parameter
The `refresh_ballots` partial ignores the `investment` parameter
completely; instead, it iterates over the investments in the
`@investments` instance variable.
2020-07-28 13:06:31 +02:00