Commit Graph

29 Commits

Author SHA1 Message Date
Javi Martín
711e6c16eb Load annotations through the draft version
We were ignoring the draft version param when loading an annotation,
which could result in a strange situation where we load an annotation
and a draft version different than the one it belongs to.

Thanks to this change, we can simplify the code a little bit. IMHO the
`comments` and `new_comment` routes should have been added on member
instead of on collection, which would further simplify the code. I'm
leaving the routes untouched just in case changing the URL has side
effects on existing installations.
2022-08-19 17:40:50 +02:00
Javi Martín
11832cc07d Make it easier to customize allowed parameters
When customizing CONSUL, one of the most common actions is adding a new
field to a form.

This requires modifying the permitted/allowed parameters. However, in
most cases, the method returning these parameters returned an instance
of `ActionController::Parameters`, so adding more parameters to it
wasn't easy.

So customizing the code required copying the method returning those
parameters and adding the new ones. For example:

```
def something_params
  params.require(:something).permit(
    :one_consul_attribute,
    :another_consul_attribute,
    :my_custom_attribute
  )
end
```

This meant that, if the `something_params` method changed in CONSUL, the
customization of this method had to be updated as well.

So we're extracting the logic returning the parameters to a method which
returns an array. Now this code can be customized without copying the
original method:

```
alias_method :consul_allowed_params, :allowed_params

def allowed_params
  consul_allowed_params + [:my_custom_attribute]
end
```
2022-04-07 19:35:40 +02:00
Javi Martín
41a9d17c76 Add and apply Lint/SymbolConversion rubocop rule
This rule was added in Rubocop 1.9.0.

We're excluding the Setting model in order to keep the settings
consistent.
2021-09-03 11:49:53 +02:00
Javi Martín
16c16e3cdf Mark safe SQL with Arel.sql
Rails 5.2 is raising a warning in some places:

DEPRECATION WARNING: Dangerous query method (method whose arguments are
used as raw SQL) called with non-attribute argument(s). 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().

IMHO this warning is simply wrong, since we're using known PostgreSQL
functions like LOWER() or RANDOM(). AFAIK this code works without warnings
in Rails 6.0 [1][2]

However, since the warning is annoying, we need to take measures so our
logs are clean.

[1] https://github.com/rails/rails/commit/6c82b6c99d
[2] https://github.com/rails/rails/commit/64d8c54e16
2020-10-15 14:57:42 +02:00
Javi Martín
ea2aeab383 Apply rubocop Rails/FindBy rule everywhere
We didn't detect these cases because by default the rule only searches
for offenses in `app/models/`.
2019-11-08 19:15:04 +01:00
Javi Martín
db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00
Javi Martín
35bbd87093 Fix adding blank comments to existing annotations
We were using the `present?` method, which will always return true for a
comment object.
2019-10-23 04:28:08 +02:00
Javi Martín
dbcc5fb724 Use AR relations when merging comments
Using arrays made it difficult to order by more than one field (like the
`most_voted` scope does), and so we were ordering by `confidence_score`
and ignoring the `created_at` column.

Using an AR relation makes it easy to reuse the existing `most_voted`
scope.

This change has one side effect: now comments with equal votes are
ordered in descending order instead of having no specific order. That
means flaky specs which failed sometimes because they assumed comments
were ordered by date are now always green.

I've also re-added the `oldest` scope removed in 792b15b thinking it was
removed because using it with arrays was too hard.
2019-05-29 20:50:53 +02:00
Angel Perez
26b213c186 Use Legislation::BaseController on instead of ApplicationController 2019-04-17 17:40:56 +02:00
Julian Herrero
d24376f6ad Use double quotes in controllers/ 2019-03-13 22:19:49 +01:00
Bertocq
22822aa173 Fix Style/RedundantParentheses rubocop issues 2017-09-25 22:44:58 +02:00
Bertocq
69f4e1c683 Fix all rubocop Metrics/LineLength issues (140+) 2017-07-10 13:22:49 +02:00
Bertocq
25e501c668 Fix Style/AndOr rubocop issue and remove from rubocop_todo list 2017-06-19 10:45:18 +02:00
Bertocq
21c6d1c4dd Cleanup Lint/AssignmentInCondition rubocop issues on code and remove it from ruboco_todo list 2017-06-19 10:45:18 +02:00
Bertocq
523988a291 Replace old open_phase? method for new phase/publication open? on Legislative Process 2017-06-13 22:04:36 +02:00
rgarcia
792b15b224 Merges annotations 2017-06-07 14:58:34 +02:00
Amaia Castro
854d51dd8e Calculate annotations weight and add weight css classes for color intensity 2017-03-02 14:25:23 +01:00
Amaia Castro
c7eaadb4b2 Show comment boxes for all annotations at the clicked point 2017-02-24 15:45:36 +01:00
Amaia Castro
20bfe5e0e5 Fix annotation highlight on click 2017-02-23 16:04:55 +01:00
Amaia Castro
53d13d8524 Create a new comment instead of a new annotation with the same ranges 2017-01-25 16:04:10 +01:00
Amaia Castro
1af047089f Add form to publish a new first level comment from the comments box 2017-01-19 15:42:50 +01:00
Fernando Blat
f1be212eeb Fix and complete controller specs 2017-01-14 16:56:55 +01:00
Fernando Blat
f47cef5a93 Highlight text when creating a comment 2017-01-14 16:43:26 +01:00
Fernando Blat
4431d95d31 Basic annotation creation 2017-01-14 16:42:12 +01:00
Amaia Castro
49e66a431c Check phase dates and that draft version is not final before creating annotations 2017-01-13 19:11:05 +01:00
Amaia Castro
a56898fed7 Fix version chooser for annotations page 2017-01-11 23:11:11 +01:00
Amaia Castro
4f539b374f View comments for draft text 2017-01-10 17:25:02 +01:00
Amaia Castro
b8f034d896 Legislation annotations/comments page 2017-01-09 09:29:15 +01:00
Amaia Castro
ee9fa3db15 Base Legislation Annotations 2017-01-04 12:56:58 +01:00