Commit Graph

141 Commits

Author SHA1 Message Date
Javi Martín
f7e2d724dd Replace ahoy events with real data
We were tracking some events with Ahoy, but in an inconsistent way. For
example, we were tracking when a debate was created, but (probably
accidentally) we were only tracking proposals when they were created
from the management section. For budget investments and their supports,
we weren't using Ahoy events but checking their database tables instead.
And we were only using ahoy events for the charts; for the other stats,
we were using the real data.

While we could actually fix these issues and start tracking events
correctly, existing production data would remain broken because we
didn't track a certain event when it happened. And, besides, why should
we bother, for instance, to track when a debate is created, when we can
instead access that information in the debates table?

There are probably some features related to tracking an event and their
visits, but we weren't using them, and we were storing more user data
than we needed to.

So we're removing the track events, allowing us to simplify the code and
make it more consistent. We aren't removing the `ahoy_events` table in
case existing Consul Democracy installations use it, but we'll remove it
after releasing version 2.2.0 and adding a warning in the release notes.

This change fixes the proposal created chart, since we were only
tracking proposals created in the management section, and opens the
possibility to add more charts in the future using data we didn't track
with Ahoy.

Also note the "Level 2 user Graph" test wasn't testing the graph, so
we're changing it in order to test it. We're also moving it next to the
other graphs test and, since we were tracking the event when we were
confirming the phone, we're renaming to "Level 3 users".

Finally, note that, since we were tracking events when something was
created, we're including the `with_hidden` scope. This is also
consistent with the other stats shown in the admin section as well as
the public stats.
2024-05-09 14:28:32 +02:00
Javi Martín
1ee30c0bb7 Remove the create action from CommentableActions
We were only using it in one place: the debates controller. All the
other controllers including CommentableActions were overwriting this
action, except the ones in the admin area, where creating proposals,
debates or investments isn't possible.

Note this means that, most of the times, we weren't tracking events
creating a resource.

Also note that since, as mentioned in commit 3752fef6b, there are no
geozones in the debates form, we don't have to load them when creating a
debate fails due to validation rules.
2024-05-09 14:24:53 +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
Javi Martín
2fd4ca912e Merge pull request #4804 from consul/allowed_params
Make it easier to customize allowed parameters
2022-04-11 12:25:26 +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
3752fef6bf Remove map page in debates
The map feature was never implemented for debates (only for proposals
and budget investments) and it was crashing for debates because the page
didn't load the geozones. And we don't have a "geozone" field in the
debates form either.

So we're removing the map page alongside its (pending implementation)
tests.
2022-04-07 15:34:07 +02: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
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
e6bfeef58d Add SDG::RelatedListSelectorComponent to Debates 2021-01-22 16:04:40 +01: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
Javi Martín
941fc76884 Remove unused query parameters in redirect
These actions are never called with query parameters in our application,
so there's no need to use these parameters in a redirect.

Note in the test I'm using the `get` method because the `patch` method
wouldn't send query parameters. This doesn't mean the action can be
accessed through GET requests, since controller tests don't check route
verbs.
2019-11-12 19:27:58 +01:00
Javi Martín
97e826f2a4 Don't use update_attribute
This method is ambiguous. Sometimes we use it to set invalid data in
tests (which can usually be done with `update_column`), and other times
we use it instead of `update!`.

I'm removing it because, even if sometimes it could make sense to use
it, it's too similar to `update_attributes` (which is an alias for
`update` and runs validations), making it confusing.

However, there's one case where we're still using it: in the
ActsAsParanoidAliases module, we need to invoke the callbacks, which
`update_column` skips, but tests related to translations fail if we use
`update!`. The reason for this is the tests check what happens if we
restore a record without restoring its translations. But that will make
the record invalid, since there's a validation rule checking it has at
least one translation.

I'm not blacklisting any other method which skips validations because we
know they skip validations and use them anyway (hopefully with care).
2019-10-25 23:17:50 +02: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
b5b07bccd3 Apply PercentLiteralDelimiters rubocop rule 2019-09-10 20:02:15 +02:00
Senén Rodero Rodríguez
51cda51155 Add debates translation interface
Also fix broken spec after removing translatable attributes from
strong_parameters definition. Now we need to send these attributes
as nested translations attributes.

