Commit Graph

17301 Commits

Author SHA1 Message Date
decabeza
4c0499d53b Manage the render of the price field on budgets results section 2022-03-29 14:49:28 +02:00
decabeza
5d475e6401 Manage the render of the price field on budgets ballot section 2022-03-29 14:49:28 +02:00
decabeza
abc4e9dca1 Manage the render of the price field on public investment section 2022-03-29 14:49:27 +02:00
decabeza
40bdd1f03a Manage the render of the price field on admin investments section 2022-03-29 14:49:27 +02:00
decabeza
2c16bac5f8 Manage the render of the price field on public budget headings 2022-03-29 14:49:26 +02:00
decabeza
9fb5019f0f Manage the render of the price field on admin budget headings
Avoid displaying the price in admin budget headings section
and avoid fill the field 'price' in admin budget headings form
when the budget has been checked with hide_money field.
2022-03-29 14:49:26 +02:00
decabeza
80e64590b7 Allow enable 'hide_money' check on admin budget form
Add new 'hide_money' field to admin budget form.

Only display new field 'hide_money' when voting style is 'approval'
2022-03-29 14:49:25 +02:00
Javi Martín
f4887089bd Merge pull request #4791 from consul/label_with_interpolation
Fix crash on attributes with interpolation arguments
2022-03-28 19:09:09 +02:00
Javi Martín
1fa05b1f54 Fix crash on attributes with interpolation arguments
The application crashed when we generated hints to attributes with
interpolation arguments in their `human_attribute_name`.

When generating the hint, we used the `custom_label` method to generate
a label and get the `for` attribute and, since we weren't passing a
text, it used the default human attribute name for the field. However,
it crashes if the default attribute name requires an interpolation
argument.

So now, since we were only using the `custom_label` method in order to
get the `for` attribute, we're simply passing an arbitrary text to the
method.
2022-03-28 14:55:42 +02:00
taitus
d719b2291e Do not generate an empty hint element when there's an empty hint 2022-03-28 14:55:42 +02:00
Javi Martín
ab0572f32a Merge pull request #4792 from consul/fix_skip_validation_test
Avoid model inheritance in skip validation test
2022-03-26 19:09:03 +01:00
Javi Martín
df2b3f2ee7 Avoid model inheritance in skip validation test
One of these tests was failing sometimes on Github Actions. It looked
like the line `custom_banner.save!` was using the validations from the
Banner class sometimes, even if the callbacks had correctly been
removed in the DummyBanner class.

Se we're inheriting from ApplicationRecord instead of inheriting from
Banner. Since I couldn't reproduce the issue locally after running the
test hundreds of times and with the same seed and tests that were
running on Github Actions, there's a change this won't work. I've tested
a few times on Github Actions and it seems to be working, but we'll have
to keep an eye on it.
2022-03-25 20:25:34 +01:00
Javi Martín
4102a4ad6c Merge pull request #4790 from consul/custom_validations
Make it easier to customize validations
2022-03-24 19:49:40 +01:00
Javi Martín
b5a4609b56 Make it easier to customize validations
There are CONSUL installations where the validations CONSUL offers by
default don't make sense because they're using a different business
logic. Removing these validations in a custom model was hard, and that's
why in many cases modifying the original CONSUL models was an easier
solution.

Since modifying the original CONSUL models makes the code harder to
maintain, we're now providing a way to easily skip validations in a
custom model. For example, in order to skip the price presence
validation in the Budget::Heading model, we could write a model in
`app/models/custom/budget/heading.rb`:

```
require_dependency Rails.root.join("app", "models", "budget", "heading").to_s

class Budget::Heading
  skip_validation :price, :presence
end
```

In order to skip validation on translatable attributes (defined with
`validates_translation`), we have to use the
`skip_translation_validation` method; for example, to skip the proposal
title presence validation:

```
require_dependency Rails.root.join("app", "models", "proposal").to_s

class Proposal
  skip_translation_validation :title, :presence
end

```

