Commit Graph

17301 Commits

Author SHA1 Message Date
Javi Martín
cfef15a313 Merge pull request #4609 from consul/dependabot/bundler/master/sprockets-4.0.2
Bump sprockets from 3.7.2 to 4.0.2
2022-01-12 13:43:06 +01:00
dependabot[bot]
91cd1ce1bc Bump sprockets from 3.7.2 to 4.0.2
Bumps [sprockets](https://github.com/rails/sprockets) from 3.7.2 to 4.0.2.
- [Release notes](https://github.com/rails/sprockets/releases)
- [Changelog](https://github.com/rails/sprockets/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rails/sprockets/compare/v3.7.2...v4.0.2)

---
updated-dependencies:
- dependency-name: sprockets
  dependency-type: direct:production
  update-type: version-update:semver-major
...

(Comment by Javi Martín): After this upgrade, compiling the assets is
significantly slower. Also note we need to explicitely include CKEditor
assets and the default application assets and images; we didn't have to
do so in the past.

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-10 15:01:23 +01:00
Javi Martín
2842f67667 Bump sassc from 2.1.0 to 2.4.0
It contains a fix which makes function helpers thread-safe. Without this
fix, our CI fails to compile assets with sprockets 4.x, so we need this
change in order to update sprockets.
2022-01-10 15:01:23 +01:00
Javi Martín
23a9ee6686 Merge pull request #4755 from consul/custom_tests
Make it easier to maintain the test suite in forks
2022-01-03 19:20:08 +01:00
Javi Martín
fed82b0024 Add a way to mark tests as consul/consul exclusive
Until now, when institutions made custom changes which made certain
tests obsolete, they didn't have a clear way to deal with the failing
tests. They would either:

1. Stop running the test suite
2. Run the test suite and get test failures 100% of the time
3. Comment the failing tests
4. Modify the failing tests in order to keep them in sync with the code

Solution 1 would be suicide from a maintenance perspective, although it
could work if only a couple of small custom changes were done.

Solution 2 would make it really hard to differenciate between "false
failures" and "real failures" when running the test suite.

Solution 3 would cause many conflicts when updating to a newer version
of Consul.

Solution 4 could make sense sometimes (big tests where only one line
needs to be changed), but it would also cause conflicts when updating
Consul.

So now, we're giving an alternative to solution 3 by making it easier to
exclude a test.

For tests that still need to be changed, when to use this solution
combined with a custom test and when to use solution 4 will have to be
decided on a per-case basis.
2022-01-03 13:33:37 +01:00
Javi Martín
a80c964121 Add folders for custom tests
We were offering ways to easily add custom Ruby code, but didn't offer
ways to easily add tests for this custom code.
2022-01-03 13:33:37 +01:00
Javi Martín
fecfbfdf88 Merge pull request #4762 from consul/fix_edit_investment_permission
Remove redundant permissions to edit/create records
2021-12-30 18:48:08 +01:00
Javi Martín
c34fc7f0b8 Remove unneeded lines restricting permissions
In the past, users had permission to edit their own legislation
proposals. However, that changed in commit ebfa3fb01, where we replaced
the `can` method with `cannot`.

An easier way to remove this permission is to simply remove the whole
statement, since by default users don't have permissions to do anything.

We're also adding a test checking users can't edit their own legislation
proposals, since it was missing.
2021-12-30 18:25:45 +01:00
Javi Martín
5980df0b31 Remove redundant permissions to edit/create records
The `edit` action is automatically authorized with the rules used for
`:update`, the same way the `new` action is authorized with the rules
used for `:create`.

So we don't need to authorize the edit and new actions.

These changes make it easier for institutions customizing Consul to
notice what they need to change if (for instance) they want users to be
able to edit investments under certain conditions.
2021-12-30 17:26:57 +01:00
Javi Martín
336c055484 Merge pull request #4753 from consul/invalid_html
Fix invalid HTML in application layout
2021-12-30 17:26:41 +01:00
Javi Martín
791b2e12f7 Fix invalid HTML introduced by Foundation
See foundation/foundation-sites issue 12167, which was fixed in
Foundation 6.7.1. However, since Foundation 6.7 requires Node 12 and the
foundation-rails gem hasn't been maintained for a year and a half, we're
not updating for now.
2021-12-30 17:05:07 +01:00
Javi Martín
231a7aa8ee Remove unused code to track events
We forgot to remove it in commit f28a5cc49.

The generated HTML was invalid, with the error:

> Element meta is missing one or more of the following attributes:
> content, property.
2021-12-30 17:05:07 +01:00
Javi Martín
ec352f8e09 Merge pull request #4214 from carlosiniesta/3552-soft-block-users
Allow hiding users without hiding their content
2021-12-30 17:04:43 +01:00
Javi Martín
efb7ad9e42 Differentiate between blocked and hidden users
It was a bit confusing to press the "hide" button and then see the user
listed as "blocked". Some moderators might think they accidentally
pressed the wrong button.
2021-12-30 16:18:26 +01:00
Javi Martín
e9d9789c25 Move users moderation index view to a component
This way it's easier to change the logic and write tests for it.
2021-12-30 15:50:03 +01:00
Javi Martín
a31e73bf23 Ask for confirmation when hiding/blocking users
In the moderation section there's no clear indicator as to what the
"Hide" and "Block" buttons do and the difference between them.

Since we're using confirmation dialogs in all moderation actions except
these ones, we're adding them here as well, so the difference will
appear in the dialog.

This isn't a very good solution, though, since the confirmation dialog
comes after clicking the button and users have already been wondering
whether clicking that button will be the right choice. A better solution
would be making the purpose clear before the button is clicked, although
that's something we don't do anywhere in the admin/moderation sections.
2021-12-30 15:50:03 +01:00
Javi Martín
992da1fef3 Make sure hidden users are shown in order
The test "Action links remember the pagination setting and the filter"
was failing sometimes because it assumed the third user created was
going to appear in the third place, but that wasn't always the case.

So we're using the same order we use in the rest of the sections dealing
with hidden content.
2021-12-30 15:50:03 +01:00
Javi Martín
7caee9a93c Show comments with hidden authors
In the past, whenever we hid users, we also hid their comments.
However, we've now implemented an action to hide users without hiding
their comments. In this case, we still want to show the comment, but we
weren't doing so.
2021-12-30 15:50:03 +01:00
Javi Martín
3b2b09be2b Use CSS to show separators in moderation actions
This is useful for people using screen readers, since the character used
as a separator won't be read aloud.

Since many screen readers also read content generated via CSS
pseudoelements, we aren't using `content: "|";` or similar but using
elements with a very small width instead.
2021-12-30 15:50:03 +01:00
Javi Martín
a5c66c7281 Use buttons instead of links to hide content
We're continuing to replace links with buttons, for the reasons
explained in commit 5311daadf.

Since we're using the admin action component, we can also simplify the
logic handling the confirmation message.

In order to avoid duplicate IDs when generating buttons to block the
same author more than once in a page, we're including the record dom_id
in the ID of the button to block an author.
2021-12-30 15:50:03 +01:00
Javi Martín
f1389b2409 Remove invalid HTML in proposal notifications
This HTML wasn't valid because it was a <span> containing the <div
class="reply"> element and it wasn't needed because there aren't any
flag actions in proposal notifications.
2021-12-30 15:50:03 +01:00
Javi Martín
76555495f6 Hide legislation proposals when blocking a user
We're also updating the notice messages to specify all contents have
been hidden (not just debates).
2021-12-30 15:50:03 +01:00
Javi Martín
021fef07b6 Make action names to block and hide more clear
The `hide` action was calling the `block` method while the `soft_block`
action was calling the `hide` method.

Combined with the fact that we also have a `block` permission which is
used in `ModerateActions` the logic was hard to follow.
2021-12-30 15:50:03 +01:00
Javi Martín
cac24b0159 Extract component to show moderation actions
Note that in proposal notifications we're writing the call to
render the component in the same line as the <div class="reply">
definition in order to be able to use the `:empty` selector when the
component renders nothing. No browser matches whitespace with the
`:empty` selector, so we can't add newline characters inside the tag. A
more elegant solution would be extracting the proposal notification
actions to a component and only rendering it if the moderation actions
component is rendered.
2021-12-30 15:50:03 +01:00
Carlos Iniesta
49edd6a9b1 Add soft block button in moderation user view 2021-12-30 15:50:03 +01:00
Javi Martín
4c8dfb6695 Use just one action to hide users
Other than removing a redundant action, we're fixing two bugs when
blocking an author using the links in the public views:

* We were always redirecting to the debates index, even if we blocked
  the author of a proposal or an investment
* We weren't showing any kind of success message
2021-12-30 15:50:02 +01:00
Javi Martín
84c6eeae9c Use headers and actions in users moderation table
Having proper headers makes it more accessible.

We're also using the table actions component because we're going to add
another action. Since table actions use a flex layout, we have to tweak
the styles a little bit. For that, I'm adding a <main> element which
will make it possible to style just this table while also providing an
extra shortcut for people using screen readers.
2021-12-30 15:50:02 +01:00
Javi Martín
600a2bd4c2 Use a button instead of a link to block users
We're continuing to replace links with buttons, for the reasons
explained in commit 5311daadf.

We're also adding an ARIA label since on the same page there might be
several links to block different users.
2021-12-30 15:50:02 +01:00
Javi Martín
9a8a8ce5ce Fix missing </td> closing tag for blocked users
It was working because browsers automatically assume one <td> element
ends when finding a </tr> tag without a </td>.
2021-12-30 15:50:02 +01:00
Javi Martín
84149d5eb4 Merge pull request #4757 from consul/remove_url_methods_in_models
Remove URL methods in models
2021-12-30 15:08:09 +01:00
Javi Martín
48cfe6ec0b Simplify absolute URLs in relationable tests
We can use `polymorphic_url` instead of manually setting the domain
every time.

This is a bit of a hack in order to comply with the validation rule
which says related content must start with the URL defined in
`Setting["url"]`.
2021-12-30 14:45:48 +01:00
Javi Martín
fa3781059c Remove URL methods in models
We can use `polymorphic_path` since commit ff93f5a591.
2021-12-30 14:45:48 +01:00
Javi Martín
697c1a4857 Merge pull request #4543 from rhian-cs/4015-detail-confirmation-alerts
Make confirm alerts show the triggering action
2021-12-22 13:18:32 +01:00
rhian-cs
609e58cacb Update system specs with detailed confirmation alerts 2021-12-22 12:32:47 +01:00
rhian-cs
b27a05cbfd Make confirmation alert message inform the triggering action 2021-12-22 12:32:45 +01:00
Javi Martín
e45ae0d7a1 Merge pull request #2859 from consul/backport_1579-user_segments_for_geozones
Add geozones as user segments
2021-12-20 17:37:18 +01:00
Javi Martín
cd58b96fad Support geozone segments with non-Latin characters
The `parameterize` method uses the `I18n.transliterate` method, whose
documentation says:

```
I18n.transliterate("Ærøskøbing")
=> "AEroskobing"

I18n.transliterate("日本語")
=> "???"
```

That means we can't use it for dictionaries where characters don't have
a transliteration to the latin alphabet.

So we're changing the code in order to only transliterate characters
with a transliteration to the latin alphabet.

Note the first example ("Česká republika") already worked with the
previous code; the test has been added to make sure accented characters
are handled properly.
2021-12-20 17:18:53 +01:00
Javi Martín
18910d0904 Reduce number of requests in user segments tests
We were testing the creation of newsletters and admin notifications for
each existing segment, which IMHO is a bit overkill, considering how
slow system tests are.

So far we don't have any reasons to believe creating newsletters and
admin notifications will only work for some user segments, so we're
testing a random one instead.

Running these tests on my machine is now about 15 seconds faster.
2021-12-20 15:30:46 +01:00
rgarcia
25a8950330 Add geozones as user segments 2021-12-20 15:30:42 +01:00
Javi Martín
7a028411ab Extract methods to get recipients and valid segments
This way we don't have to use the `send` method in other places, like
the AdminNotification class, and we can change the internal
implementation at any point.
2021-12-20 15:07:46 +01:00
Javi Martín
78e543f6d3 Extract method to get a user segment name
We're going to add geozones as user segments, so it's handy to have the
method in the UserSegments class.

We're also changing the `user_segment_emails` parameter name for
consistency and simplicity.
2021-12-20 15:07:43 +01:00
Javi Martín
a0416d4d85 Fix method description in user segments tests
We generally use "#" to describe instance methods and "." to describe
class methods.
2021-12-20 15:07:25 +01:00
rgarcia
68a2281203 Refactor segment constant into a class method
We're going to make it dynamic using the geozones. Besides, class
methods can be overwritten using custom models, while constants can't be
overwritten without getting a warning [1].

Makes the definition of segments with geozones a little cleaner. I
think it’s worth it, compared to the slight memory gain of using a
constant [2].

[1] warning: already initialized constant UserSegments::SEGMENTS

[2] https://stackoverflow.com/questions/15903835/class-method-vs-constant-in-ruby-rails#answer-15903970
2021-12-20 15:07:25 +01:00
Javi Martín
58aa861ef9 Merge pull request #4754 from consul/remove_madrid_code
Remove legacy code from Madrid's fork
2021-12-20 15:05:28 +01:00
Javi Martín
c45a0bd8ac Remove unused welcome#verification action
The route was deleted in commit 1cd47da9d and this feature was probably
only used in Madrid.
2021-12-20 14:42:53 +01:00
Javi Martín
05474b377c Remove Madrid City Council docs
They were added when CONSUL was only used in Madrid, but that hasn't
been the case for more than five years.
2021-12-20 14:42:53 +01:00
Javi Martín
d7fdb83d7f Merge pull request #2125 from LauraConcepcion/feature/generalize_postal_code_verification
Redefine postal code verification methods to use setting config parameter
2021-12-17 17:26:57 +01:00
Javi Martín
d6b85a038c Allow regular expressions in postal codes
Programmers can take advantage of this feature when defining custom
default settings. And, since many CONSUL installations had custom
changes in the `custom/verification/residence.rb` model and those
changes might use regular expressions, we're making it easier to migrate
that code to the new system to define valid postal codes.

We aren't documenting this feature in the description in the admin
section because most administrators don't know what regular expressions
are.

Note that, in order to simplify the setting, we already define the `/\A`
and `\Z/` characters. So, if the custom code had something like
`postal_code =~ /^280/`, the setting would have to be "280*" (without
the quotes) or, in order to comply with a length validation,
"280[0-9]{2}" (without the quotes).
2021-12-16 23:58:40 +01:00
Javi Martín
a79bbac894 Fix invalid postal code message
We were using the word "registered" in English as an equivalent of the
Spanish word "empadronado". However, the term "registered" is very
confusing because it might be understood as being registered in the
CONSUL website.

In the message, we're saying "cannot participate" in order to make the
message consistent with the message regarding the required age.
2021-12-16 23:58:36 +01:00
Javi Martín
c2e95f6b86 Allow any postal code by default
Due to the way Madrid handled postal code validations (see issue 533),
by default we were requiring everyone to validate against the local
census *and* to specify valid postal codes.

This could be useful in some cases, but in other cases, the census
validation will be enough and there'll be no need to manually define the
valid postal codes. Besides, some CONSUL installations are used in
organizations or political parties where the postal code validation
doesn't make sense.
2021-12-16 13:57:00 +01:00