Commit Graph

545 Commits

Author SHA1 Message Date
taitus
7e779bf68b Remove eval from remote_census_api
The use of eval is a serious security risk, so we change by JSON.parse method
2019-10-21 16:52:20 +02:00
Senén Rodero Rodríguez
a733bc7b2e Avoid calls to remote census api (legacy) when endpoint is not defined
Also keep the same behavior for test and development environments.
2019-10-21 14:30:03 +02:00
Javi Martín
b36e659f4e Use puma instead of unicorn
Puma is the server we use in the development environment, so this way we
don't need to maintain two servers. Furthermore, puma seems to offer a
few advantages over unicorn (like multithreading) and no disadvantages.
2019-10-12 16:50:49 +02:00
Javi Martín
94a7e13dce Update capistrano's restart unicorn task
Our current unicorn task wasn't working in some cases. We also had a
version in the `capistrano` branch, which was the one we recommended.
However, that version assumed RVM, a certain ruby version and a certain
deploy folder were used. This version uses `bundle exec` and variables
like `release_path`, so it does not depend on any specific
configuration.

Even if we're replacing unicorn with puma, I wanted to make this change
in case we need it as a reference in the future.
2019-10-10 21:01:42 +02:00
Javi Martín
9a299aeeb5 Fix checkbox label containing links
The link tags were being stripped out by `content_tag`.
2019-10-09 19:46:47 +02:00
Javi Martín
0a2efb1d80 Use application logger in set_original_heading_id
The pull request adding the original heading was done before we started
using `ApplicationLogger` in rake tasks.
2019-10-08 20:39:26 +02:00
Javi Martín
4fad6f16f6 Make set_original_heading_id task idempotent
This way there'll be no side effects if accidentally executed on data
already having the `original_heading_id`.
2019-10-08 20:30:02 +02:00
Javi Martín
acbad38749 Update execute_release_tasks task
It now contains tasks we've added after version 1.0.0
2019-10-08 20:20:41 +02:00
Javi Martín
7bb39c8e4e Execute add_new_settings on every release
Although it's already executed when deploying with capistrano, heroku
installations don't use capistrano for deployment, so we're also
executing it when upgrading.

This isn't a one-time task, so it makes sense to have it executed on
every release.
2019-10-08 20:19:48 +02:00
Javi Martín
8fb44961e9 Remove tasks to rename/remove deprecated settings
I was thinking of leaving these tasks empty, so in the future we could
use them again if we rename or remove more settings. But since we
haven't renamed nor removed any settings for more than seven months, and
we've only used these tasks once, I'm simply removing the tasks. It's
easy to add them back if we ever need them.
2019-10-08 20:19:48 +02:00
Javi Martín
122b066573 Remove already executed tasks
These tasks were executed when upgading to version 0.19, 1.0.0-beta or
1.0.0.
2019-10-08 20:19:48 +02:00
Javi Martín
75a28fafcb Sanitize label texts automatically
This way we can remove all those `html_safe` calls and we avoid
potential XSS attacks in label texts.
2019-10-08 18:46:21 +02:00
Javi Martín
2aabf79fb4 Rename methods to add auto links to HTML
The name `safe_html_with_links` was confusing and could make you think
it takes care of making the HTML safe. So I've renamed it in a way that
makes it a bit more intuitive that it expects its input to be already
sanitized.

