Commit Graph

55 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
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
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
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
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
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
7ca55c44e0 Apply Rails/SaveBang rubocop rule
Having exceptions is better than having silent bugs.

There are a few methods I've kept the same way they were.

The `RelatedContentScore#score_with_opposite` method is a bit peculiar:
it creates scores for both itself and the opposite related content,
which means the opposite related content will try to create the same
scores as well.

We've already got a test to check `Budget::Ballot#add_investment` when
creating a line fails ("Edge case voting a non-elegible investment").

Finally, the method `User#send_oauth_confirmation_instructions` doesn't
update the record when the email address isn't already present, leading
to the test "Try to register with the email of an already existing user,
when an unconfirmed email was provided by oauth" fo fail if we raise an
exception for an invalid user. That's because updating a user's email
doesn't update the database automatically, but instead a confirmation
email is sent.

There are also a few false positives for classes which don't have bang
methods (like the GraphQL classes) or destroying attachments.

For these reasons, I'm adding the rule with a "Refactor" severity,
meaning it's a rule we can break if necessary.
2019-10-23 14:39:31 +02:00
Javi Martín
431074c99f Add save! method to ActiveModel models
This way we make it clear we expect records to be valid when we save
them, just like we do with ActiveRecord models.
2019-10-23 14:32:42 +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
71d9ddd849 Apply rule to end files with a newline character 2019-09-10 20:02:15 +02:00
Julian Herrero
d24376f6ad Use double quotes in controllers/ 2019-03-13 22:19:49 +01:00
rgarcia
618c6f8f36 uses method instead of db attribute to check for sms verification 2017-09-06 12:25:55 +02: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
Juanjo Bazán
73aea8f127 rescues ahoy error stoping user verifications 2016-01-29 11:41:16 +01:00
Juanjo Bazán
3802bc78b5 removes comments
This controller is no longer used in /management
2015-10-23 11:22:23 +02:00
kikito
f596beaaf5 removes unnecessary conditions from before_actions in verification/letter_controller 2015-10-20 17:33:16 +02:00
kikito
18db6482f9 makes sure verifications only happen for signed in users when doing a letter verification 2015-10-20 17:18:28 +02:00
kikito
0d0806c9ae improvements in the letter verification error messages 2015-10-20 16:19:17 +02:00
rgarcia
5fe1bb3eee verifies the letter's code 2015-10-19 22:58:44 +02:00
rgarcia
5ac2784294 removes unnecessary layout 2015-10-19 20:32:55 +02:00
rgarcia
a6fd1fb489 moves letter verification to letter controller 2015-10-19 19:38:22 +02:00
rgarcia
fd8684e713 redirects to show after asking for letter 2015-10-19 19:32:53 +02:00
kikito
050971c459 modifies email controllers: management email makes users level two verified, and sets their document number permanently. Fixes failing test 2015-10-13 17:20:39 +02:00
rgarcia
f5d0b8083f adds change me note 2015-10-12 14:06:02 +02:00
kikito
5b21fc464f Fixes failing tests 2015-10-08 19:59:33 +02:00
kikito
3ed5c269e4 Adds unconfirmed_document_number into email verifications
It also makes sure that when a user is considered level 3 is also
considered residence-verified.
2015-10-02 18:44:15 +02:00
rgarcia
f0b1f1901e fixes typo 2015-09-28 12:05:06 +02:00
rgarcia
24a60bdbf2 removes unnecessary condition and flash 2015-09-28 11:59:03 +02:00
Alberto Garcia Cabeza
0b2cf1e2bb Changes final verification step page 2015-09-14 19:18:50 +02:00
Juanjo Bazán
dbdd149c06 redirects user to sms if no verified data
Fixes #433
2015-09-12 21:42:17 +02:00
Juanjo Bazán
f517d7f410 adds before action for verified users 2015-09-11 16:44:52 +02:00
rgarcia
abc68dc868 refactors lock tries [#279] 2015-09-10 20:26:49 +02:00
rgarcia
b7c1b4acee renames verify? methods [#395] 2015-09-10 20:08:11 +02:00
rgarcia
cdda0ec34a removes unused i18n key [#395] 2015-09-10 14:31:33 +02:00
Enrique García
78f35673b3 Merge pull request #457 from AyuntamientoMadrid/letter_verification_tries-332
Letter verification tries
2015-09-10 13:21:31 +02:00
rgarcia
16dd609ad0 adds verification tries to letter code [#332] 2015-09-10 11:43:25 +02:00
rgarcia
9360c0090e tracks level 2 verified users 2015-09-10 11:03:31 +02:00
rgarcia
34218d112b increases residence verification tries after a Census call 2015-09-05 23:57:47 +02:00
rgarcia
d0d33cc517 sends custom emails with delayed jobs 2015-09-03 22:48:29 +02:00
rgarcia
4d97063887 removes unused spec 2015-09-02 21:59:51 +02:00
rgarcia
99d779bcec adds letter code verification 2015-09-02 21:57:03 +02:00
Alberto Garcia Cabeza
da86c5d6e0 Adds styles for verification account process 2015-09-02 12:34:08 +02:00
Juanjo Bazán
3217d262b4 Merge pull request #292 from AyuntamientoMadrid/mask_user_data
Mask user data
2015-08-30 15:22:25 +02:00
rgarcia
76daee1fb0 removes unmasked emails and phones in forms 2015-08-30 15:16:33 +02:00
rgarcia
9abd794133 validates acceptance of census terms of service 2015-08-30 12:50:17 +02:00
Juanjo Bazán
e8463d1372 moves Residence model to Verification namespace 2015-08-29 12:38:07 +02:00
Juanjo Bazán
e33723635b moves Email model to Verification namespace 2015-08-29 12:26:20 +02:00
Juanjo Bazán
e6fd62189b moves Sms model to Verification namespace 2015-08-29 12:17:27 +02:00
Juanjo Bazán
50dcbcdf9b moves Letter to Verification namespace 2015-08-29 12:07:43 +02:00