Commit Graph

554 Commits

Author SHA1 Message Date
Javi Martín
2c76f265f8 Add and apply Style/NegatedIfElseCondition rule
This rule was added in Rubocop 1.2.0, and will make developers who hate
negative conditions particularly happy.
2021-09-03 11:49:53 +02:00
Javi Martín
102cf74b3d Bump faker from 1.8.7 to 2.0
Since version 2.0 introduced many breaking changes, we're upgrading to
it first.

The changes have been done by installing the rubocop-faker gem and
running:

```
rubocop \
  --require rubocop-faker \
  --only Faker/DeprecatedArguments \
  --auto-correct
```
2021-08-13 04:39:44 +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
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
dafe6038ec Merge pull request #4509 from consul/remove-skip-map
Remove skip map checkbox
2021-06-04 17:54:04 +02:00
Javi Martín
d06031c427 Don't run release 1.3.0 tasks anymore
People who have already upgraded to version 1.3.0 don't need to execute
them again.

We're not deleting the tasks yet in case some people would like to
upgrade from version 1.2.0 to version 1.3.1. In this case, they'll have
to execute the tasks manually.
2021-06-03 17:24:46 +02:00
Melvin Lammerts
c34aa54122 Remove skip map checkbox 2021-06-03 11:13:52 +02:00
Javi Martín
7024f1edf5 Extract class to find assets
So its methods can be used in other places.
2021-05-29 14:34:46 +02:00
Julian Herrero
909071c48b Allow editing the name of budget phases
Co-authored-by: decabeza <alberto@decabeza.es>
2021-03-11 19:37:58 +01:00
decabeza
c0c458bb38 Remove summary in phases form
Since it does not appear in the phases anymore.

Also, the rake unifies the fields of the budget summary with the budget
description.
2021-03-11 19:37:58 +01:00
Julian Herrero
77aaa5e973 Add task to set published on existing budgets
Note we're making the validation rule dynamic so it's affected by the
way we stub the constant in the tests to emulate data created in old
applications.

Co-Authored-By: Javi Martín <javim@elretirao.net>
2021-02-23 17:05:24 +01:00
Javi Martín
5a42d65d5f Make it possible to add banners to the SDG section 2021-01-20 17:22:08 +01:00
Javi Martín
948a8b2904 Add search method to legislation processes
This way we'll be able to search processes in the SDG Management
section.
2020-12-21 18:04:48 +01:00
Javi Martín
852014e478 Add search method to polls
So far the method does not take questions nor answers into account.

This way we'll be able to search polls in the SDG Management section.
2020-12-21 18:04:48 +01:00
Senén Rodero Rodríguez
c7c8309ad1 Add rake task to load sdg
This task should be useful for existing installations that are going
to upgrade the app and want to load SDG data into an already
existing database.
2020-12-02 12:38:03 +01:00
Senén Rodero Rodríguez
265f8dbf01 Connect to the service only when remote census endpoint is defined
Also return an invalid response when the endpoint is not defined.

This will allow to test remote web services on development environments.
2020-11-02 11:42:39 +01:00
Senén Rodero Rodríguez
ac6260a2ef Mock remote census responses in tests using XML
By using real XML responses developers will be able to understand better
how the integration works (the data flow), and the correspondency between
`remote_census` settings and their place at a real XML response.

As `stubbed_responses` methods were removed from the model layer now the
stubbing part should be managed from the test environment code so also
added a new helper module `RemoteCensusSetup` that can be used anywhere
where we need to call the web service.

Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-11-02 11:42:39 +01:00
Senén Rodero Rodríguez
dd0f56f85f Use shorter responses and configuration for specs
By simplyfing the responses the configuration for specs can be simpler too.

We're also using more generic terms instead of the ones used in Madrid's
Census API.

Co-Authored-By: Javi Martín <javim@elretirao.net>
2020-11-02 11:42:39 +01:00
Senén Rodero Rodríguez
3ed4bdaff8 Return no variants when document_number is blank
Otherwise the variants returned for document_type="1" and
document_number="" will be

`["0", "00", "000", "0000", "00000", "000000", "0000000", "00000000"]`

