Commit Graph

151 Commits

Author SHA1 Message Date
Javi Martín
f1105140ae Remove duplicate <main> tags in management views
There can only be one <main> tag in a document, and we've already got a
<main> tag in the management layout.
2024-03-23 00:33:41 +01:00
taitus
7c771b28b5 Add password complexity 2023-10-24 19:00:43 +02:00
Javi Martín
0edfd0cab5 Open management links in the same window
We were doing it this way because managers usually have the management
section open at all times. However, this might not always be the case,
and by opening links in a new tab, we're taking control away from them.

If managers would like to keep the management section open, they can
open the link in a new tab, and if they open it in the same tab, they
can go back to the management section by either clicking the browser's
back button or clicking on the navigation link to the management
section.
2023-10-24 16:31:39 +02:00
Javi Martín
629e208e9d Add and apply ArgumentAlignment rubocop rule
We're choosing the default `with_first_argument` style because it's the
one we use the most.
2023-08-18 14:56:16 +02:00
Javi Martín
8b13daad95 Add and apply rules for multi-line hashes
For the HashAlignment rule, we're using the default `key` style (keys
are aligned and values aren't) instead of the `table` style (both keys
and values are aligned) because, even if we used both in the
application, we used the `key` style a lot more. Furthermore, the
`table` style looks strange in places where there are both very long and
very short keys and sometimes we weren't even consistent with the
`table` style, aligning some keys without aligning other keys.

Ideally we could align hashes to "either key or table", so developers
can decide whether keeping the symmetry of the code is worth it in a
case-per-case basis, but Rubocop doesn't allow this option.
2023-08-18 14:56:16 +02:00
Senén Rodero Rodríguez
96f584c4f7 Allow printing investments from any budget in the management interface 2023-02-03 12:18:13 +01:00
Senén Rodero Rodríguez
569138cbae Extract view into component 2023-01-16 13:36:31 +01:00
Javi Martín
9b908d7264 Extract component to render account permissions
We were using similar code in four different places; six, if we count
the welcome pages seeds. Reducing duplication in the pages seeds is a
bit tricky because administrators are supposed to edit their content and
might remove the HTML class we use to define styles. However, we can
share the code everywhere else.

Note that there's a bug in the application since we show that level 2
users cannot vote for budget projects but we give them permission to do
so in the abilities model. We're keeping the same behavior after this
refactoring but we might change it in the future.
2022-11-29 18:48:24 +01:00
Javi Martín
92b1e53fc3 Unify user permission texts
We had the same texts four times, with slight variations in the case of
the management section.

We're unifying them under the "verification" i18n namespace, since the
texts are about actions which can be done depending on whether users are
verified or not.

Note the names of the i18n keys aren't very consistent, since we use
"debates" in plural but "proposal" in singular. We're leaving it like
this so existing translations aren't affected.
2022-06-01 14:27:33 +02:00
Javi Martín
015613a140 Fix HTML injection in search results summary
In commit f374478dd, we enabled the possibility to use HTML in the
search results translations in order to add a <strong> tag to these
results. However, that meant we were also allowing HTML tags inside the
search term itself, and so it was possible to inject HTML on the page.

Stripping the HTML tags solves the issue.

Note the issue wasn't a high severity issue because tags such as
`<script>` weren't allowed since we were using the `sanitize` helper.
2022-04-12 14:23:35 +02:00
Javi Martín
e54b6b3d97 Increase investments width in management section
I'm not sure whether it now looks worse on extra large screens, but I'm
positive it looks much better on medium and large screens, particularly
when investments have images.
2021-11-09 01:36:19 +01:00
Javi Martín
7a1acf5706 Rename proposal-form HTML class to proposal-new
So it's consistent with the proposal-edit class we use in the edit
action.
2021-07-13 15:25:31 +02:00
decabeza
823cc37ce8 Update styles and layout for new budget investment form 2021-07-09 14:25:24 +02:00
Javi Martín
14d8bef0d8 Use order links in print proposals management
A `<select>` tag here might make more sense than in other similar places
since there are 5 options to choose among, and using links might take
too much screen space.

However, as mentioned in the previous commits, `<select>` tags which
automatically submit a form have many accessibility and usability
issues.

An alternative would be to create a dropdown menu with a button and a
list of links (similar to what Foundation does). I'm keeping the links
for simplicity and because the interface looks a bit more consistent
with the rest of the sections. Before these changes, we had a heading,
then a `<select>` field to choose the filter, and then a button to print
the page. We never use a similar interface, and some people might think
the "Print" button is related to the same form as the `<select>` field.

Now that we don't use the `order_selector` partial anywhere anymore, we
can remove it.
2021-06-28 00:15:08 +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
decabeza
a851048d56 Allow users to remove their support on investments
Note we don't cast negative votes when users remove their support. That
way we provide compatibility for institutions who have implemented real
negative votes (in case there are / will be any), and we also keep the
database meaningful: it's not that users downvoted something; they
simply removed their upvote.

