Commit Graph

39 Commits

Author SHA1 Message Date
taitus
29f4edd466 Remove unused scopes from Legislation::Proposal
The "for_render", "sort_by_hot_score" and "sort_by_most_commented"
scopes in Legislation::Proposal are no longer used
anywhere in the code. They were all introduced in commit 335399e571
("Created Legislation Proposals model") and have never been
referenced since.
2025-11-14 13:44:12 +01:00
taitus
93189d3ecd Allow use embedded_video_component in legislation proposals
Since the PR "Do not use third-party cookies in embedded videos #5548", the logic from
"embed_videos_helper" was extracted to the "embedded_video_component" and the
"videoable" model concern.

However, during this refactor, the "regex" method, which uses record.class:: to handle
video embeds, was left inaccessible for Legislation Proposals.

This commit fixes the issue by including the concern in the Legislation Proposal model.
2024-10-14 15:24:29 +02:00
Javi Martín
fb0c087f95 Add and apply Rails/WhereRange rubocop rule
This rule was added in rubocop-rails 2.25.0. Applying it allows us to
simplify the code a little bit. For example, now there's no need to
specify the `proposals` table in proposal scopes, which was actually
causing a bug in the `Legislation::Proposal` model, which was using the
`proposals` table instead of the `legislation_proposals` table (but,
since we don't use this scope, it didn't affect the application).
2024-07-05 17:11:29 +02:00
taitus
fd5fa2da79 Refactoring: Move 'vote' action to Votes Controllers
As far as possible I think the code is clearer if we use CRUD actions
rather than custom actions. This will make it easier to add the action
to remove votes in the next commit.

Note that we are adding this line as we need to validate it that a vote
can be created on a debate by the current user:

```authorize! :create, Vote.new(voter: current_user, votable: @debate)```

We have done it this way and not with the following code as you might
expect, as this way two votes are created instead of one.

```load_and_authorize_resource through: :debate, through_association: :votes_for```

This line tries to load the resource @debate and through the association
"votes_for" it tries to create a new vote associated to that debate.
Therefore a vote is created when trying to authorise the resource and
then another one in the create action, when calling @debate.vote_by (which
is called by @debate.register_vote).
2023-10-09 07:21:49 +02:00
dependabot[bot]
ff04009e4a Bump rubocop from 1.35.1 to 1.56.2
Among many things, this version includes updates in the
`Layout/ExtraSpacing`, `Layout/SpaceAroundOperators` and
`Style/RedundantReturn` rules, which means we need to update the code in
some places in order to follow these rules.

Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.35.1 to 1.56.2.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.35.1...v1.56.2)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-07 13:09:11 +02:00
Javi Martín
8b13daad95 Add and apply rules for multi-line hashes
For the HashAlignment rule, we're using the default `key` style (keys
are aligned and values aren't) instead of the `table` style (both keys
and values are aligned) because, even if we used both in the
application, we used the `key` style a lot more. Furthermore, the
`table` style looks strange in places where there are both very long and
very short keys and sometimes we weren't even consistent with the
`table` style, aligning some keys without aligning other keys.

Ideally we could align hashes to "either key or table", so developers
can decide whether keeping the symmetry of the code is worth it in a
case-per-case basis, but Rubocop doesn't allow this option.
2023-08-18 14:56:16 +02:00
Javi Martín
45517f659e Add SDG goals/targets to legislation proposals 2021-02-24 20:42:53 +01:00
Javi Martín
42d2e5b3ad Apply Rails/InverseOf rubocop rule
Not doing so has a few gotchas when working with relations, particularly
with records which are not stored in the database.

I'm excluding the related content file because it's got a very peculiar
relationship with itself: the `has_one :opposite_related_content` has no
inverse; the relation itself is its inverse. It's a false positive since
the inverse condition is true:

```
content.opposite_related_content.opposite_related_content.object_id ==
  content.object_id
```
2019-10-25 19:29:12 +02:00
Javi Martín
94d2496f8f Add missing has_many relations for users
Usually when we specify a `belongs_to` relations, we also specify its
equivalent `has_many`. That allows us to write, for example:
`topic.user.topics`.
2019-10-25 19:27:30 +02:00
Javi Martín
27ed26d6f2 Remove unnecessary class names in relations
Just like we do in the Budget module, and in some places in the Poll and
Legislation modules, we don't need to specify the class name when the
name of the relation matches the name of a class in the same module.
2019-10-25 19:03:14 +02:00
Javi Martín
fda53a0a2a Remove unnecessary foreign_key options
When we specify `belongs_to :author`, ActiveRecord automatically uses
`author_id` as the foreign key.
2019-10-25 19:03:10 +02:00
Javi Martín
1004ac01f8 Add and apply Style/SafeNavigation rubocop rule
We were already using it most of the time, but not always.
2019-10-22 17:37:51 +02:00
Javi Martín
9fe8c47528 Apply Rails/SafeNavigation rubocop rule 2019-09-10 21:43:39 +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
Julian Herrero
8e0bbf54f6 Replace harcoded images and documents settings 2019-06-04 11:50:09 +02:00
decabeza
5bdac5c4f5 Remove question and external_url fields from legislation proposals 2019-04-30 11:35:47 +02:00
Angel Perez
01c1ac2b10 Replace all occurrences of ActiveRecord::Base with ApplicationRecord 2019-04-17 17:40:56 +02:00
Javi Martín
4c35df4812 Use double quotes inside string interpolation 2019-03-25 14:58:54 +01:00
Julian Herrero
3ba961a2d7 Use double quotes in models 2019-03-14 17:25:43 +01:00
Javi Martín
e3ca700e17 Add concerns to set and order by a random seed 2019-02-20 11:51:32 +01:00
Javi Martín
660c59016b Fix random proposals order in the same session
Using `setseed` and ordering by `RAND()` doesn't always return the same
results because, although the generated random numbers will always be
the same, PostgreSQL doesn't guarantee the order of the rows it will
apply those random numbers to, similar to the way it doesn't guarantee
an order when the `ORDER BY` clause isn't specified.

Using something like `reorder("legislation_proposals.id % #{seed}")`,
like we do in budget investments, is certainly more elegant but it makes
the test checking two users get different results fail sometimes, so
that approach might need some adjustments in order to make the results
more random.
2019-02-20 11:51:32 +01:00
decabeza
6b62ba0e91 Show cached_votes_score on admin legislation proposals 2019-02-12 18:42:44 +01:00
decabeza
0ae1cdfc8c Replace total votes to cached_votes_score on legislation proposals
This show votes_score as result of votes_up minus votes_down
2019-02-12 18:42:41 +01:00
Julian Herrero
ef835bef1c new algorithm for filter 'most active' 2018-12-13 11:42:22 +01:00
Javi Martín
8976280493 Order selected proposals by confidence score
The same way we order budget results.
2018-10-04 16:31:00 +02:00
Javi Martín
dc9cf5da55 Order by supports in descending order
Just as we do with confidence score, and as admins expect when they
order by received supports: the ones with more supports appear first.
2018-10-04 16:29:01 +02:00
Raúl Fuentes
05340e423c Add select to Legislation::Proposals
Add admin interface for mark any proposal as selected
Add filter to public interface for selected proposals
2018-10-04 16:28:56 +02:00
decabeza
7c194f6042 Adds imageable to legislation proposals 2018-10-01 16:48:46 +02:00
rgarcia
2b52d26d82 refactors notifications into concerns and shared examples 2017-12-14 16:15:30 +01:00
rgarcia
abaf6ab785 adds model validations for legislation proposals 2017-12-13 12:52:25 +01:00
Bertocq
cd66ba5d54 Rubocop autocorrections 2017-11-13 02:22:00 +01:00
María Checa
5ae31a6d01 Prevent responsible_name and question from validation 2017-10-27 10:43:37 +02:00
María Checa
b5f2f9aa21 Added cached_votes_total and cached_votes_down to Legislation Proposals 2017-10-25 16:42:24 +02:00
María Checa
5ae8cda0d5 Fixed legislation proposal vote action 2017-09-21 16:23:34 +02:00
María Checa
ba041f90c8 Removed unnecessary parts in Legislation Proposals 2017-09-21 16:17:11 +02:00
María Checa
c1672bdbf4 Legislation proposals adaptation in some models and initializers 2017-09-19 10:10:10 +02:00
María Checa
335399e571 Created Legislation Proposals model 2017-09-14 12:50:48 +02:00
María Checa
f521a9023b Added Proposal model to Legislation
This new Legislation::Proposal model inherits from the original Proposal, as it will behave in a very similar way.
2017-09-13 15:43:36 +02:00