which seems to be useless.
2020-11-02 11:42:39 +01:00
Senén Rodero Rodríguez
93e458d46e Return invalid response when document_type or document_number are empty
Probably this case is not real for production environments where those
arguments will always be fullfilled but seems to be interesting for
testing environment where this method is being called when those
paremeters where empty.
2020-11-02 11:42:39 +01:00
Javi Martín
cd418e45be Allow hints on select fields
Just like we allow them on input fields.
2020-09-09 12:20:46 +02:00
Javi Martín
fc9a87a8ab Use native HTML5 date fields in the admin section
We've had to add a couple of hacks in order to make jQuery UI datepicker
work with Turbolinks, and one of our tests is failing because the
datepicker changes its height when changing from a month with 5 weeks to
a month with 6 weeks.

We could add a workaround so the test still passes (jQuery UI doesn't
provide a configuration option to always displays 6 weeks in the
datepicker), but I think it's easier to just use the HTML5 native date
input field, which also allows us to simplify the code a bit and IMHO it
improves the user experience, particularly when using mobile phones.

Since date fields are not supported in Safari and Internet Explorer,
we're still using the jQuery UI datepicker on those browsers (and on any
other browser not supporting date fields).

Due to these changes, we're moving the tests checking datepicker's
behaviour to the dashboard. I've choosing not to change the public pages
because I'm not 100% sure everybody would like this change (some people
prefer the datepicker because we can configure the way it looks).
2020-08-28 12:55:58 +02:00
Javi Martín
c5f4cd6229 Fix invalid "hint" attribute in forms
Using `hint: false` was generating an input with `hint="false"` instead
of generating no hint at all.
2020-08-22 23:00:14 +02:00
Javi Martín
f49745d7ba Simplify passing the object in the form builder
The object is already a method, so we don't need to pass it around.
2020-08-22 23:00:14 +02:00
Julian Herrero
151aa6009d Allow links and images on legislation drafts
Note we're using a new sanitizer. Ideally we'd reuse the
`AdminWYSIWYGSanitizer`, but then code that would be correctly shown by
markdown-it (like the <h1> tag) wouldn't be shown on the web, which is
confusing. Ideally we would configure markdown-it to only allow the tags
present in the `AdminWYSIWYGSanitizer` and provide some kind of help
showing which tags are allowed.
2020-08-10 12:20:59 +02:00
Javi Martín
1b34c061bb Use where.not instead of where(NOT IN)
This way we simplify the code a bit and reduce our usage of raw SQL.
2020-07-14 12:32:12 +02:00
Javi Martín
f6351819fa Simplify SQL using DISTINCT
Using `pluck("DISTINCT")` was raising a warning in Rails 5.2:

DEPRECATION WARNING: Dangerous query method (method whose arguments are
used as raw SQL) called with non-attribute argument(s): "DISTINCT
taggings.tag_id". Non-attribute arguments will be disallowed in Rails
6.0. This method should not be called with user-provided values, such as
request parameters or model attributes. Known-safe values can be passed
by wrapping them in Arel.sql().

Since there was only one other use of distinct, I've decided to change
both of them in the same commit, even if the second one wasn't raising a
warning.
2020-07-08 18:34:58 +02:00
Javi Martín
6fd9a286d7 Don't access the database in after_initialize
Rails 5.2 crashes in the `db:create` task because it tries to run the
`after_initialize` block before the database is created.

The easiest way to solve it is to move the code out of the initializer
and calculate the API type definitions on demand. Note results are still
cached using a class instance variable (not to be confused with a class
variable), and so once definitions are obtained, they will remain
constant until the application is restarted, even in the development
environment.
2020-07-08 18:34:58 +02:00
Javi Martín
9837b1ab74 Remove tasks to upgrade to version 1.1
These tasks are not needed for new installations, and in existing
installations they've already been executed when upgrading to version
1.1.

One of them also raises a warning in Rails 5.2:

