Commit Graph

147 Commits

Author SHA1 Message Date
Javi Martín
28aafbd4bc Add and apply Style/InvertibleUnlessCondition rule
This rule was added in rubocop 1.44.0. It's useful to avoid accidental
`unless !condition` clauses.

Note we aren't replacing `unless zero?` with `if nonzero?` because we
never use `nonzero?`; using it sounds like `if !zero?`.

Replacing `unless any?` with `if none?` is only consistent if we also replace
`unless present?` with `if blank?`, so we're also adding this case. For
consistency, we're also replacing `unless blank?` with `if present?`.

We're also simplifying code dealing with `> 0` conditions in order to
make the code (hopefully) easier to understand.

Also for consistency, we're enabling the `Style/InverseMethods` rule,
which follows a similar idea.
2023-09-07 19:14:03 +02:00
Javi Martín
a1439d0790 Apply Layout/LineLength rubocop rule
Note we're excluding a few files:

* Configuration files that weren't generated by us
* Migration files that weren't generated by us
* The Gemfile, since it includes an important comment that must be on
  the same line as the gem declaration
* The Budget::Stats class, since the heading statistics are a mess and
  having shorter lines would require a lot of refactoring
2023-08-30 14:46:35 +02:00
Javi Martín
5b6de96241 Add and apply MultilineMethodCallIndentation rule 2023-08-18 14:56:16 +02:00
Javi Martín
b0b7d0f25b Remove unused legislation proposals map action
The only view that linked to this action was never used and so it was
deleted in commit 0bacd5baf.

Since now the proposals controller is the only one place rendering the
`shared/map` partial, we're moving it to the proposals views.
2023-05-04 15:27:10 +02:00
Javi Martín
6105de307b Rename map_location variable containing parameters
When it was named `map_location`, I constantly thought it was an object
instead of a hash.
2023-04-28 17:16:07 +02:00
Javi Martín
65ed778226 Avoid removing other proposals map locations
It was possible to remove a map location from a different proposal (even
one created by a different author) by modifying the hidden `id`
parameter in the form.

So we're making sure the map location we destroy is the one associated
to the proposal we're updating.

Since we're now using the `@proposal` instance variable in the
`destroy_map_location_association` method, we're calling that method
after loading the resource with cancancan.
2023-04-28 17:11:59 +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
4b42a68b6a Use the vote action to vote featured proposals
The action and the views were almost identical, with the supports
progress and the HTML classes of the success message element being the
only exceptions; we can use CSS for the styles instead.
2022-02-21 18:47:13 +01:00
Javi Martín
b98244afd9 Remove votes query optimizations
Just like we did in commit 0214184b2d for investments, we're removing
some possible optimizations (we don't have any benchmarks proving they
affect performance at all) in order to simplify the code.

The investement votes component `delegate` code was accidentally left
but isn't used since commit 0214184b2, so we're removing it now that
we're removing the `voted_for?` helper method.
2022-02-21 18:47:13 +01:00
Javi Martín
c8d8fae98d Move related list partial to a component
This way the code is easier to follow; the code checking whether the
list has contents is in the partial rendering the list.

We also remove some duplication setting up related content in the
controllers.