I've changed `text_with_links` as well so now the two method names
complement each other.
2019-10-08 18:46:20 +02:00
Javi Martín
4f1131d2e5 Add labels to radio buttons automatically 2019-10-06 20:06:00 +02:00
Javi Martín
aec84f6522 Generate labels for attribute automatically
I'm not sure why it isn't already done by foundation's form builder. It
doesn't make any sense to change an ID of a form field without changing
the `for` attribute of its label.
2019-10-06 19:32:04 +02:00
Javi Martín
8d9cb4d8e3 Simplify generating checkboxes in forms
Using the block syntax to generate the label with a <span> tag inside
isn't necessary after upgrading foundation_rails_helpers. Before the
upgrade, we couldn't do so because the <span> tag was escaped.
2019-10-06 19:32:04 +02:00
Javi Martín
4f5de5be3b Add aria-describedby attribute automatically
We were manually adding the attribute in many places, but not
everywhere. I'm assuming adding it where we didn't have it is doing no
harm.
2019-10-06 19:32:03 +02:00
Javi Martín
4a19bb6b77 Simplify generating fields with hints
We were already using this code in translatable forms. Using it on every
form means we can reduce the code we need to generate a field with a
hint.
2019-10-06 18:03:38 +02:00
Javi Martín
ae6fab9f5e Inherit from builder instead of monkey patching it
We were monkey-patching FoundationRailsHelper::Formbuilder, which made
form customization difficult. We can inherit from it, which is the
standard way of extending what an existing class does, and make our form
the default one.
2019-10-05 16:01:58 +02:00
Javi Martín
871fa020a5 Add and apply ParenthesesAsGroupedExpression rule 2019-10-05 15:03:26 +02:00
Javi Martín
93a2ebd46f Add and apply DuplicateMethods rubocop rule
These methods were defined with `attr_reader` (or accessor in some
cases) and then they were redefined.
2019-10-05 15:03:26 +02:00
voodoorai2000
71e6c5713a Add rake task to set the original_heading_id value
By default we want this attribute to be the current heading id for existing investments. If there have been reclassifications, this field should be updated accordingly.
2019-09-12 16:49:01 +02:00
Javier Martín
8670cafa2e Merge pull request #3611 from PierreMesure/adding-missing-subtasks-to-upgrade-task
Adding missing subtasks to upgrade task and adding info log
2019-09-11 21:26:45 +02:00
Javi Martín
d639cd587a Remove unnecessary uniq calls
The code `where(id: ids)` is equivalent to `where(id: ids.uniq)`.

Since Rails 5 uses `distinct` instead of `uniq` and in most cases where
we use `uniq` with `pluck` we should simply remove the `uniq` call (as
done in this commit), we're also removing the `Rails/UniqBeforePluck`
rubocop rule.
2019-09-10 22:27:33 +02:00
Javi Martín
a5ba13b599 Apply Rails/Presence rubocop rule 2019-09-10 21:43:38 +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
488461b8ac Remove consecutive blank lines 2019-09-10 20:02:15 +02:00
Javi Martín
47b2c42a1d Apply IndentationConsistency rubocop rule 2019-09-10 20:02:15 +02:00
Javi Martín
e252d82cdb Apply IndentationWidth rubocop rule 2019-09-10 20:02:15 +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
53abc57578 Fix Infinity exceptions in hot score calculator
There was a rare case we've found on some Travis builds where the system
time suddenly moved back to the past a couple of tenths of a second,
meaning `Time.current - resource.created_at` returned a negative number,
which lead to a division by zero.
2019-09-10 16:00:21 +02:00
Javi Martín
852d3b0ed6 Extract methods to calculate hot score period 2019-09-10 16:00:21 +02:00
Javi Martín
a21240b230 Use Date.current and Time.current
Using Date.today and Time.now might lead to inconsistencies if the time
zone the application uses is not the same as the system time zone.
2019-08-28 20:32:40 +02:00
Javi Martín
d981e23cd7 Remove custom dashboard task
It was made for Madrid's repository, but was accidentally added to
CONSUL as well.
2019-08-07 20:37:02 +02:00
taitus
292a1adbbe Boy scout: rename variables with correct order 2019-07-29 13:10:09 +02:00
taitus
090390c09f Boy Scout: Create document parser spec file
Regroup DocumentParser spec. Now they're duplicates in
local_census_specs and census_api_spec.

Move duplicate private method "dni?(document_type) from
LocalCensus and CensusAPI to DocumentParser
2019-07-29 13:10:09 +02:00
taitus
4dfce4f245 RemoteCensusAPI accept :date_of_birth and :postal_code
New RemoteCensusAPI allow receive :date_of_birth and
:postal_code and use in request to endpoint always that have
been configured on remote_census_configuration:
  - Setting["remote_census.request.date_of_birth"]
  - Setting["remote_census.request.postal_code"]

Add new params to CensusCaller 'call' method.
2019-07-29 13:10:09 +02:00
taitus
3f16157418 Create new RemoteCensusAPI
Create a new RemoteCensusAPI with the same functionality as
the old CensusAPI.

In the new RemoteCensusAPI both the request and the
processing of the response are made according to the
parameters defined in the "Remote Census Configuration"
page.

Same as old Census API we only consider document_type and
document_number on API request.

* request(document_type, document_number))

On "Remote Census Configuration" we allow to define request
structure on Setting["remote_census.request.structure"]

