Commit Graph

8599 Commits

Author SHA1 Message Date
efgalvao
713ae540b0 Add length validation for debate description
Fixes issue #4013.
2021-08-29 01:13:48 +02:00
Javi Martín
d827768c07 Set HTML dir attribute in RTL languages
This way properties flex layouts text direction will work properly.
2021-08-16 17:47:34 +02:00
Javi Martín
a868a5ff35 Change Foundation text direction in RTL languages
This way, when the language is written form right-to-left, elements
using Foundation mixins/classes will float to the opposite direction as
they do in left-to-right languages. The same will apply to text
alignment.

To offer full support for RTL languages, we need to change every single
reference to `float: left`, `float: right`, `text-align: left`,
`text-align: right`, and possible adjust other properties like `left`,
`margin-left`, `padding-left` or `border-left`. In the meantime, we at
least partially support these languages.

Replacing `float` with `flex` when possible would also improve RTL
support.
2021-08-16 17:47:33 +02:00
Machine Learning
4d27bbebad Add experimental machine learning 2021-08-16 16:31:04 +02:00
Javi Martín
c8d8fae98d Move related list partial to a component
This way the code is easier to follow; the code checking whether the
list has contents is in the partial rendering the list.

We also remove some duplication setting up related content in the
controllers.

For some reason, we have to manually ignore i18n keys which were
automatically ignored when the code was in the view.
2021-08-16 16:30:13 +02:00
Javi Martín
89436b528f Extract component to render a date range
Note we're using the `call` method (which is equivalent to adding an ERB
file) because we were getting an error calling `render` from the `dates`
method:

```
ActionView::Base#lookup_context delegated to
view_renderer.lookup_context, but view_renderer is nil:
```