DEPRECATION WARNING: Dangerous query method (method whose arguments are
used as raw SQL) called with non-attribute argument(s): "MIN(id) as id".
Non-attribute arguments will be disallowed in Rails 6.0. This method
should not be called with user-provided values, such as request
parameters or model attributes. Known-safe values can be passed by
wrapping them in Arel.sql()
2020-07-08 18:34:58 +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
Paweł Świątkowski
d99875cde2 Get search dictionary based on I18n.default_locale (merge pull request #3856)
Implementation tries to be open for further extensions, such as deciding on
search dictionary based on configuration option or by locale set for
given user.
2020-04-12 14:22:36 +02:00
Javier Martín
14b1f1b4d3 Merge pull request #3911 from rockandror/dashboard-email
Improve Dashboard emails
2020-02-19 19:06:53 +01:00
taitus
4bb194e1cc Recover rake "settings:rename_setting_keys"
We need to add :rename_setting_keys before :add_new_settings task.
This way the value of the old key will not be lost.
2020-02-19 16:14:44 +01:00
Julian Herrero
193e51d42f Enable Wordpress Oauth login and registration 2020-02-07 12:23:41 +07:00
Javier Martín
3bbd63e549 Merge pull request #3871 from consul/smtp_symbols
Use symbols instead of strings for SMTP settings
2019-12-11 18:33:55 +01:00
taitus
d1c9df5f91 Sanitize resource fields values
Sanitize resource fields values from ddbb before send
to remote translate client.
2019-12-04 17:03:57 +01:00
Javi Martín
1910115469 Use symbols instead of strings for SMTP settings
ActionMailer does differenciate between symbols and strings, and the
code stringifying keys comes from an early version which we forgot to
remove.
2019-12-01 20:30:45 +01:00
Javi Martín
a08d42d3f8 Enable/disable delayed jobs in the secrets file
While this is not a secret and in theory should be in a file under
version control, currently the CONSUL installer disables delayed jobs by
default, meaning we were keeping two versions of the delayed jobs
configuration file, and some existing configurations have their settings
defined in a file in capistrano's `shared` folder.

So we're moving existing settings to the secrets file.
2019-11-12 14:58:35 +01:00
Julian Herrero
d6130cf6e2 Add task to move force_ssl settings to secrets.yml
Existing installations having their configuration settings in the
capistrano shared folder needed this migration.
2019-11-12 14:58:05 +01:00
Javi Martín
03c4275525 Add task to move SMTP settings to secrets.yml
Existing installations having their configuration settings in the
capistrano shared folder needed this migration.

Note we can't just use `YAML.load` because we'd lose the anchors defined
in the file. So we have to parse the file the hard way.
2019-11-12 14:47:27 +01:00
Javi Martín
01a01c834d Only generate stats if we can access them
There's no point generating stats nobody can access.

Note with this change we're automatically excluding polls created in the
dashboard, since these polls don't have stats enabled.
2019-11-09 19:34:24 +01:00
Javi Martín
a1b89094be Don't add log info messages when running tests
We use these messages in rake tasks, but when we run the test suite they
only add noise.
2019-11-08 18:06:18 +01:00
Senén Rodero Rodríguez
be886ba77a Add rake task to remove duplicated local census records
Also supress migration messages during spec execution to keep test log as clean
as possible.
2019-11-08 14:46:45 +01:00
Javi Martín
9b511edd5b Write task to migrate budget admins and valuators
If we didn't run this task, investments for existing budgets wouldn't
show their administrator/valuators as an option when we're editing them,
leading to data loss.
2019-11-01 17:12:42 +01:00
Javi Martín
b8fbd6347b Use acts_as_taggable for investment valuation tags
We were manually doing the same thing, generating inconsistent results,
since the method `valuation_tag_list` was using the `valuation` context,
when actually the expected behavior would be to use the `valuation_tag`
context.
2019-11-01 17:12:31 +01:00
Mohsin Khan
9fd79cefd4 Don't send newsletters to unconfirmed accounts (Merge #3781) 2019-10-30 21:15:05 +01:00
Javi Martín
a727dcc031 Apply Style/SymbolProc rubocop rule
This style is much more concise.
2019-10-26 20:10:32 +02:00
Javi Martín
8b5cca746c Apply rubocop rules to freeze constants
Added by popular demand among our team members.
2019-10-26 13:21:36 +02:00
Javi Martín
b5eeb3f32f Apply Style/HashSyntax rubocop rule
We were already using it almost everywhere.
2019-10-26 13:03:49 +02:00
Javi Martín
eafb4018bf Apply Style/CollectionMethods rubocop rule
We were already using `map` and `reduce` almost everywhere.
2019-10-26 13:03:49 +02:00