Co-Authored-By: Javi Martín <javim@elretirao.net>
Co-Authored-By: Julian Nicolas Herrero <microweb10@gmail.com>
2021-06-14 14:46:54 +02:00
Javi Martín
758cdaf8d7 Extract controllers to support investments
Since we're going to add an action to remove supports, having a separate
controller makes things easier.

Note there was a strange piece of code which assumed users were not
verified if they couldn't vote investments. Now the code is also
strange, since it assumes users are not verified if they can't create
votes. We might need to revisit these conditions if our logic changes in
the future.
2021-06-14 14:42:03 +02:00
Javi Martín
0214184b2d Remove investment supports query optimizations
In the previous commit I mentioned:

> If I'm right, the `investment_votes` instance variable only exists to
> avoid several database queries to get whether the current user has
> supported each of the investments.
>
> However, that doesn't make much sense when only one investment is
> shown.

Now let's discuss the case when there are several investments, like in
the investments index:

* There are 10 investments per page by default
* Each query takes less than a millisecond
* We still make a query per investment to check whether the current user
  voted in a different group
* AFAIK, there have been no performance tests showing these
  optimizations make the request to the investments index significantly
  faster
* These optimizations make the code way more complex than it is without
  them

Considering all these points, I'm removing the optimizations. I'm fine
with adding `includes` calls to preload records and avoid N+1 queries
even if there are no performance tests showing they make the application
faster because the effect on the code complexity is negligible. But
that's not the case here.

Note we're using `defined?` instead of the `||=` operator because the
`||=` operator will not serve its purpose when the result of the
operation returns `false`.
2021-06-14 14:41:57 +02:00
Javi Martín
5fab843184 Simplify managing investment votes
If I'm right, the `investment_votes` instance variable only exists to
avoid several database queries to get whether the current user has
supported each of the investments.

However, that doesn't make much sense when only one investment is shown.
In this case, the number of queries stays the same, and so we can
simplify the code by rendering the component with an optional parameter.
2021-06-14 14:41:51 +02:00
Javi Martín
d5f4313f59 Simplify getting URL to support an investment
We're also changing the method name to `vote_path` in order to be
consistent with the way Rails uses `_path` for relative URLs.
2021-06-14 14:38:34 +02:00
Javi Martín
014d29b991 Extract method to get a budget phase title 2021-03-09 16:37:47 +01:00
Javi Martín
00656e2e10 Fix SpaceAroundErbTag offense 2021-02-08 15:18:56 +01:00
Javi Martín
f864156b21 Add and apply ClosingErbTagIndent ERB Lint rule
Note this rule does still allow us to add new lines after opening tags;
it just makes sure that if we do, we also add it in closing tags.
Likewise, if we don't add it in the opening tag, it forces us not to add
it in the closing tag either.

I don't have a strong preference about either style; in these cases I've
chosen the latter because it seemed more common in our code.
2021-02-05 17:39:42 +01:00
Javi Martín
663fba53db Group admin search label translations together
Since there are two different labels/placeholders for poll officers and
also two different ones for users, we're only grouping one of each.
2020-12-21 18:25:45 +01:00
Javi Martín
55d2cfe5b1 Use link list helper in admin menus
For now we're not including lists with nested lists.
2020-12-07 15:28:56 +01:00
Javi Martín
cf510043a4 Search on the same URL by default 2020-12-07 14:28:36 +01:00
Javi Martín
e33794e45e Reuse admin search component in other sections
There are some sections where we are not reusing it:

* The budget investments search is completely different, so this
  component isn't appropriate there
* Booth assignment and officers are slightly different, and I'm not
  entirely sure it's safe to refactor these cases
2020-12-04 19:57:05 +01:00
Javi Martín
bdf30aa14e Use CSS to display icons in the admin menu
This way we simplify the HTML and generating similar menus will be
easier. We also improve the experience for screen reader users, who
might have been hearing the icons as text because we weren't using the
`aria-hidden` attribute.

We're still keeping the "icon-" classes for compatibility with CONSUL
installations which might have changed this code.
2020-11-27 12:33:42 +01:00
Javi Martín
d99ca9bd34 Use CSS to make items bold in the admin menu
From a semantic point of view, there's no reason to add a strong
emphasis to the menu items.

Besides, using CSS simplifies the code and is less error-prone. For
instance, the "stats" section didn't have a <strong> tag, and so it was
the only one which wasn't bold.
2020-11-26 20:04:08 +01:00
Javi Martín
a293dc013d Make management layout similar to admin layout
The <main> tag was including the navigation, and now we use the same
flex layout, making it more accessible for mobile phone users.

I'm not sure the <main> tag should actually include the account info and
the flash message. I'm keeping it like this in order to keep the layout
the way it was.
2020-09-21 15:14:20 +02:00
Javi Martín
125106f9c0 Simplify code to have an off-canvas menu
While Foundations's off-canvas menu allows us to forget about writing
CSS, it also leads to complicated HTML.

Ideally Foundation would provide an easy way to simplify what we're
doing, but I haven't found anything in the documentation.