For some reason, we have to manually ignore i18n keys which were
automatically ignored when the code was in the view.
2021-08-16 16:30:13 +02:00
Javi Martín
4150d7f1be Move proposals form partial to a component
Since now categories are loaded in both the investment form component
and proposal form component, and their controllers are the only
"commentable" controllers using the `@categories` instance variable, we
can remove the `load_categories` call in `CommentableActions` affecting
the create and update actions.
2021-07-13 15:25:29 +02:00
Melvin Lammerts
c34aa54122 Remove skip map checkbox 2021-06-03 11:13:52 +02:00
taitus
ac144d172d Move document attributes to concern 2021-04-09 16:21:00 +02:00
taitus
c173568404 Move map_location attributes to concern 2021-04-09 16:20:59 +02:00
taitus
7fa594e3e3 Rename sdg_related_list to related_sdg_list
To maintain consistency with the current names in the database with fields:
:related_sdg_type and :related_sdg_id
2021-01-26 19:18:11 +01:00
taitus
95c1f36bdd Add SDG::RelatedListSelectorComponent to Proposals
Allow to relate SDG and Targets to Proposals
2021-01-22 16:05:16 +01:00
anks
9bd012f83c Hide retired proposals from related content proposals (Merge pull request #4196)
Co-authored-by: Anna Anks Nowak <matisnape@users.noreply.github.com>
2020-10-25 14:22:41 +01: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
b483d50d30 Remove unused tag filter
This filter was added in commit 4285ba4b, it was changed in commit
002d8688, and most of the code from the original commit has disappeared
without a trace (maybe due to a merge conflict?).

This filter could actually be useful if we started using it when users
click on a tag. Since we don't, I'm removing it. We might add it back if
we decide to actually use it.
2020-04-08 13:49:48 +02:00
Andy Sims
74fbde09f1 Support creates follow (Merge pull request #3895)
* Supporting a proposal will create a follow relationship
* Only followers receive notifications
2020-04-06 15:26:47 +02:00
Javi Martín
d0d681a44b Add and apply EmptyLineAfterGuardClause rule
We were inconsistent on this one. I consider it particularly useful when
a method starts with a `return` statement.

In other cases, we probably shouldn't have a guard rule in the middle of
a method in any case, but that's a different refactoring.
2019-10-24 17:56:03 +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
Senén Rodero Rodríguez
5dc0f7f054 Add :except and :only options to translatable_params method
Allow to choose among resource model translatable attributes.
2019-06-27 09:19:37 +02:00
Senén Rodero Rodríguez
bd3bb72370 Add proposals translation interface
* Convert proposal form into translatable one.
 * Adapt translatable shared spec to define an owner when running at
   frontend feature specs.
 * Remove old attributes from strong parameters.
2019-06-27 09:19:37 +02:00
Senén Rodero Rodríguez
02be0c61f9 Add proposal translations
Adapt retire form to include needed translations and move validations
from controller to model.

Also change sanitizable concern to sanitize not marked for destruction
translations.
2019-06-27 09:19:36 +02:00
Julian Herrero
d4ec750428 Show archived proposals in selected proposals list 2019-05-30 11:19:38 +02:00
Julian Herrero
a852696eeb Remove not selected proposals from other lists 2019-05-30 11:19:38 +02:00
Julian Herrero
b68a872298 Change links for proposals lists
Changed applied:

- Remove Archived proposals from tab and add a link under Proposals
  lists
- Remove Popular proposals link from custom section and add it to the
  Proposals lists
- Remove Retired proposals link from custom section and add it to the
  Proposals lists
- Remove Selected proposals link from custom section and add it to the
  Proposals lists
2019-05-30 11:19:38 +02:00
Julian Herrero
ad5f7a06e1 Allow admins to select proposals and users to list them 2019-05-30 11:19:33 +02:00
decabeza
0995480b73 Remove question and external_url fields from proposals 2019-04-30 11:35:47 +02:00
decabeza
91be3cf775 Fix more hound warnings 2019-03-27 15:22:14 +01:00
decabeza
eda6ea7f12 Merge branch 'master' into dashboard 2019-03-26 16:45:48 +01:00
Julian Herrero
d24376f6ad Use double quotes in controllers/ 2019-03-13 22:19:49 +01:00
decabeza
25c8212e80 Remove proposal improvement path setting 2019-02-19 11:07:58 +01:00
rogelio-o
f1bb1ff8de Moves attributes to a concern. 2019-01-14 20:26:47 +01:00
rogelio-o
ea76179002 Solves #3153. It refactors images attributes. 2019-01-12 17:42:55 +01:00
decabeza
37da986014 Adds settings for featured proposals 2018-12-04 18:04:36 +01:00
decabeza
609d2083f8 Changes proposals controller to always load featured proposals 2018-12-04 17:46:46 +01:00
Juan Salvador Pérez García
77dd60427d Implements story #136
Adds draft state for proposals
2018-07-17 17:46:54 +02:00
Angel Perez
a143fa447b Ensure recommendations are only shown when enabled 2018-07-15 21:28:58 -04:00
Angel Perez
463c753880 Recommendations are automatically disabled if dismissed by user 2018-07-15 21:28:58 -04:00
Angel Perez
a58f6a2662 Enable 'Recommended proposals' setting for users 2018-07-15 21:28:57 -04:00
decabeza
bdb3f30e40 Adds recommendations on proposals index 2018-07-15 21:28:57 -04:00
iagirre
21b1d00205 Add backend for the moderators
Add new routes for the proposal notifications edition and
abilities to let moderators edit it (mark as ignored, hide, etc.).

The notifications are not flaggable because they doesn't work like that,
but in a similar way. The moderator/administrator is in charge of hidding
them through the UI, so the normal users don't flag it as inappropriate.

New controller Moderation::ProposalNotification to manage the moderators
work.
2018-07-02 18:17:45 +02:00
decabeza
bdedb023d1 Adds view mode on proposals 2018-04-02 17:27:52 +02:00
Angel Perez
665a5b57ab Empty instances of MapLocation won't result in a new DB record (#2220) 2018-01-26 09:26:48 -04:00
rgarcia
19a084c0c7 adds map validations 2017-12-19 20:32:55 +01:00
Raimond Garcia
d0b407d4e5 Merge pull request #2183 from consul/related-content
Related contents functionalities
2017-12-15 10:00:43 +01:00
María Checa
1830a7bb04 Added pagination for relationed content list 2017-12-14 20:54:35 +01:00
Angel Perez
ab9d612128 'Proposals' feature can be enabled/disabled
Fixes #1886
2017-11-17 13:10:55 -04:00