Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't send newsletters to unconfirmed accounts #3781

Merged
merged 4 commits into from
Oct 30, 2019

Conversation

mohsinkhansymc
Copy link
Contributor

@mohsinkhansymc mohsinkhansymc commented Oct 20, 2019

References

Objectives

Prior to this PR, an unconfirmed user was considered as active. After this change a user who has confirmed his account is an active user.

@mohsinkhansymc
Copy link
Contributor Author

@PierreMesure Please review, thanks

@javierm javierm added this to Reviewing in Roadmap via automation Oct 20, 2019
@javierm
Copy link
Member

javierm commented Oct 20, 2019

@mohsinkhansymc Thanks for this pull request! 😄 I'll have a look at it, hopefully next week.

In the meantime, could you add a test for the scenario we're trying to fix (sending newsletters to unconfirmed account)? 🙏 Thanks!

@PierreMesure
Copy link
Collaborator

PierreMesure commented Oct 20, 2019

Thanks a lot!

Did you do any manual test? Because by looking at the other scopes like:

scope :newsletter,     -> { where(newsletter: true) }
scope :email_digest,   -> { where(email_digest: true) }

It doesn't seem like they filter by active user, but booleans like newsletter or email_digest are already set to true before the account is confirmed. Shouldn't we add that criterium to all the scopes (except erased)?

I will have time to try it myself on Friday.

@javierm javierm moved this from Reviewing to Doing in Roadmap Oct 21, 2019
@mohsinkhansymc
Copy link
Contributor Author

@PierreMesure The active check is enough as first all the users are fetched and then

Thanks a lot!

Did you do any manual test? Because by looking at the other scopes like:

scope :newsletter,     -> { where(newsletter: true) }
scope :email_digest,   -> { where(email_digest: true) }

It doesn't seem like they filter by active user, but booleans like newsletter or email_digest are already set to true before the account is confirmed. Shouldn't we add that criterium to all the scopes (except erased)?

I will have time to try it myself on Friday.

This code should work if the said scope sends to all users, but sure you can have a look on Friday

@mohsinkhansymc
Copy link
Contributor Author

@javierm Please review the test case, thanks

@PierreMesure
Copy link
Collaborator

PierreMesure commented Oct 21, 2019

Ah, thanks! That answers my question!

@mohsinkhansymc your test looks great. I'd say you don't need to test that user3 is not in the array since you already tested that the array is exactly [user1, user2].

If @javierm has time to review and merge before Friday, then please do it. Otherwise, I'll try to spend half an hour on it at the end of the week.

@javierm javierm moved this from Doing to Reviewing in Roadmap Oct 21, 2019
Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohsinkhansymc Thank you very much! 😄 I've left a couple of comments; let me know what you think 😉. I think we're definitely on the right track here 👍.

app/models/user.rb Outdated Show resolved Hide resolved
spec/models/user_spec.rb Outdated Show resolved Hide resolved
@javierm javierm moved this from Reviewing to Doing in Roadmap Oct 21, 2019
@mohsinkhansymc
Copy link
Contributor Author

@javierm I have done the changes you proposed. Thanks

@javierm javierm moved this from Doing to Reviewing in Roadmap Oct 22, 2019
lib/user_segments.rb Outdated Show resolved Hide resolved
@javierm javierm moved this from Reviewing to Doing in Roadmap Oct 22, 2019
@javierm javierm added the Bug label Oct 22, 2019
@javierm javierm changed the title send email notifications to verified active users Don't send newsletters to unconfirmed accounts Oct 22, 2019
@javierm javierm self-assigned this Oct 22, 2019
@PierreMesure
Copy link
Collaborator

PierreMesure commented Oct 23, 2019

Before we close this, I'd like to point out that User.active is also used to calculate the number of users shown in the Statistics page on the admin panel. Is this what we want? Or do we want to reflect the number of users who actually confirmed their e-mail address?

Capture d’écran 2019-10-23 à 19 36 56

In general, shouldn't we replace all the occurrences of User.active by a new scope that dismisses the users that didn't confirm their e-mail addresses?

In the cases where we use this method to find users who have already created content or to filter by document number, that might actually slightly increase the performances.

@javierm
Copy link
Member

javierm commented Oct 23, 2019

In general, shouldn't we replace all the occurrences of User.active by a new scope that dismisses the users that didn't confirm their e-mail addresses?

The active scope is used in several places related to verification, which is a part of the application most forks change, so I'd rather be conservative here and keep the existing behavior 🤔.

Regarding the admin statistics, I don't have a strong opinion; I guess both approaches are valid 🤔.

@PierreMesure
Copy link
Collaborator

PierreMesure commented Oct 23, 2019

Yes, I agree with you that touching active is not a good idea. But creating a confirmed_users scope which we can then use in all the places where active is used today?

I'm curious, would you be able to check how many accounts never confirmed their e-mail address on decide.madrid.es?

The query would be

SELECT COUNT(*)
FROM users
WHERE confirmed_at is NULL;

@mohsinkhansymc
Copy link
Contributor Author

@PierreMesure we can have a separate label on the stats page that shows confirmed accounts or we can modify the total users label to confirmedcount/totalusers. Also instead of showing unverified users we can show active users that will return the confirmed accounts count. What do you guys think? @javierm

@javierm
Copy link
Member

javierm commented Oct 30, 2019

This is an interesting topic 🤔. Since we're trying to get everything ready for version 1.1, I'd rather be conservative and only change the code affecting newsletters. Feel free to open a new issue and continue this conversation once we release version 1.1, and maybe then we can study the implications of chaging the active scope 😄.

@mohsinkhansymc For now, it would be awesome if we kept this pull request as it is, except for the suggested change in the all_users method, and then we can merge it and it will be included in version 1.1 🎉.

Co-Authored-By: Javier Martín <35156+javierm@users.noreply.github.com>
Roadmap automation moved this from Doing to Testing Oct 30, 2019
@javierm javierm merged commit 9fd79ce into consuldemocracy:master Oct 30, 2019
Roadmap automation moved this from Testing to Release 1.1.0 Oct 30, 2019
@javierm
Copy link
Member

javierm commented Oct 30, 2019

@mohsinkhansymc Thanks a lot! 😄

smarques pushed a commit to venetochevogliamo/consul that referenced this pull request Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Roadmap
  
Release 1.1.0
Development

Successfully merging this pull request may close these issues.

Consul sends newsletters to unconfirmed accounts
3 participants