Commit Graph

18 Commits

Author SHA1 Message Date
rgarcia
68a2281203 Refactor segment constant into a class method
We're going to make it dynamic using the geozones. Besides, class
methods can be overwritten using custom models, while constants can't be
overwritten without getting a warning [1].

Makes the definition of segments with geozones a little cleaner. I
think it’s worth it, compared to the slight memory gain of using a
constant [2].

[1] warning: already initialized constant UserSegments::SEGMENTS

[2] https://stackoverflow.com/questions/15903835/class-method-vs-constant-in-ruby-rails#answer-15903970
2021-12-20 15:07:25 +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
f6351819fa Simplify SQL using DISTINCT
Using `pluck("DISTINCT")` was raising a warning in Rails 5.2:

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

Since there was only one other use of distinct, I've decided to change
both of them in the same commit, even if the second one wasn't raising a
warning.
2020-07-08 18:34:58 +02:00
Mohsin Khan
9fd79cefd4 Don't send newsletters to unconfirmed accounts (Merge #3781) 2019-10-30 21:15:05 +01:00
Javi Martín
8b5cca746c Apply rubocop rules to freeze constants
Added by popular demand among our team members.
2019-10-26 13:21:36 +02:00
Javi Martín
d639cd587a Remove unnecessary uniq calls
The code `where(id: ids)` is equivalent to `where(id: ids.uniq)`.

Since Rails 5 uses `distinct` instead of `uniq` and in most cases where
we use `uniq` with `pluck` we should simply remove the `uniq` call (as
done in this commit), we're also removing the `Rails/UniqBeforePluck`
rubocop rule.
2019-09-10 22:27:33 +02:00
Javi Martín
47b2c42a1d Apply IndentationConsistency rubocop rule 2019-09-10 20:02:15 +02:00
decabeza
e6af2f15fb Add new user segment all_proposals_authors 2019-05-17 17:22:29 +02:00
Julian Herrero
002e16ce30 Use double quotes in lib/ 2019-03-15 10:29:07 +01:00
Julian Herrero
fc69c21ebb Send newsletter emails in order
The list of emails for sending newsletters will always be ordered by
user creation date, so it will be easier to debug and to know for
which users the email has been sent.
2019-02-06 15:06:29 +01:00
Bertocq
2ecbfc76e0 Add Segment for users without supports on Budget
Created not_supported_on_current_budget at UserSegment along with model
spec scenario and translation strings.
2018-03-15 16:48:54 +01:00
Bertocq
6b41b6487b Add UserSegments#user_segment_emails helper method
Why:

Both Newsletters and Email Downloads need the same logic: To extract the
emails from all the users in the segment that have newsletter flag
active, removing all empty email values.

How:

1- UserSegments#user_segment_emails holds that repeated logic and is used
on both Newsletter & EmailDownload.

2- Rename Newsletter#list_of_recipients to list_of_recipient_emails as
it is more descriptive. There is no need to pass entire Users around,
only the emails are needed at Mailer#newsletter method.

3- Cleanup Newsletter#list_of_recipient_emails model spec scenario
2018-03-01 20:59:20 +01:00
María Checa
678ea0bef2 Added unfeasible investments with valuation not finished to UserSegments#feasible_and_undecided_investment_authors 2018-02-28 16:54:28 +01:00
Bertocq
61f015e2c2 Add administrators UserSegment
We need a user segment to have only administrators as recipients of both
newsletters and notifications
2018-02-21 23:34:20 +01:00
Bertocq
fb2c92228a Refactor UserSegment class
Simple refactor to avoid creating unnecessary variables and make it easier
to read.
2018-02-21 11:47:30 +01:00
Bertocq
bdbb32e824 Move newsletter User scope outside UserSegments
Why:

UserSegments are not only used for Newsletters or Email downloads, but
also for internal Global Notifications. We don't want to have that scope
hardcoded inside UserSegments as users that have opted-out from the
newsletter should still be recipients of global notifications.

How:

Removing the scope from the UserSegments `all_users` method that acts as
base for all the other segments. Including that `newsletter` scope only
on the places that is relevant:
* When listing recipients for a newsletter
* When downloading a listing emails that can be newsletter recipients

Also updated relevant tests
2018-02-21 11:45:38 +01:00
María Checa
6c36e17ce2 Added SEGMENTS variable to UserSegments class 2018-02-20 22:33:01 +01:00
María Checa
07f2419f8f Added newsletter model and UserSegments class 2018-02-13 11:39:10 +01:00