Co-Authored-By: taitus <sebastia.roig@gmail.com>
2022-03-24 17:05:35 +01:00
Javi Martín
12460c2000 Merge pull request #4789 from consul/rails_6.0_compatibility
Add Rails 6.0 compatibility
2022-03-23 14:14:11 +01:00
Javi Martín
f6c4d70d78 Merge pull request #4775 from jorgebg/call_verify_ballots_after_create
Add offline ballot sheet votes to the total vote count
2022-03-22 19:17:36 +01:00
Sebastia
c861a1c44b Merge pull request #4787 from consul/custom_constants
Make it easier to customise model constants
2022-03-22 17:47:25 +01:00
taitus
ecde8c6439 Add lambda to the validations that use model constants
In this way when we need modify the constants model value in the
model/custom folder, adding lambda it will be possible load the new
values.
2022-03-22 15:52:36 +01:00
Javi Martín
3f84ab0758 Add test case for adding budget poll results
While writing the test, we noticed it didn't work because the labels
weren't correctly generated, so we're fixing them as well.
2022-03-21 21:33:07 +01:00
Javi Martín
dba68c2c04 Fix deprecation warning in Tagging monkey patch
We were getting a warning in Rails 6.0:

DEPRECATION WARNING: Class level methods will no longer inherit scoping
from `public_for_api` in Rails 6.1. To continue using the scoped
relation, pass it into the block directly. To instead access the full
set of models, as Rails 6.1 will, use
`ActsAsTaggableOn::Tag.default_scoped`.
2022-03-21 20:43:50 +01:00
Javi Martín
2e863fdc51 Fix OR condition in public taggings
In SQL, conditions like:

```
tag_id IN (x) AND taggable_type='Debate' OR taggable_type='Proposal'
```

Don't work as intended; we need to write:

```
tag_id IN (x) AND (taggable_type='Debate' OR taggable_type='Proposal')
```

Due to this bug, we were returning taggings for proposals without
intending to do so.

Since the code was very hard to read, we're also simplifying it.
2022-03-21 20:43:50 +01:00
Javi Martín
effd646e54 Update the way we create form builders in tests
We were getting a warning in Rails 6:

DEPRECATION WARNING: ActionView::Base instances should be constructed
with a lookup context, assignments, and a controller.
2022-03-21 20:43:50 +01:00
Javi Martín
94d4e1db1e Use render template: instead of render file:
We did a similar change in commit 47925fbab, and we were getting a
warning in Rails 6.0:

DEPRECATION WARNING: render file: should be given the absolute path to a
file

Since using `render file:` would ignore views in custom folders, we're
using `render template:` instead.
2022-03-21 20:43:50 +01:00
Javi Martín
9c95735534 Remove invalid key in before_destroy
The `only:` key does not apply to model callbacks. It was added in commit 1077e25b2, probably by accident.

Using this key raises an error in Rails 6.0.
2022-03-21 20:43:50 +01:00
Jorge Barata
b507acb38b Add ballot sheet votes to the total count 2022-03-21 20:33:13 +01:00
Javi Martín
5928f467f3 Merge pull request #4788 from consul/custom_javascript
Make it easier to customize JavaScript functions
2022-03-21 16:37:06 +01:00
Javi Martín
ea026dbe5e Require custom JavaScript after everything else
This way we make sure the custom JavaScript will overwrite anything in
the original code.
2022-03-18 17:20:33 +01:00
Javi Martín
95c1999cca Make it easier to customize JavaScript functions
When there was a custom JavaScript file, we weren't loading the original
one, meaning that, in order to customize it, it was necessary to copy
the whole original file and then changing it.

Now we're loading both the original and the custom file, so the custom
file can simply add more functions or overwrite the ones we'd like to
customize, without copying the whole file.