We could simplify the HTML a bit more if we used a CSS grid layout
instead of a flex one, but old browsers have better support for the
latter.

Note we're using `breakpoint(medium)` so we can group the CSS for small
screens and follow SCSS-Lint rules at the same time.

Also note behavior of the main area when the menu appears on small
screens is slightly different: it doesn't move the main content to the
right. I've done it this way so we don't have any overflow issues,
unlike the previous version.

There's a small issue using a label and a checkbox to enable/disable the
menu: sighted keyboard users with a small screen might not be able to
enable the menu. So we're adding the `:focus-within` pseudoclass so the
menu can be normally navigated using the keyboard. Even if old browsers
don't support this pseudoclass, we believe the probability of a sighted
user using a small screen, navigating with the keyboard and using an old
browser is really low, particularly in the admin area.

We're also adding the `aria-hidden` attribute on the label, since the
menu is never hidden for screen readers and so having a control to show
it could be confusing. Since the label is not focusable, we're complying
with the fourth ARIA rule:

> Do not use role="presentation" or aria-hidden="true" on a focusable
> element .
>
> Using either of these on a focusable element will result in some users
> focusing on 'nothing'.
2020-09-21 15:14:20 +02:00
Javi Martín
749428d93f Replace content_tag with new tag builder syntax
One of the main advantages of this syntax is we can now omit the content
parameter when it's empty.
2020-04-27 19:26:37 +02:00
Javi Martín
27468b0b7b Use relative URLs where possible
In general, we always use relative URLs (using `_path`), but sometimes
we were accidentally using absolute URLs (using `_url`). It's been
reported i might cause some isuses if accepting both HTTP and HTTPS
connections, although we've never seen the case.

In any case, this change makes the code more consistent and makes the
generated HTML cleaner.
2019-10-20 17:26:14 +02:00
Javi Martín
6b1864fbcd Sanitize translations instead of using _html
Using the `_html` suffix in an i18n key is the same as using `html_safe`
on it, which means that translation could potentially be used for XSS
attacks.
2019-10-09 19:46:47 +02:00
Javi Martín
b66859945e Remove _html suffix from already sanitized texts
Using the `_html` suffix automatically marks texts as HTML safe, so
doing so on sanitized texts is redundant.

Note flash texts are not sanitized the moment they are generated, but
are sanitized when displayed in the view.
2019-10-09 19:46:47 +02:00
Javi Martín
928312e218 Use sanitize in translations with links
Sometimes we're interpolating a link inside a translation, and marking
the whole translations as HTML safe.

However, some translations added by admins to the database or through
crowdin are not entirely under our control.

Although AFAIK crowdin checks for potential cross-site scripting
attacks, it's a good practice to sanitize parts of a string potentially
out of our control before marking the string as HTML safe.
2019-10-08 18:46:21 +02:00
Javi Martín
9ddbd01f91 Use active model translations for labels
The same way we did for Active Record, but this time we do it for models
not inheriting fom Active Record.
2019-10-07 01:56:24 +02:00
Javi Martín
3ea9f3cecf Simplify generating form fields with labels
Instead of generating the label and then a field without a label, we can
directly generate a field with a label.
2019-10-05 16:01:58 +02:00
Javi Martín
f9ed186909 Add rubocop spacing rules
We were following these rules in most places; we just didn't define them
anywhere.
2019-09-10 21:04:56 +02:00
Javi Martín
71d9ddd849 Apply rule to end files with a newline character 2019-09-10 20:02:15 +02:00
Javi Martín
911fe4e481 Simplify calls to render partial
We're also adding a bit of consistency, since most of our calls to
partial rendering omit the `partial` and `locals` keys.
2019-09-04 15:00:36 +02:00
Javi Martín
4ab535dec4 Remove comma inside a HTML tag
The typo was detected thanks to erb-lint SpaceInHtmlTag rule.
2019-08-27 17:22:22 +02:00
taitus
ceaf118188 Add new fields to form
- Add :date_of_birth and :postal_code
- Only display new fields when aplication has configured the Remote
  Census API and contains values for fields. Check with Setting Class
  methods:
  - force_presence_date_of_birth?
  - force_presence_postal_code?
2019-07-29 13:10:09 +02:00
voodoorai2000
d0b8fef6b3 Delete spending proposals 2019-05-31 18:22:59 +02:00
rgarcia
a4f0161aa8 fixes specs related to ActionController params 2019-04-17 17:40:55 +02:00
Javi Martín
3e4e65ead7 Use double quotes inside ERB
We were using single quotes inside ERB code when that code was inside
HTML double quotes.
2019-03-25 14:58:54 +01:00
Julian Herrero
c82b2a975a Add new settings tab for participation processes
- Rename setting keys
- New tab por participation processes
- Hide these settings from features tab
2019-03-19 19:45:32 +01:00
Julian Herrero
0e0462368b Use double quotes in app/views/management 2019-03-19 12:16:50 +01:00
decabeza
b43945ad33 Removes custom content on management and devise views 2018-07-30 17:58:13 +02:00