Commit Graph

15065 Commits

Author SHA1 Message Date
decabeza
0896701b57 Remove unused document section on polls
This section is not used because it's only possible to add documents to the poll's answers not to the poll itself.
2020-06-18 09:30:25 +02:00
Javier Martín
769db34b76 Merge pull request #4040 from consul/rename_admin_proposal_notifications_controller
Rename admin proposal notifications controller
2020-06-16 19:56:21 +02:00
Javi Martín
438a751599 Rename admin proposal notifications controller
To be consistent with all the other controllers dealing with hidden
content, we use the word "hidden" in the controller class.
2020-06-16 19:40:04 +02:00
Javier Martín
539db4398a Merge pull request #4038 from consul/fix_admin_search
Fix deleting searched managers/moderators/admins
2020-06-16 19:39:14 +02:00
Javi Martín
99256adf13 Simplify manager/moderator/admin/official tables
Originally, the code was shared between the index action and the search
action, but since commit fb6dbdf2 that's no longer the case. So in the
index action we don't need to check whether a user is a
moderator/manager/admin/official or not; they all are.
2020-06-16 19:26:05 +02:00
Javi Martín
5d10afdf26 Fix deleting searched managers/moderators/admins
We were deleting managers, moderators and administrators based on their
user ID, instead of their manager/moderator/administrator ID.
2020-06-16 19:09:27 +02:00
Javier Martín
21572e704d Merge pull request #4033 from consul/dependabot/bundler/websocket-extensions-0.1.5
[Security] Bump websocket-extensions from 0.1.4 to 0.1.5
2020-06-16 17:49:09 +02:00
dependabot-preview[bot]
976f031984 [Security] Bump rack from 2.2.2 to 2.2.3
Bumps [rack](https://github.com/rack/rack) from 2.2.2 to 2.2.3. **This update includes a security fix.**
- [Release notes](https://github.com/rack/rack/releases)
- [Changelog](https://github.com/rack/rack/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rack/rack/compare/v2.2.2...2.2.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-06-16 12:16:08 +00:00
Javier Martín
99dc861d45 Merge pull request #4036 from consul/space_around_method_call_operator
Apply Layout/SpaceAroundMethodCallOperator rule
2020-06-16 14:13:52 +02:00
Javi Martín
4bb906f0be Apply Layout/SpaceAroundMethodCallOperator rule
This rule was added in rubocop 0.82.
2020-06-16 13:47:38 +02:00
Javi Martín
5315f34c72 Remove Performance/Detect rubocop rule
After upgrading the rubocop-performance gem, we're asked to change this
code:

milestones.select { |milestone| milestone.image.present? }.last

To:

milestones.reverse.find { |milestone| milestone.image.present? }

IMHO the original code is easier to read, so the performance gain isn't
worth it.
2020-06-16 13:47:38 +02:00
Javi Martín
199d8ff609 Bump rubocop from 0.75.0 to 0.83.0
Recent versions introduce the `Layout/SpaceAroundMethodCallOperator`,
which we are going to use. We aren't upgrading to the latest rubocop
version because it conflicts with the version of Capybara we're using
and because it isn't supported by Hound.

Some rules have been renamed:

Layout/IndentAssignment is now Layout/AssignmentIndentation
Layout/IndentHeredoc is now Layout/HeredocIndentation
Layout/LeadingBlankLines is now Layout/LeadingEmptyLines
Layout/Tab is now Layout/IndentationStyle
Layout/TrailingBlankLines is now Layout/TrailingEmptyLines
Lint/StringConversionInInterpolation is now Lint/RedundantStringCoercion
Metrics/LineLength is now Layout/LineLength

Note after upgrading we get a new "offense" in the `StartWith` rule, so
we're changing the code in order to fix it.
2020-06-16 13:47:38 +02:00
Javier Martín
129fbb52e5 Merge pull request #4007 from consul/development_cache
Use a memory cache store in development
2020-06-15 19:21:23 +02:00
Javier Martín
3872e3792d Merge pull request #3952 from consul/resolve
Use "resolve" for polymorphic hierarchy paths
2020-06-15 17:31:55 +02:00
Javi Martín
65604a92c2 Add non-prefixed polymorphic admin routes
These routes are solved in a different way because of an inconsistency:
we define `groups` and `budget_investments`; we should either use the
`budget_` prefix in all places or remove it everywhere.

We can now share code using `polymorphic_path` even with these models.
2020-06-15 11:54:05 +02:00
Javi Martín
7563b7f4d1 Simplify polymorphic routes in shared specs
Now we get rid of the "hierarchy" methods and use standard Rails methods
except in the routes definitions themselves.
2020-06-15 11:54:05 +02:00
Javi Martín
ff93f5a591 Use "resolve" for polymorphic hierarchy paths
In the past, we couldn't use `polymorphic_path` in many places. For
instance, `polymorphic_path(budget, investment)` would return
`budget_budget_investment_path`, while in our routes we had defined
`budget_investment_path`.

With the `resolve` method, introduced in Rails 5.1, we can use symbols
to define we want it to use `investment` instead of `budget_investment`.
It also works with nested resources, so now we can write
`polymorphic_path(investment)`.

This makes the code for `resource_hierarchy_for` almost impossible to
understand. I reached this result after having a look at the internals
of the `resolve` method in order to get its results and then remove the
symbols we include.

Note using this method will not make admin routes compatible with
`polymorphic_path`. Quoting from the Rails documentation:

> This custom behavior only applies to simple polymorphic URLs where a
> single model instance is passed and not more complicated forms, e.g:
> [example showing admin routes won't work]

Also note that now the `admin_polymorphic_path` method will not work for
every model due to inconsistencies in our admin routes. For instance, we
define `groups` and `budget_investments`; we should either use the
`budget_` prefix in all places or remove it everywhere. Right now the
code only works for items with the prefix; it isn't a big deal because
we never call it with an item without the prefix.

Finally, for unknown reasons some routing tests fail if we use
`polymorphic_path`, so we need to redefine that method in those tests
and force the `only_path: true` option.
2020-06-15 11:54:05 +02:00
Javi Martín
334b57501b Simplify uses of polymorphic admin nested routes 2020-06-11 18:39:57 +02:00
Javier Martín
59f70641cb Merge pull request #4026 from consul/fill_in_ckeditor
Fix chromedriver hanging with CKEditor
2020-06-09 14:47:06 +02:00
Javi Martín
72c2b87227 Wait till CKEditor is ready before checking it
With chromedriver >= 80, the tests are freezing sometimes, particularly
when the same editor is loaded again.

We don't know whether it's a CKEditor issue or a chromedriver issue. In
the past we've had some errors related to CKEditor trying to load the
same instance twice and we aren't sure they have been fixed since we
could never reproduce them.

It could be a coincidence, though. If we modify the views so the only
content of the `<body>` tag is a textarea with the `html-area` class,
chromedriver freezes even if we only access the page once. So maybe
we're only detecting the problem on the second visit because the second
request is faster than the first one.

Since chromedriver no longer hangs after this change, we don't have to
force any chromedriver version anymore.
2020-06-09 13:29:56 +02:00
Javi Martín
8408bfdcf0 Don't use ckeditor.setData in specs
After upgrading to chromedriver 80, tests checking CKEditor's content
were causing chromedriver to hang. That's why we were configuring
webdrivers to use an older chromedriver.

Version 80 of chromedriver introduced several issues regarding frames.
Debugging shows in this case chromedriver froze when we used `setData`
and then `within_frame`. Since adding a `sleep` call made it work, we
think `within_frame` was being executed before `setData` had finished.
The fact that `setData` causes the browser to enter the frame having
CKEditor is probably the reason.

Even though the `setData` method provides a callback when it's finished,
configuring it so the rest of the Ruby code isn't executed until that
happens leads to complex code. Using Capybara's `set` to fill in the
editor is IMHO a bit easier to understand.

After this change, since we're using a method provided by Capybara
instead of executing asynchronous JavaScript code, we don't have to
check CKEditor has been filled anymore. The "Admin Active polls add"
test, which failed on my machine without that check, now passes.
2020-06-09 13:29:56 +02:00
Javi Martín
4d65507cbb Check for exact text in have_ckeditor
If we don't use the `exact` option, tests will pass even if filling in
CKEditor adds the content twice or adds the new content to the existing
content, which has actually happened and has gone mostly unnoticed while
testing several ways to fill in CKEditor with Capybara (particularly,
when using Capybara's `send_keys` method). The problem was detected by
just one test, which checked the original content wasn't present anymore
after updating a record.
2020-06-09 13:29:56 +02:00
Julian Herrero
fb0917026c Add processes feature info section in help page 2020-06-08 11:39:27 +07:00
dependabot-preview[bot]
4b5f518482 [Security] Bump websocket-extensions from 0.1.4 to 0.1.5
Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-ruby) from 0.1.4 to 0.1.5. **This update includes a security fix.**
- [Release notes](https://github.com/faye/websocket-extensions-ruby/releases)
- [Changelog](https://github.com/faye/websocket-extensions-ruby/blob/master/CHANGELOG.md)
- [Commits](https://github.com/faye/websocket-extensions-ruby/compare/0.1.4...0.1.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-06-05 14:36:56 +00:00
Javier Martín
4aee1d28cf Merge pull request #4027 from consul/dependabot/bundler/kaminari-1.2.1
[Security] Bump kaminari from 1.1.1 to 1.2.1
2020-05-29 18:24:49 +02:00
dependabot-preview[bot]
eab36f476e [Security] Bump kaminari from 1.1.1 to 1.2.1
Bumps [kaminari](https://github.com/kaminari/kaminari) from 1.1.1 to 1.2.1. **This update includes a security fix.**
- [Release notes](https://github.com/kaminari/kaminari/releases)
- [Changelog](https://github.com/kaminari/kaminari/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kaminari/kaminari/compare/v1.1.1...v1.2.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-05-28 21:14:42 +00:00
Javier Martín
83b930f357 Merge pull request #4014 from consul/dependabot/bundler/puma-4.3.5
[Security] Bump puma from 4.3.3 to 4.3.5
2020-05-26 18:57:35 +02:00
dependabot-preview[bot]
8e36fab5ad [Security] Bump puma from 4.3.3 to 4.3.5
Bumps [puma](https://github.com/puma/puma) from 4.3.3 to 4.3.5. **This update includes security fixes.**
- [Release notes](https://github.com/puma/puma/releases)
- [Changelog](https://github.com/puma/puma/blob/master/History.md)
- [Commits](https://github.com/puma/puma/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-05-26 16:39:43 +00:00
Javier Martín
f929108870 Merge pull request #4023 from consul/homepage_confirm_dialog
Don't use confirm dialog in admin homepage form
2020-05-26 18:14:58 +02:00
Javier Martín
a3ed4e380e Merge pull request #4003 from rockandror/fix-comments-reply-alternate
Update comment responses count when adding replies
2020-05-26 14:14:22 +02:00
Senén Rodero Rodríguez
31c0b4360d Improve the way to toggle comment responses
Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-05-26 13:20:26 +02:00
Senén Rodero Rodríguez
dcff7e8a33 Show parent comment responses when a new reply is added
When a user replies to a comment whose responses was hidden at the
moment of reply form submission and although the reply were correctly
added to the DOM it was hidden because was added to a collapsed list.

This solution is about showing all responses of parent comment after adding
the new comment to the DOM so the user can see new reply into the screen.
(This is not applicable to root comments which cannot be collapsed)
2020-05-26 13:20:26 +02:00
Senén Rodero Rodríguez
014fa6eb1c Add mutations observer to initialize user initials added through ajax 2020-05-26 13:20:26 +02:00
Senén Rodero Rodríguez
956f002738 Update parent comment responses count when a new reply is created
Extract the needed portion of code to a new partial to be able to update
only the elements needed when a new comment is added keeping UI properly
updated.
2020-05-26 13:20:26 +02:00
Javi Martín
5bf968d2b2 Don't use confirm dialog in admin homepage form
In this case the confirmation dialog isn't really necessary since the
action to enable/disable the setting can easily be undone.

Furthermore, these tests were failing with Chrome 83, probably because
we use `confirm_dialog` and then we use `visit` without checking the
page in between.

In theory we shouldn't need to check the page in between because the
request generated by `confirm_dialog` is a synchronous one and so
`visit` isn't executed after the previous request has finished, but
apparently this behavior has changed in Chrome 83.

We could add an expectation before executing the `visit` method, but
that wouldn't improve the usability of the application.
2020-05-25 19:28:16 +02:00
Javier Martín
095abbf9a7 Merge pull request #4012 from consul/webdrivers
Simplify chromedriver installation with webdrivers
2020-05-25 19:27:29 +02:00
Javi Martín
2c4acb0bf7 Use chromedriver 2.38
The latest stable version is causing problems on some machines, hanging
forever in tests involving frames. So we're installing an old version
which works with the latest Chrome.

Note this means we're using an unsupported version. Officially, only the
latest chromedriver supports the latest Chrome.

We're using 2.38 instead of a more recent one (like 2.40) because it's
the one we specified in our Dockerfile.

See also:
https://bugs.chromium.org/p/chromedriver/issues/detail?id=3361
2020-05-25 15:50:36 +02:00
Javi Martín
59b625a5f9 Simplify chromedriver installation with webdrivers
This gem will automatically install chromedriver based on the installed
version of Chrome/Chromium.
2020-05-25 15:50:35 +02:00
Javi Martín
e4346261ce Use a memory cache store in development
In commit 574133a5 we configured the development to use Dalli to cache
pages. However, cache is usually disabled in the development
environment.

When we upgraded to Rails 5 in commit eb36b7e2, we configured the
development environment to enable caching (using a memory store) when a
certain file is present, and to disable it when it's not. This
configuration makes more sense IMHO, and it was being overwritten by the
one previously mentioned.

After this change, using memcached is no longer required in the
development environment and the `DalliError: No server available` error
message is gone.
2020-05-19 19:05:03 +02:00
Javier Martín
876f209729 Merge pull request #3768 from consul/errors_count
Don't count errors for the same field twice
2020-05-18 18:42:40 +02:00
Javi Martín
1e883af9cd Don't count errors for the same field twice
The number of errors in a form includes several errors for the same
field. For example, if a title is mandatory and has to have at least 5
characters, leaving the title blank will result in two errors. So users
will be invited to look for two errors, but they'll only find one field
with errors.

So it's a bit more intuitive to show as many errors as fields having
errors.

Note we're excluding errors on `:base`, which is a bit of a hack for
errors in association fields. For example, if the title of one
translation is not present, `resource.errors.messages` will contain two
elements: one for the translation's title, and one for the `base` field.
This resulted in the count of errors being 2 when there was only one.

Also note I haven't found a way to count errors on all `has_many`
relations. That is, if two translations have a missing title field, only
one error will be mentioned in the message (as it did before this
commit).
2020-05-18 17:57:06 +02:00
Javier Martín
1f2bdce837 Merge pull request #4010 from consul/fix_nested_documentable_spec
Fix flaky nested documentable / imageable specs
2020-05-18 13:59:40 +02:00
Javier Martín
d9d18f0d15 Merge pull request #3995 from rockandror/fix_map_zoom_js_error
Do not update form location fields when marker is not defined
2020-05-14 19:36:26 +02:00
Javi Martín
f5c8d5eea6 Submit the form after the image is attached
We were submitting the form without checking the AJAX request to attach
the image had finished, so sometimes two requests were executed at the
same time. Sometimes this made InvisibleCaptcha to go crazy and report
the form was submitted too quickly.

Checking the first AJAX request has finished before submitting the form
solves the problem.
2020-05-14 00:12:14 +02:00
Javi Martín
dddd5dd808 Check the DOM after attaching file has succeeded
We were checking `expect_document_has_title(0, "My Title")`, which was
already true before the AJAX request generated by `attach_file` had
finished.

That meant the AJAX request sometimes was handled after this test had
finished, affecting the following test and causing it to fail because
its cookie was overwritten and so `current_user` was set to `nil`.

In the test checking the filename is present, a similar scenario was
taking place: we were updating the `.file-name` element in the `change`
event of `fileupload` (using `App.Documentable.setFilename`); that is,
when the AJAX request started. And so the test passed before the request
was finished, causing the same issue.
2020-05-13 18:55:45 +02:00
Javier Martín
8c9264f24e Merge pull request #3992 from consul/remote_translations_runtime
Check remote translations locales at runtime
2020-05-13 18:04:51 +02:00
Javier Martín
ec78d4c466 Merge pull request #4008 from consul/comments
Simplify code to render comments
2020-05-13 12:38:12 +02:00
Javi Martín
f89bf0c52c Bump initialjs-rails from 0.2.0.5 to 0.2.0.8
Version 0.2.0.5 was causing comments to have invalid HTML because the
avatars had `<img>` tags with an empty `src` attribute.
2020-05-12 23:57:57 +02:00
Javi Martín
ae41becd3a Use CSS to hide reply forms
We were using inline styles and passing local variables around, while
the rule we were following is very simple: it's only hidden if it's a
form to reply to a comment.
2020-05-12 23:57:57 +02:00
Javi Martín
61a63ddd59 Use label text instead of ID to fill in comments
This way tests are easier to read (and easier to write).
2020-05-12 23:57:57 +02:00