Existing copies of original files will still overwrite the whole file
and won't be affected.
2022-03-18 16:43:14 +01:00
Javi Martín
9b76a5a19e Merge pull request #4784 from consul/bump_active_storage_to_5.2.6.3
Bump rails from 5.2.6 to 5.2.7
2022-03-16 20:52:30 +01:00
Javi Martín
7ce263efd6 Bump rails from 5.2.6 to 5.2.7
This version solves a security issue in Active Storage; we're including
it even if most probably no CONSUL applications are affected:

https://discuss.rubyonrails.org/t/cve-2022-21831-possible-code-injection-vulnerability-in-rails-active-storage/80199
2022-03-16 20:34:13 +01:00
Javi Martín
8c7091612e Merge pull request #4783 from consul/dependabot/bundler/view_component-2.49.1
Bump view_component from 2.37.0 to 2.49.1
2022-03-04 13:10:34 +01:00
Javi Martín
15d9b88978 Use with_request_url with query params in specs
Support for query params in component specs was added in ViewComponent
2.41.0.
2022-03-04 12:54:47 +01:00
dependabot[bot]
dc0c5c1da0 Bump view_component from 2.37.0 to 2.49.1
Note we don't require the "view_component/engine" in the Gemfile
anymore, since it's been deprecated since ViewComponent 2.46.0.

Bumps [view_component](https://github.com/github/view_component) from 2.37.0 to 2.49.1.
- [Release notes](https://github.com/github/view_component/releases)
- [Changelog](https://github.com/github/view_component/blob/main/docs/CHANGELOG.md)
- [Commits](https://github.com/github/view_component/compare/v2.37.0...v2.49.1)

---
updated-dependencies:
- dependency-name: view_component
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-04 12:53:58 +01:00
Javi Martín
999ae6fb16 Merge pull request #4782 from trendspotter/sdg_cs
Add cs icon of SDGs
2022-03-01 23:00:29 +01:00
Javi Martín
2147a82ae7 Merge pull request #4781 from consul/dependabot/bundler/nokogiri-1.13.3
Bump nokogiri from 1.12.5 to 1.13.3
2022-02-28 13:21:39 +01:00
dependabot[bot]
2d93c928d9 Bump nokogiri from 1.12.5 to 1.13.3
Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.12.5 to 1.13.3.
- [Release notes](https://github.com/sparklemotion/nokogiri/releases)
- [Changelog](https://github.com/sparklemotion/nokogiri/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sparklemotion/nokogiri/compare/v1.12.5...v1.13.3)

---
updated-dependencies:
- dependency-name: nokogiri
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-28 12:58:11 +01:00
decabeza
c98e8a004f Add new 'hide_money' column to the budgets' table
We will use this field to show/hide all price references in the Budgets
with the final voting style: Approval.
2022-02-25 16:22:52 +01:00
Javi Martín
193b61af02 Merge pull request #4600 from consul/active_storage
Remove Paperclip and use just Active Storage
2022-02-24 16:32:18 +01:00
trendspotter
1cd80ce1ab Add cs icon of SDGs 2022-02-23 21:19:01 +01:00
Javi Martín
8eea6f585a Remove hack to allow IO files in Active Storage
We were using this hack in order to allow `File.new` attachments in
tests files. However, we can use the `fixture_file_upload` helper
instead.

Just like it happened with `file_fixture`, this helper method doesn't
work in fixtures, so in this case we're using `Rack::Test::UploadedFile`
instead.
2022-02-23 19:00:33 +01:00
Javi Martín
4f232c3a25 Use the file_fixture helper in tests
This way we don't have to write `"spec/fixtures/files"` every time.

Note this method isn't included in factories. We could include it like
so:

```
FactoryBot::SyntaxRunner.class_eval do
  include ActiveSupport::Testing::FileFixtures
  self.file_fixture_path = RSpec.configuration.file_fixture_path
end
```

However, I'm not sure about the possible side effects, and since we only
use attachments in a few factories, there isn't much gain in applying
the monkey-patch.
2022-02-23 18:43:48 +01:00
Javi Martín
5ff66f96cd Use file_validators to validate attachments
We were using custom rules because of some issues with Paperclip. These
rules work fine, but since we're already using the file_validators gem,
we might as well simplify the code a little bit.
2022-02-23 18:43:48 +01:00
Javi Martín
7212657c02 Remove Paperclip and use just Active Storage 2022-02-23 18:43:48 +01:00
Javi Martín
ca7f2bc9d5 Fix deleted file case in CKEditor
We were getting an error when browsing the server if one file had been
deleted.
2022-02-23 18:21:38 +01:00
Javi Martín
8c82ff290b Handle CKEditor attachments with Active Storage
The code is based on what's generated using CKEditor's code generator.

We're doing one minor change to the `Ckeditor::Backend::ActiveStorage`
module; we're assigning the data in a `before_validation` instead of a
`before_save` callback. Validations with `file_validations` didn't work
otherwise; it looks like this backend was written with
`active_storage_validations` in mind [1].

Note we don't need to update the `name` column in the attachments table
because, when using Active Storage, CKEditor uses both `data` (as
attribute accessor) and `storage_data` (as attachment attribute).

[1] https://github.com/galetahub/ckeditor/blob/f9e48420ccb6dc/lib/generators/ckeditor/templates/active_record/active_storage/ckeditor/picture.rb#L4
2022-02-23 18:21:38 +01:00
Javi Martín
600f5c35e9 Use file_validators instead of Papeclip validations
Since we're going to remove Paperclip and Active Storage doesn't provide
any validations, we have to either write our own validation rules or use
a different gem.

We're using the file_validators gem instead of the
`active_storage_validations` gem because the latter doesn't support
proc/lambda objects in size and content type definitions. We need to use
them because in our case these values depend on settings stored in the
database.
2022-02-23 18:21:38 +01:00
Javi Martín
7daf75d01a Use Active Storage to validate custom image size
The same way we're handling images.
2022-02-23 18:21:38 +01:00
Javi Martín
8e6df7f5d9 Use Active Storage to render custom images
Just like we did with regular attachments, we're moving the logic to
generate URLs out of the model.

Note we're changing the `image_path_for` helper method in order to
return a `polymorphic_path` because sometimes it's used in combination
with `favicon_link_tag`, and `favicon_link_tag` doesn't automatically
generate a polymorphic URL when given an `ActiveStorage::Attachment`
record.
2022-02-23 18:21:38 +01:00
Javi Martín
e0e35298d5 Use Active Storage to handle cached attachments
This fixes a few issues we've had for years.

First, when attaching an image and then sending a form with validation
errors, the image preview would not be rendered when the form was
displayed once again. Now it's rendered as expected.

Second, when attaching an image, removing it, and attaching a new
one, browsers were displaying the image preview of the first one. That's
because Paperclip generated the same URL from both files (as they both
had the same hash data and prefix). Browsers usually cache images and
render the cached image when getting the same URL.

Since now we're storing each image in a different Blob, the images have
different URLs and so the preview of the second one is correctly
displayed.

Finally, when users downloaded a document, they were getting files with
a very long hexadecimal hash as filename. Now they get the original
filename.
2022-02-23 18:21:38 +01:00
Javi Martín
091abfc944 Use Active Storage to render attachments
This way we fix a bug we mentioned in commit 930bb753c which caused
links to documents to be broken when editing their title because the
title was used to generate the URL of the document.

Note we're still using Paperclip to render cached attachments because
this is the only case where we store files with just Paperclip and not
Active Storage.

With Active Storage, we render attachments just like any other resource,
using `polymorphic_path`. Paperclip included the `url` method in the
model; since the model doesn't have access to the request parameters
(like the host), this was inconvenient because it wasn't possible to
generate absolute URLs with Paperclip.

In order to simplify the code and make it similar to the way we used
Paperclip, we're adding a `variant` method accepting the name of a
variant and returning the variant.
2022-02-23 18:21:38 +01:00