It might be because we aren't rendering the
`Adming::Budgets::DurationComponent` but just calling one method, and so
there's no view context in this case.
2021-08-16 16:30:13 +02:00
Javi Martín
b5220effd1 Bump ahoy_matey from 1.6.0 to 3.2.0
Bumps [ahoy_matey](https://github.com/ankane/ahoy) from 1.6.0 to 3.2.0.
- [Release notes](https://github.com/ankane/ahoy/releases)
- [Changelog](https://github.com/ankane/ahoy/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ankane/ahoy/compare/v1.6.0...v3.2.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-15 01:26:29 +02:00
dependabot[bot]
d7afb9d8fe Bump devise from 4.7.3 to 4.8.0
Bumps [devise](https://github.com/plataformatec/devise) from 4.7.3 to 4.8.0.
- [Release notes](https://github.com/plataformatec/devise/releases)
- [Changelog](https://github.com/heartcombo/devise/blob/master/CHANGELOG.md)
- [Commits](https://github.com/plataformatec/devise/compare/v4.7.3...v4.8.0)

---
updated-dependencies:
- dependency-name: devise
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-08-13 00:10:15 +02:00
Javi Martín
cdef030f15 Add a consistent order in system email previews
Since PostgreSQL doesn't guarantee the order of the records unless an
`ORDER BY` clause is used, the records sometimes had a different order.
This might cause records being present in more than one page.

One test was failing sometimes (when the record created first was
rendered after the record created last) because there seems to be a bug
in chrome/chromedriver 83 and later which causes links not to be clicked
when they're right at the edge of the screen (which was the case for the
notification appearing in the last place):

```
  1) System Emails Preview Pending #moderate_pending
     Failure/Error: click_on "Moderate notification send"

     Selenium::WebDriver::Error::ElementNotInteractableError:
       element not interactable: element has zero size
         (Session info: headless chrome=91.0.4472.114)
```
2021-08-10 22:07:47 +02:00
Javi Martín
d472b46f3e Fix duplicate HTML ID in system emails preview
The ID was the same for every proposal notification.
2021-08-10 21:56:47 +02:00
Javi Martín
db4451c7c2 Add Performance/BlockGivenWithExplicitBlock rule
We don't need to use `block_given?` since we specifically pass the block
parameter, particularly since we added the Style/ExplicitBlockArgument
rule in commit a102f3f0a.
2021-08-10 13:31:37 +02:00
Javi Martín
e619ca992c Add and apply Performance/Sum rubocop rule
We're not adding it for performance reasons but because it simplifies
the code.
2021-08-10 13:30:07 +02:00
Javi Martín
ab9e99f45c Merge pull request #4288 from consul/dependabot/bundler/rubocop-rails-2.9.1
Bump rubocop-rails from 2.6.0 to 2.9.1
2021-08-10 13:23:32 +02:00
Javi Martín
bab5cbf03a Merge pull request #4215 from consul/dependabot/bundler/rubocop-0.93.1
Bump rubocop from 0.91.1 to 0.93.1
2021-08-10 13:15:52 +02:00
Javi Martín
884fd2b27b Add and apply Rails/WhereEquals rubocop rule
We were already following this style in most places.
2021-08-09 23:52:47 +02:00
Javi Martín
8ae138aa19 Add and apply Rails/WhereNot rubocop rule
We simplify the code a little bit, and make it more consistent since we
were already using `where.not` in most places.
2021-08-09 23:52:47 +02:00
Javi Martín
69dda19af7 Add and apply Rails/PluckId rubocop rule 2021-08-09 23:52:47 +02:00
Javi Martín
8d47acc12b Add and apply Rails/ActiveRecordCallbacksOrder rule
We were already following it most of the time.
2021-08-09 23:52:34 +02:00
decabeza
4a9aae9806 Add groups index page
When render the investment list component with the link "see all
investments", now we redirect to groups index page when a budget has
multiple headings.
2021-08-09 21:45:29 +02:00
Javi Martín
469b39ffa3 Add and apply Style/RedundantInterpolation rule
Somehow I thought we already had this rule; must have forgotten to
actually add it.
2021-08-09 21:37:04 +02:00
Javi Martín
3cd2529791 Fix huge header in participatory budgets
The budget header was supposed to be huge, but only in the participatory
budgets index or show actions. It was still huge, with plenty of empty
space, when there was no budget, or in the "submit my ballot" and
"select a heading" pages.
2021-08-09 20:07:51 +02:00
Javi Martín
297956b579 Extract placeholder selector for budget header
This way it'll be easier to reuse its main properties.
2021-08-09 20:07:51 +02:00
taitus
c6b23bb6fa Render investments list in all budgets types
We make this change to unify the index/show budget pages.

This way both single and multiple budgets will render the investments
list component.
2021-08-09 20:07:51 +02:00
Javi Martín
99bbad9b1e Add and apply Style/RedundantCondition rule
This is a rule we generally follow all the time but accidentally forgot
in one place.
2021-08-09 19:21:31 +02:00
Javi Martín
a102f3f0a7 Add and apply Style/ExplicitBlockArgument rule
We were already applying it in most places.
2021-08-09 19:11:29 +02:00
Javi Martín
57d8a59d10 Add an apply Style/RaiseArgs rubocop rule
We were already applying it most of the time.
2021-08-09 17:32:46 +02:00
Javi Martín
930bb753c5 Use a rake task to delete cached attachments
Our previous system to delete cached attachments didn't work for
documents because the `custom_hash_data` is different for files created
from a file and files created from cached attachments.

When creating a document attachment, the name of the file is taken into
account to calculate the hash. Let's say the original file name is
"logo.pdf", and the generated hash is "123456". The cached attachment
will be "123456.pdf", so the generated hash using the cached attachment
will be something different, like "28af3". So the file that will be
removed will be "28af3.pdf", and not "123456.pdf", which will still be
present.

Furthermore, there are times where users choose a file and then they
close the browser or go to a different page. In those cases, we weren't
deleting the cached attachments either.

So we're adding a rake task to delete these files once a day. This way
we can simplify the logic we were using to destroy cached attachments.

Note there's related a bug in documents: when editing a record (for
example, a proposal), if the title of the document changes, its hash
changes, and so it will be impossible to generate a link to that
document. Changing the way this hash is generated is not an option
because it would break links to existing files. We'll try to fix it when
moving to Active Storage.
2021-07-30 17:30:11 +02:00
Javi Martín
c0a6bf54fc Fix invisible error message in attachments
In commit cc6f9391f we made the images and documents file inputs
invisible (instead of using `display: none`) in order to make it
possible to attach images and documents using the keyboard.

However, since the error messages associated to these inputs has the
same HTML class as the inputs, we were also hiding them (the `display:
none` didn't affect the error messages because they've also got the
`is-visible` class).

Using the `[type=file]` selector we make it more explicit that we only
want to style these inputs.

I'm not adding a test for this scenario because technically the text is
there and I'm not sure how to test for the presence of invisible
elements.
2021-07-27 23:57:41 +02:00
Javi Martín
6c63aaee76 Fix removing existing image and adding a new one
We introduced a bug in commit acbd1b023.

When editing a record and removing an existing image, we don't remove
the HTML fields associated with that image but simply hide them, and
then we add fields to create a new image when clicking on "Add image".

This is standard cocoon behavior. However, since in the case of images
there's a `has_one` relation, cocoon doesn't add unique identifiers to
the new fields, generating duplicate IDs, which is invalid HTML.

Since there's a duplicate file input ID, clicking on the "Choose image"
label we aren't clicking on the new input but on the old one. This means
we aren't correctly attaching an image. The tests passed because
Capybara uses the equivalent of a keyboard to select the field, and in
this case everything worked properly.

So we need to delete the existing elements before inserting new ones.
We're adding a test to check there aren't duplicate IDs.
2021-07-27 19:27:29 +02:00
Javi Martín
b3104fae68 Merge pull request #4586 from consul/attach_with_keyboard
Allow attaching files using the keyboard
2021-07-15 00:19:27 +02:00
decabeza
e42db48f2b Do not show confirm message if user can vote in all headings 2021-07-14 16:14:29 +02:00
Javi Martín
cc6f9391fc Fix attaching files using the keyboard
We were hiding the file input and styling the label as a button instead.
Since clicking on a label has the same effect as clicking on the input,
the input worked properly for mouse and touch screen users.

However, hiding the input makes it inaccessible for keyboard users,
since labels don't get keyboard focus, but inputs do.

So we must not hide the input but make it invisible instead. But we
still need to hide the input (alongside the label) after a file has been
attached.

We could add some extra JavaScript to hide the input when we hide the
label. Since the JavaScript is already quite complex and my first few
attempts at changing it failed, I've opted to assume that the input (and
its label) must be hidden whenever there's already a file name, and
implement that rule with CSS.

Note we're using the `:focus-within` pseudoclass to style a label when
focus is on the input. This rule (at the time of writing) is only
supported by 93.5% of the browsers. Keyboard users without a screen
reader and using the other 6.5% of the browsers will still be able to
focus on the field but might not notice the field has received focus.
Since the percentage of affected users will decrease over time and until
now 100% of keyboard users were completely unable to focus on these
fields, for now we think this is a good-enough solution.
2021-07-13 17:09:05 +02:00
Javi Martín
6da8eeac6f Simplify code to delete a cached attachment
We were already defining the links with data-remote and data-method, so
instead of manually doing an AJAX request we can rely on Rails to
perform the request and then handle the `ajax:complete` event.
2021-07-13 16:58:22 +02:00
Javi Martín
367d3f9d14 Remove condition for non-nested case
We don't use these input fields inside a non-nested context since commit
2993ef870.
2021-07-13 16:58:22 +02:00
Javi Martín
a7e2f1ae30 Move file name before the destroy attachment link
This way screen reader users will hear the name of the file before
hearing about the link to destroy it. We were already displaying it this
way visually by having the file name on the left and the destroy link on
the right.

Thanks to this change we can also simplify the code which dynamically
changed the layout.
2021-07-13 16:58:22 +02:00
Javi Martín
acbd1b0239 Simplify code to reset attachment fields
Since elements are created and destroyed, we don't have to do any kind
of "reset" before destroying or creating them. We would have to do so if
we were just hiding the elements in order to show them again later, but
that's not the case.
2021-07-13 16:58:13 +02:00
Javi Martín
8cdee167f8 Fix duplicate HTML ID in document fields
Using `dom_id` means generating `new_document` as ID for new documents.
Since there might be more than one new document in the form, that means
duplicate IDs, which is invalid HTML.

Even though this issue doesn't affect image fields (because we don't
have many images on the same form), we're removing the ID there as well
for consistency.
2021-07-13 16:58:13 +02:00
Javi Martín
394a94cbff Fix invalid HTML in document/image fields labels
These labels weren't associated with any fields, which is invalid HTML.
We're using a legend inside a fieldset instead, which is the natural way
to group form fields together.
2021-07-13 16:58:13 +02:00
Javi Martín
c9903f36cc Simplify imageable/documentable note method names 2021-07-13 16:58:13 +02:00
Javi Martín
67c29a7c5f Remove duplication in max documents allowed code 2021-07-13 16:58:13 +02:00
Javi Martín
a181052f0d Move nested images partial to a component 2021-07-13 16:58:13 +02:00
Javi Martín
c9113041c0 Move nested documents partial to a component 2021-07-13 16:58:13 +02:00
Javi Martín
629df5ab9b Simplify getting imageable/documentable in forms
The imageable/documentable object is always the object the form builder
is based on; since we're already passing the form builder, we don't have
to pass the object as well.

The only exception are the poll answers. In this case, we're passing a
new answer as the object. That's OK; the same hack that we're using to
send the data to the answer URL without displaying existing attachments
causes the form to keep working the same way.
2021-07-13 16:58:13 +02:00
Javi Martín
ac495e7523 Remove unnecessary code in poll images controller
We're already loading the answer with a `before_action`.
2021-07-13 16:58:13 +02:00
Javi Martín
3073fee4c8 Remove unused documentable class method
It isn't used since commit 6c1d828a6.
2021-07-13 16:58:13 +02:00
Javi Martín
21fee9cff5 Simplify method names in image/document fields
We were using long, unique names because these methods used to be helper
methods. Helper methods should have unique names because otherwise one
method would overwrite the other.

Now that we're using components, we can omit the `image_` and
`document_` prefixes.
2021-07-13 16:58:13 +02:00
Javi Martín
8116e75aee Simplify showing/hiding attached file name
Note we have to render the `<p>` tag in one line because at the time of
writing browsers don't consider elements with whitespace inside as empty
[1].

[1] https://developer.mozilla.org/en-US/docs/Web/CSS/:empty
2021-07-13 16:58:13 +02:00
Javi Martín
5cf96ba03d Extract methods to get objects in attachment forms 2021-07-13 16:58:13 +02:00
Javi Martín
810814486c Move document fields partial to a component 2021-07-13 16:58:13 +02:00
Javi Martín
d58c2f8323 Move image fields partial to a component 2021-07-13 16:58:13 +02:00