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

Added functionality to send email whenever primary email is changed #3158

Merged
merged 2 commits into from
Mar 7, 2018

Conversation

waseem18
Copy link
Contributor

@waseem18 waseem18 commented Mar 7, 2018

Fixes #998

  • Added code to send an email to primary email whenever primary email is changed.
    • If A is the current primary email and email B has been made primary then an email will be sent to the email A.
  • Added email templates
  • Added tests

@waseem18
Copy link
Contributor Author

waseem18 commented Mar 7, 2018

@di Can you please review this PR?!

Thanks

@@ -0,0 +1,5 @@
Someone, perhaps you, has changed the primary email for your PyPI account
'{{ username }}'.
Copy link
Member

Choose a reason for hiding this comment

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

I think it'd be nice here if this email included the emails it changed from/to. So something like

The primary email for your PyPI account:

  '{{ username }}'

been changed from this address:

  {{ old_email }}

to this address:

  {{ new_email }}

If you did not make this change, you can reply to this email directly to
communicate with the PyPI administrators.

@@ -379,8 +379,8 @@ def test_change_primary_email(self, monkeypatch, db_request):
user = UserFactory()
old_primary = EmailFactory(primary=True, user=user)
new_primary = EmailFactory(primary=False, verified=True, user=user)

Copy link
Member

Choose a reason for hiding this comment

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

Also, this is a very small issue, but it seems like your PR removes some empty lines like this one here -- could you make sure they remain?

@waseem18
Copy link
Contributor Author

waseem18 commented Mar 7, 2018

Addressed reviews @di

@di di merged commit c8ed765 into pypi:master Mar 7, 2018
assert view.change_primary_email() == view.default_response
assert send_email.calls == [
pretend.call(db_request, db_request.user, email.email)
Copy link
Contributor Author

@waseem18 waseem18 Mar 8, 2018

Choose a reason for hiding this comment

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

@di After we merged this PR, I created another PR with the latest master - but I see my Travis test failing at this line which is no way related to #3111 . I'm not getting why this particular test failed on Travis. I'm not able to replicate the test failure locally.
I've been looking into this since a couple of hours but in vain so thought of seeking you help.
Could you please help me with this? Thanks

Copy link
Contributor Author

@waseem18 waseem18 Mar 8, 2018

Choose a reason for hiding this comment

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

Strange! Now when I updated my branch in #3111 there wasn't any test failure.

Copy link
Member

Choose a reason for hiding this comment

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

See my comment here: #3158 (comment)

@di di mentioned this pull request Mar 8, 2018
@@ -379,8 +379,10 @@ def test_change_primary_email(self, monkeypatch, db_request):
user = UserFactory()
old_primary = EmailFactory(primary=True, user=user)
new_primary = EmailFactory(primary=False, verified=True, user=user)
email = EmailFactory(user=user)
Copy link
Member

@di di Mar 8, 2018

Choose a reason for hiding this comment

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

@waseem18 The issue is that we're adding an extra email here. Since we've already created the old_primary email above, and since EmailFactory defaults to making the created email primary as well, we had created two primary emails for the user in this test.

The way User.email works is that it assumes there might be multiple primary emails, and returns the first primary email it finds for the user (not totally sure why this is the case, but I'm guessing backwards compatibility with legacy).

In this test, most of the time, user.email would refer to this email, but sometimes (not sure why) they might be created out of order, so user.email would be old_primary instead, causing the test to fail.

The fix is in #3178: just create one primary email for the user, and test that email is the one that gets the message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much for the detailed response and the PR @di

Copy link
Member

Choose a reason for hiding this comment

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

No worries! Sorry that I missed it in review and you spent so much time trying to debug it.

Mariatta pushed a commit to Mariatta/warehouse that referenced this pull request Mar 9, 2018
Mariatta pushed a commit to Mariatta/warehouse that referenced this pull request Mar 9, 2018
Mariatta pushed a commit to Mariatta/warehouse that referenced this pull request Mar 10, 2018
di pushed a commit that referenced this pull request Mar 14, 2018
)

* Send email when a new collaborator has been added to the project.

- send the email to the newly added collaborator
- send the email to other owners
- email not sent to the person who added the collaborator

Closes #1000

* Remove prints

* Make linter happy.

* Added functionality to send email whenever primary email is changed (#3158)

Addressed code reviews

* - Send a separate welcome email to the new collaborator
- Add owners emails in bcc field

* PEP 8

* Fix linters errors

* - Deindent
- Add footer to email

* Rebased with master

* Fix broken unit test.

* Fix linter error

* PEP 8

* Actually send the email to bcc recipients
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants