Commit Graph

17301 Commits

Author SHA1 Message Date
Javi Martín
bf10cf0c18 Simplify calls to content_block helper
All calls were using `I18n.locale` as the second parameter, so we might
as well make it optional.
2021-06-24 13:15:04 +02:00
Javi Martín
dae4aae328 Avoid rendenring an empty list in top links
We've had an accessibility error reported by the Spanish "Portal
Administración electrónica" (PAe). While I can't find any accessibility
rule saying empty lists should be avoided, it looks like some screen
readers report finding lists with 0 items, which is annoying.
2021-06-24 13:15:04 +02:00
Javi Martín
6d999559b3 Move top links partial to a component
This way it's easier to test.
2021-06-24 13:15:04 +02:00
Javi Martín
f26a06de83 Remove unused CSS for blog icon
It isn't used since commit ccee843da.
2021-06-24 13:15:04 +02:00
Javi Martín
da76c848fc Avoid rendering an empty list in footer
We've had an accessibility error reported by the Spanish "Portal
Administración electrónica" (PAe). While I can't find any accessibility
rule saying empty lists should be avoided, it looks like some screen
readers report finding lists with 0 items, which is annoying.

We could also do it with CSS using `ul:empty { display: none}`. However,
at the time of writing no browser supports this rule when the tag
contains whitespace.
2021-06-24 13:15:03 +02:00
Javi Martín
339c3c7eca Remove unnecessary margins in social links
On small screens the list is on its own line so it doesn't need a
margin, while on medium/large screens the padding of its parent element
makes the margin unnecessary as well.
2021-06-24 12:43:44 +02:00
Javi Martín
211ed101b9 Simplify code in social component 2021-06-24 12:43:44 +02:00
Javi Martín
3b00f3c141 Remove duplication in social icons in footer 2021-06-24 12:43:44 +02:00
Javi Martín
0aba34ad4d Extract social links to a component 2021-06-24 12:43:43 +02:00
Javi Martín
7bc9aea2d1 Merge pull request #4564 from consul/related_content_custom_url
Fix related content with custom URLs
2021-06-24 12:37:20 +02:00
Javi Martín
71b6eda160 Merge pull request #4563 from consul/related_content_accessibility
Improve accessibility in form to add related content
2021-06-24 12:36:30 +02:00
Javi Martín
89a06ea6ef Fix related content with custom URLs
Some CONSUL installations might want to customize their URLs. For
instance, Spanish institutions might want to use "/propuestas" instead
of "/proposals". In that case, it would be impossible to add proposals
as related content because the related contents controller assumed the
name of the model was part of the URL.

Using `recognize_path` instead of manually analyzing the URL solves the
issue.

Now that we don't call the `constantize` method on an empty string as we
previously did, we can be more specific in the `rescue` block and point
out that the only exception we expect is the one where users enter a
route which isn't recognized.
2021-06-23 23:28:35 +02:00
Javi Martín
48dc72cea9 Avoid a brakeman warning in related contents
Although it wasn't a real security concern because we were only calling
a `find_by` method based on the user input, it's a good practice to
avoid using constants based on user parameters.

Since we don't use the `find_by` method anymore but we still need to
check the associated record exists, we're changing the validations in
the `RelatedContent` model to do exactly that.
2021-06-23 23:13:58 +02:00
Javi Martín
8f20ee1a33 Move related content validation to the model
We were manually checking validation rules (like both relationable
objects are present, or they're both the same object) in the controller
and then using the `save!` method.

However, we usually use the `save` method (which checks all validations)
in a condition, and proceed depending on the result.

Now we're taking the same approach here. This means introducing a new
validation rule in the model to check whether both relationable objects
are the same, which is more robust than checking a condition in the
controller.
2021-06-23 23:13:58 +02:00
Javi Martín
b318a8b8d2 Use polymorphic_path instead of Relationable#url
The #url method in the models provides a feature that can be done using
native Rails features (polymorphic paths), is inconsistent (some models
have that method and some haven't), and only works for URLs in the
public area (but not in sections like administration or management).
Besides, models are already fat enough without introducing methods
related to controllers or routes.
2021-06-23 23:13:58 +02:00
Javi Martín
82c8a5896a Simplify relationable comparison
Two different records will have two different URLs, so we can compare
the records themselves.
2021-06-23 23:13:58 +02:00
Javi Martín
606cf267f6 Use Font Awesome icons on related content actions
We've deprecated the "icons" font since we started using Font Awesome
two years ago.
2021-06-23 23:06:24 +02:00
Javi Martín
14e9b71766 Show score actions after their related content
"Is it related content? Yes (link) No (link)".

After reading that, you probably haven't decided whether to click the
"Yes" link or the "No" link or neither of them. You probably have to
read the content it's related to, and then go back to these links.

That's the reason we style them so they're on the right of the screen on
languages which are read from left to right, so first we read the
content and then we read the links to mark it as related or unrelated.

So it makes sense to put these links after the content they refer to.
This way users with small screens as well as screen reader users will
also see/hear these links after they get the proper context. It will
also be more intuitive for keyboard users, who saw the focus on the
links before focusing on the title of the related content, when they
probably expected the opposite.

Since we're now using a flexbox layout instead of a right float, this
also means the content will automatically be shown on the left when
switching the content direction to "right to left".
2021-06-23 23:06:24 +02:00
Javi Martín
a5a0977f36 Reuse related content variable
We were defining a variable and then using it in some places while
calculating it again in some other places.
2021-06-23 23:06:24 +02:00
Javi Martín
f298a308c2 Show actions to score related content to everyone
We were only showing these actions to users with small screens and to
mouse users on hover. Keyboard users or users with a touch screen of a
medium or large size could never find out the actions were there.
2021-06-23 23:06:24 +02:00
Javi Martín
e5070fb172 Make "Add related content" button look interactive
The button looked just like regular text and it wasn't obvious that it
was an interactive element.

So we're styling it like the "Hide" link (which should actually be a
button, by the way).

Note buttons by default don't have a `cursor: pointer` property because
they're usually styled in a way that makes it obvious they're
interactive elements. Since that isn't the case here, we're adding that
extra hint for mouse users.

Also note all these links/buttons will look like regular text to color-
blind users. And if they use a touchscreen, they won't be able to hover
on them to see the cursor change. We might need to change these elements
in the future.
2021-06-23 23:06:24 +02:00
Javi Martín
49e0138cd1 Fix label in related content form
It didn't have a `for` attribute and so it wasn't correctly associated
with its input. That means clicking on / touching the label didn't have
the effect of focusing on the field, and screen readers wouldn't
announce the label.
2021-06-23 23:06:24 +02:00
Javi Martín
85215e7e97 Fix aria-expanded value in related content button
The button was announced as expanded when the form was hidden and as
collapsed when the form was shown.

This is because Foundation sets the expanded attribute based on whether
the class to toggle already exists. Since initially the form had the
"hide" class and the button toggled that class, Foundation checked that
the class was already present and so set the button as expanded.

So we're changing the toggler class for a class we don't use at all,
just so Foundation initiall sets `aria-expanded=false` and then changes
it to `aria-expanded=true` after the button is clicked. Then we're
ignoring this class completely and are styling this form with CSS
instead.

We could also use a toggler class like "visible" and write something
like:

```
.add-related-content + form:not(.visible) {
  display: none;
}
```

However, using ARIA attributes is more robust as it guarantees the
styles will always be in sync with what screen reader users experience.

And we could also remove all the Foundation toggler functionality and
use our own JavaScript to handle the button state. We might do so in the
future.
2021-06-23 23:06:24 +02:00
Javi Martín
f1221e9c1c Make relationable test expectations consistent
We're removing the parenthesis after page expectations (as we do almost
everywhere) and we're replacing `have_selector` with `have_css`, since
on that file we were using `have_css` everywhere except in one place.
2021-06-23 23:06:24 +02:00
Javi Martín
f910b326ea Fix indentation in related content form code 2021-06-23 23:06:24 +02:00
Javi Martín
089fe3cd1f Put button to add content next to its related form
This way the relationship between the two elements is more obvious. And
since now the button and the form are siblings, it's easier to find one
based on the other using CSS or JavaScript.
2021-06-23 23:06:18 +02:00
Javi Martín
66ff6898bc Merge pull request #4557 from consul/redundant_placeholders
Remove redundant placeholders in forms
2021-06-23 20:07:43 +02:00
Javi Martín
42c9645fb7 Improve label in dashboard actions link form
We were using a placeholder to indicate content which should be part of
a label.

It might be better to actually use "Link address" as a label instead of
"URL". I'm using "URL" because it's used in other places in the admin
section.
2021-06-23 19:52:50 +02:00
Javi Martín
24d758ee64 Use a label in the email verification email field
We were using a paragraph before the field, and then a field with no
label and a redundant placeholder. This causes accessibility issues for
screen reader users, who will not hear the label being announced when
entering the field, and to users who click on the label expecting it to
automatically focus on its related field (which is the standard browser
behavior).
2021-06-23 19:52:50 +02:00
Javi Martín
1632540984 Remove redundant placeholders in forms
Using placeholders having similar (or identical) text as already present
as a label has a few issues.

First, it's a distraction. Reading the same information twice is
useless, requires an extra effort, and might even frustrate users.

Second, if users start typing before reading the placeholder and see it
disappear, they might think they're missing relevant information,
delete what they typed, and read the placeholder. That will get them
nowhere.

Finally, we display placeholders using a text offering very low contrast
against the background, so users don't think the placeholder is an
actual value entered in the field. Using such low contrast makes the
text hard to read, particularly for users with visual impairments.

So we're removing these placeholders.

This commit only deals with placeholder texts with similar (or
identical) texts as the label text. There might be other places where we
should replace placeholder texts with labels, but that's a different
topic.
2021-06-23 19:52:45 +02:00
Javi Martín
cdc31db723 Merge pull request #4560 from consul/improve_icon_support
Fix SVG icons on old browsers
2021-06-23 13:00:13 +02:00
Javi Martín
767b65e7d6 Remove unused related content button ID attribute 2021-06-22 22:33:02 +02:00
Javi Martín
ea2a613359 Render related content form just to signed in users
It doesn't make much sense to render a hidden form to users who will not
be able to use it.
2021-06-22 22:33:02 +02:00
Javi Martín
8a697216d1 Fix invalid HTML in related content button
A button cannot be inside an anchor tag, and it might confuse some
browsers or screen readers.

We're also making it clear in the tests that the intention is to use a
button there by using `click_button` instead of `click_on` since the
latter also clicks on links.
2021-06-22 22:32:08 +02:00
Javi Martín
918276ec70 Merge pull request #4555 from consul/flaky_recount_spec
Fix flaky poll recount spec
2021-06-22 18:30:14 +02:00
Javi Martín
83ed54dff5 Merge pull request #4559 from consul/speed_up_development_requests
Disable JavaScript debugging in development
2021-06-22 17:26:27 +02:00
Javi Martín
61cfcfcc97 Disable JavaScript debugging in development
While debugging JavaScript is certainly useful, enabling it generates
about 100 extra HTTP requests because we include about 100 JavaScript
files (including external dependencies and files written by us).
Depending on the browser configuration, this might make the browser take
a very long time processing these requests.

On my machine, with these changes, refreshing a page on Firefox takes
about 1 second, while previously it took about 6-8 seconds. With
Chromium, there doesn't seem to be much difference.

Developers are encouraged to temporarily turn debugging while debugging
JavaScript (which is a task I personally do about once a month) if that
makes debugging easier for them.

This change doesn't affect our CSS files, since for CSS we use Sass
instead of the asset pipeline. Sass already compiles all CSS files into
one in the development environment.
2021-06-22 17:11:51 +02:00
Javi Martín
d0f8560c33 Fix SVG icons on old browsers
We were using an `@extend` selector inside a `@supports` condition,
which didn't generate the `@supports` clause as we intended to, so
browsers with no support for mask images were still applying properties
which were meant for browsers with support for mask images.
2021-06-21 20:16:45 +02:00
Javi Martín
017035c659 Merge pull request #4551 from consul/responsive_font_size
Increase font size on extra large screens
2021-06-21 16:11:48 +02:00
Javi Martín
4e04adecf9 Increase font size on extra large screens
Nowadays there are many users with a screen of 1920px (or higher) width
but who don't change their font-size preferences and keep them at 16px,
which is the default in most browsers.

On pages which use the whole window width, that results in unreasonably
long lines which are very hard to read. That's the main reason why many
sites (including CONSUL) use rules like `max-width: 75rem` for the body
or other elements.

However, on extra large screens this causes the content to be in the
middle of the screen while most of the screen is empty, and the text
might also be too small for that resolution, making it harder to read.

There are a few approaches to solve this problem.

Using just viewport units like `font-size: calc(4vw + 4vh + 2vmin);` is
indeed responsive, but it's got an important flaw: it ignores user
preferences, and so the font size will be the same for users who prefer
a 16px size and for users who prefer a 32px size.

Using `calc(1em + 0.2vw)` or similar might make the text too big on
small screens.

Finally, using `max(1em, 1vw)` would work in a similar way to what we're
doing, but zooming in and out would only work when the viewport width is
less than 100em (at that moment, 1em == 1vw).

So we're taking an approach where zooming in and out always works at
least to a certain degree (due to the 0.25em part) and the font size is
increased gradually when we reach the point where the viewport width is
bigger than 100em. We're using 0.25em since it will be exactly 4px with
the default browser configuration, and so calculations are easier than
with (for example) 0.3em.

Disclaimer: I've tested this feature on several devices with different
screen sizes and resolutions, but I must admit there might be cases I'm
unaware of where there are side effects for certain combinations of
screen size/resolution/dpi. In general, though, the side effects should
be similar to what happens when users increase the font size in their
browser's preferences.

Note we're using `Max` instead of `max` because Sass can't handle the
CSS `max` function, as mentioned in commit cdfa23fc6.
2021-06-21 15:38:36 +02:00
Javi Martín
64a3761aee Merge pull request #4526 from consul/relative_font_size
Use relative units as base font size
2021-06-21 15:33:29 +02:00
Javi Martín
de79d8a0fd Merge pull request #4556 from consul/auth_divider
Fix margin in sign in / sign up forms divider
2021-06-21 15:25:35 +02:00
Javi Martín
79007fa2b5 Fix margin in sign in / sign up forms divider
When the "Or fill the following form" text was translated to another
language or customized by administrators, the text could span over two
lines. Since the element had a fixed height, it could overlap with the
text below it.

So now we're using an element with a relative position to achieve the
same effect (have the contents of the elements on top of its border).
2021-06-17 16:04:03 +02:00
Javi Martín
c6a459c115 Merge pull request #4558 from consul/featured_disabled
Respond with 403 when features are disabled
2021-06-17 15:39:12 +02:00
Javi Martín
59518846a8 Merge pull request #4554 from consul/flaky_hidden_spec
Fix flaky hidden budget investments spec
2021-06-17 15:34:22 +02:00
Javi Martín
5f747122c5 Don't assign IDs to user records in tests
This test will fail if the ID of the created record is the same as the
ID of the first user we create in the test. The chance is very low due
to the `rand(9999999)` which causes the test to fail just once every ten
million times. However, why assigning the ID in the first place? Without
it, the test will never fail due to conflicting IDs.
2021-06-17 01:46:48 +02:00
Javi Martín
433b465ec7 Don't assign IDs to assignment records in tests
The test "updates officer_assignment_id_log if amount changes" failed
when the ID we assigned when creating the records was the same as the ID
of the first officer assignment created during that test. It's recently
happened while running our test suite [1] with the following error:

```
1) Poll::Recount logging changes updates officer_assignment_id_log if
amount changes
  Failure/Error: poll_recount.officer_assignment =
                  create(:poll_officer_assignment, id: 101)

     ActiveRecord::RecordNotUnique:
       PG::UniqueViolation: ERROR:  duplicate key value violates unique
       constraint "poll_officer_assignments_pkey"
       DETAIL:  Key (id)=(101) already exists.
```

We're also removing the IDs in the "updates officer_assignment_id_log if
amount changes" test to avoid any possible issues, even if in this test
I think no other officer assignments are created and so there can't be
another record with the same ID.

[1] https://github.com/consul/consul/runs/2818889296
2021-06-17 01:46:48 +02:00
Javi Martín
1627d87890 Avoid adding compiled assets to version control
We've seen a few CONSUL repositories where compiled assets have
accidentally been added to version control. It's pretty easy if you use
something like `git add .` before creating a commit and you've compiled
the assets locally.

Having these assets in version control doesn't help and in certain
environments it might even have side effects. For instance, we might try
updating the source code of a Sass file and might wonder why these
changes are ignored in some test or development environments.
2021-06-17 01:44:24 +02:00
Javi Martín
1e80ab31ee Use relative units as base font size
Using pixels to define font sizes has an important problem: it ignores
user settings. No matter whether users set their font size to 16px (the
default font size in most browsers), to 18px (like I do) or to 32 px
(like users with huge screens or with a visual disability); the size
will not change.

Even if most browsers can zoom to somehow overcome this issue, it's
still annoying. And, in our case, we use relative units most of the time
but absolute units in some places. This leads to situations where some
of the text gets larger when users increase their font size while some
of the text remains the same. Sometimes this results in titles having a
smaller size than regular text below it.

The solution is using relative units everywhere. Quoting the Web
Accessibility Initiative guide for styles [1]:

> The user needs to be able to resize the text to 200% of its size
> anywhere on the page, without the text being cut off or overlapping
> other text. The font size should be defined in relative units, such as
> percentages, em or rem. It is not possible to zoom text set in pixels
> independently from the rest of the page in some browsers.

[1] https://www.w3.org/WAI/tutorials/page-structure/styling/
2021-06-17 01:41:40 +02:00
Javi Martín
125f0bc73a Fix font size on column selector label
It was duplicating the `$base-font-size` value, and it was using pixels
as a unit, which we only use in the `$base-font-size` variable.
2021-06-17 01:41:40 +02:00