The information text of this field on "Remote Census Configuration" is:
> The "static" values of this request should be filled.
> Values related to Document Type, Document Number, Date of Birth and
  Postal Code should be nil value.

An Example with the expected value for this field:
"{ request:
    {
      codigo_institucion: 1,
      codigo_portal: 1,
      codigo_usuario: 1,
      documento: nil,
      tipo_documento: nil,
      codigo_idioma: '102',
      nivel: '3'
    }
  }"
Where 'codigo_institucion', 'codigo_portal', 'codigo_usuario' and
'nivel' are "static" and filled in with their expected static values.
On the other hand 'documento' and 'tipo_documento' are fields
related with 'document_type','document_number' and filled in with
 nil value.

On 'request' method we fill in thats 'nil values' with their
correct argument value. We can fill_in correctly because on
"Remote Census Configuration" we allow to define request path for
'document_type','document_number'

Setting["remote_census.request.document_type"]
Setting["remote_census.request.document_number"]

An Example with the expected values:
Setting["remote_census.request.document_type"] = "request.tipo_documento"
Setting["remote_census.request.document_number"] = "request.documento"

With this information with 'fill_in(structure, path_value, value)'
method, we can update structure with correct argument ('document_type',
'document_number', 'date_of_birth' and 'postal_code') value.

An Example of fill_in(structure, path_value, value) where:
structure = "{ request:
                {
                  codigo_institucion: 1,
                  codigo_portal: 1,
                  codigo_usuario: 1,
                  documento: nil,
                  tipo_documento: nil,
                  codigo_idioma: '102',
                  nivel: '3'
                }
              }"
path_value = "request.documento"
value = "12345678X"

The result expected is:
{ request:
  {
    codigo_institucion: 1,
    codigo_portal: 1,
    codigo_usuario: 1,
    documento: "12345678X",
    tipo_documento: nil,
    codigo_idioma: '102',
    nivel: '3'
  }
}
2019-07-29 13:10:09 +02:00
taitus
dc5c316caf Allow new call to RemoteCensusApi on CensusCaller
When Setting["feature.remote_census"] is active, we allow and
ability the calls to new RemoteCensusAPI througth CensusCaller
2019-07-29 13:10:09 +02:00
taitus
064235d29f Add rake task to create remote census setting 2019-07-29 13:10:09 +02:00
taitus
44da3126d6 Convert AvailableLocales from Module to Class 2019-06-27 09:21:19 +02:00
taitus
3a154a57cb Fix houncibot offenses: Style/StringLiterals 2019-06-27 09:21:19 +02:00
taitus
72d1893703 Manage the remote translation button display
- Add remote_translation_button partial to layout
- Only display button when we have remote_translations and if current
  locale is include on available locales from remote translations service.
- Recover available locales from remote translations service.
  Use daily_cache to detect every day if remote translation service has
  added new available locale.

Co-Authored-By: alessandro <agileontheweb@gmail.com>
2019-06-27 09:21:18 +02:00
taitus
6ad294e71f Fix houncibot offenses. 2019-06-27 09:21:18 +02:00
taitus
1d3dd6f727 Add RemoteTranslationsCaller to new namespace
- Rename to Caller
 - Add to new namespace RemoteTranslations
 - Update references to new namespace
2019-06-27 09:21:18 +02:00
taitus
510307b0bd Add SentencesParser to new namespace
Add to new name space RemoteTranslations::Microsoft
2019-06-27 09:21:18 +02:00
taitus
4c1704a5a3 Add RemoteAvailableLocales to new namespace
Add to new name space RemoteTranslations::Microsoft and rename to
AvailableLocales.
2019-06-27 09:21:18 +02:00
taitus
d29656d78f Add MicrososftTranslateClient to new namespace
- Rename to Client
- Add to new namespace RemoteTranslations::Microsoft
- Update references to new namespace
2019-06-27 09:21:18 +02:00
taitus
d2506358ef Fix found Hound violations 2019-06-27 09:21:18 +02:00
taitus
4272b60339 Create Remote Translations Caller
This module is used in a callback model and in charge of
  - extracting resources associated from RemoteTranslation and preparing
    its fields to be sent to the MicrosoftTranslateClient thought DelayedJobs
  - receive the response from MicrosoftTranslateClient and update resource
    with his translates

Co-authored-by: javierm <elretirao@gmail.com>
2019-06-27 09:21:18 +02:00