Commit Graph

17138 Commits

Author SHA1 Message Date
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
Javi Martín
35e0477e03 Ignore trailing spaces in postal codes verification
This way both administrators and regular citizens have a certain margin
of error when entering the postal codes.
2021-12-16 13:57:00 +01:00
Javi Martín
5cc10cbadf Allow dashes in postal codes
In some countries, postal codes are defined with a dash in the middle,
so we're using a colon to define ranges instead. We could also use two
dots, like in Ruby ranges, but IMHO this would cause typos since people
would enter codes separated with three dots or just one dot.
2021-12-16 13:57:00 +01:00
Javi Martín
b8b4336266 Compare postal codes with strings and not integers
We can now get rid of the rule forcing a length of 5 digits, which
doesn't apply to all countries.
2021-12-16 13:57:00 +01:00
Javi Martín
edc56b1e1f Avoid using eval in postal code validation
We were getting a warning by Rubocop because we were using eval with a
string defined by administrators, which in theory could be dangerous.
2021-12-16 13:57:00 +01:00
Javi Martín
006269a94b Simplify tests validating postal codes
We weren't using the `be_valid` matcher because we had errors in the
census data.

Removing the `before_validation` callback and using a method to get the
census data instead allows us to stub the `census_data` method in the
tests, and so we can use the `be_valid` matcher instead of calling
`valid?` manually and then checking for errors.
2021-12-16 13:57:00 +01:00
Laura Concepción Rodríguez
f4512b2117 Redefine postal code verification methods to use setting config parameter 2021-12-16 13:57:00 +01:00
Javi Martín
bcce43fd0f Merge pull request #4643 from consul/phone_number_field
Use telephone fields in phone number form controls
2021-12-16 13:48:53 +01:00
Javi Martín
ae91361edb Use telephone fields in phone number form controls
Using a field with `type="tel"` causes most mobile phone browsers to
show a numeric keyboard which makes it easy to enter phone numbers.

We aren't using a number field because some browsers show "spinners" to
increment/decrement numbers (which doesn't make much sense in a phone
number) and because they don't allow characters like spaces. Phone
numbers can have characters like spaces, dashes, parenthesis, asterisks,
the plus sign, ...

Since phone number formats vary depending on the region, and sometimes
even within the same region several different formats can be used, for
now we aren't offering any kind of format validation. We could offer a
format validation that rejects just letters (although there are cases
where letters are actually allowed). However, this causes issues at both
the server side and the client side.

We could use a client-side validation adding a `pattern` attribute to
the field, but that would be something unlike anything else we use in
the application, and we would need to to write some JavaScript in order
to use a proper error message.

On the other hand, if we add a server-side validation, we might find out
existing users are invalid, and it would be impossible to update them in
the many places where we update users assuming they were valid in the
first place. We'd have to add a rake task to update existing user
records and make sure they contain a valid phone number or create a
setting so this validation only applies to new CONSUL installations.
Another option would be to add a per-form validation, so the phone
number is only validated in pages where it is introduced.

All the mentioned scenarios offer certain complexities. So, for now,
we're keeping things simple.

Co-Authored-By: decabeza <alberto@decabeza.es>
2021-12-16 13:24:26 +01:00
Javi Martín
ff0855f0fe Merge pull request #4734 from consul/manager_header
Make management and admin headers consistent
2021-12-15 14:15:29 +01:00
Javi Martín
519a34b1f8 Use the admin header in the management section
Now that we also have the "go back to CONSUL" link, the layouts are so
similar that it isn't worth it maintaining both of them separately.

With this change, people using small screens also get the "menu" button
in the management section, just like they do everywhere else.

We're adding the `namespace != "management"` condition so the menu still
shows up in the officing namespace.
2021-12-15 13:53:56 +01:00
Pierre Mesure
228a1d9090 Add missing link and button on management interface 2021-12-15 12:47:01 +01:00
Javi Martín
031ec8fce1 Merge pull request #4733 from consul/dev_seeds_without_english
Make dev seeds independent on available locales
2021-12-14 20:28:08 +01:00
Javi Martín
d59d9aac3b Check missing/unused translations in seeds.yml
We were making some typos during development in the name of the keys and
tests were still passing.

We're also removing some texts that were never used.
2021-12-14 20:10:35 +01:00