Use activerecord.yml title attribute label so form helper could load it
from default location.
2019-06-27 09:19:36 +02:00
Julian Herrero
d24376f6ad Use double quotes in controllers/ 2019-03-13 22:19:49 +01: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
522c206f6d Enable 'Recommended debates' setting for users 2018-07-15 21:28:57 -04:00
decabeza
36a5ff39b8 Adds recommendations on debates index 2018-07-15 21:28:57 -04:00
decabeza
c4dc7bc831 Adds view mode on debates 2018-04-02 17:28:39 +02:00
María Checa
3836b73482 Added related contents to debates 2017-12-18 23:56:32 +01:00
taitus
fe3bb7a389 Add recommended tab on proposals and debates index. 2017-08-01 16:31:44 +02:00
decabeza
c76bd65b40 removes old proposals successful banner 2017-06-05 16:29:48 +02:00
rgarcia
87dd15b7bf includes search concern in commendable actions 2017-05-04 20:42:21 +02:00
rgarcia
37d8693049 extracts advanced search to controller concern 2017-05-04 04:23:53 +02:00
Juanjo Bazán
7b6713f8bb fixes typo in method call 2016-12-27 18:26:27 +01:00
kikito
f0b8cfd4a2 Time.now -> Time.current 2016-11-23 19:19:19 +01:00
rgarcia
bb3c4c6399 adds consistency to ruby code style
Keep a blank line before and after private
Keep a blank line before and after protected
Remove extra empty line at class body end
Remove extra blank line
Add final newline
Use 2 (not 3) spaces for indentation
Use 2 (not 4) spaces for indentation
Remove space before comma
Add space after comma
Remove trailing whitespaces
Remove unnecessary spacing
Use snake_case for variable names
Do not use then for multi-line if
Remove unused block argument - i
Use the new Ruby 1.9 hash syntax
Remove unused assignment to variable
Indent when as deep as case
Align attributes
Align end with def
2016-11-15 11:18:43 +01:00
Alberto Garcia Cabeza
7abd31e4bf Renames variable, updates text 2016-09-15 13:47:53 +02:00
Alberto Garcia Cabeza
db6f82fa4c Moves banner to a partial and includes it on debates index 2016-09-14 11:09:36 +02:00
kikito
9ac6e2d60b Uses invisible_captcha's default "foo fast" action 2016-04-28 12:47:04 +02:00
kikito
7adc706d23 Moves redirect_timestamp_spam to AppController 2016-04-27 16:13:49 +02:00
kikito
289182b145 Adds invisible_captcha to proposals, debates & sps 2016-04-27 16:12:32 +02:00
kikito
eedf02a186 Starts using invisible_captcha in the source code. Pending: tests, proper invisible_captcha gem in Gemfile 2016-04-27 16:07:48 +02:00
kikito
dea1a28a69 purges simple_captcha 2016-04-27 16:07:47 +02:00
Juanjo Bazán
54c1c581f9 uses index_customization in debates_controller 2016-04-21 12:00:48 +02:00
MaiteHdezRivas
f771a61a50 Refactoring method on debates controller 2016-04-21 11:13:58 +02:00
MaiteHdezRivas
3e7db9d1b5 Best practices code changes 2016-04-20 16:40:58 +02:00
MaiteHdezRivas
68f9a76cea Mark debates as featured 2016-03-20 13:56:05 +01:00
Raimond Garcia
2a4adc2e60 Merge pull request #817 from microweb10/friendly_urls
Friendly urls
2016-03-02 17:51:00 +01:00
rgarcia
f82a590e1e reverts debate links 2016-02-19 19:08:35 +01:00
palomahnhp
2ee90ac76e share links to debate 2016-02-08 10:32:57 +01:00
rgarcia
e4a49f802e removes duplication between debate and proposal suggestions 2016-02-03 19:57:37 +01:00
MaiteHdezRivas
5dd4633d6a Merge branch 'suggest_before_creating'
Conflicts:
	app/assets/javascripts/application.js
	app/controllers/debates_controller.rb
	app/controllers/proposals_controller.rb
	config/locales/es.yml
	config/routes.rb
	db/schema.rb
	spec/features/debates_spec.rb
	spec/features/proposals_spec.rb
2016-01-27 13:11:23 +01:00
MaiteHdezRivas
7406904c51 adding suggest with coffescript 2016-01-27 12:32:44 +01:00
rgarcia
21b9e31f11 uses geozones instead of district tags 2016-01-25 22:28:46 +01:00
Perisso
7d1d4cea4a filter by districts and categories 2016-01-25 22:28:17 +01:00
Juanjo Bazán
393388de71 Merge pull request #830 from AjuntamentdeBarcelona/feature_flags
Feature flags
2016-01-18 15:19:09 +01:00