Skip to content

Email notification when user's role is changed/removed. #3306

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

Closed
wants to merge 9 commits into from

Conversation

Mariatta
Copy link
Contributor

  • Send email to the user whose role has been changed/removed.
  • Send email to other owners of the project.
  • The person who made the change will not receive the email.

Closes #3264

- Send email to the user whose role has been changed/removed.
- Send email to other owners of the project.
- The person who made the change will not receive the email.

Closes pypi#3264
@brainwane
Copy link
Contributor

@Mariatta You see the build failing, right? Thanks for the PR - please comment again when it's fixed up and passing tests. :)

@Mariatta
Copy link
Contributor Author

Thanks @brainwane. All checks passed now 🎉 ✅

Copy link
Contributor

@nlhkabu nlhkabu left a comment

Choose a reason for hiding this comment

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

Hi @Mariatta thanks for the PR :) Just a small copy request from me:

@@ -0,0 +1,6 @@
Your role in the {{ project }} project has been removed by {{ submitter }}.

You are no longer an {{ role }}.
Copy link
Contributor

@nlhkabu nlhkabu Mar 19, 2018

Choose a reason for hiding this comment

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

I think we might need to reword this, because it could either be "a maintainer" or "an owner".

It would also be nice to add some kind of text explaining what the role is.

e.g.

"You are now a project owner. This means that you may add other collaborators, upload releases for the project, delete files and releases, or delete the entire project."

Or

"You are now a project maintainer. This means you may upload releases for the project. You cannot add collaborators, delete files, delete releases, or delete the project.

see #3157 for reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this particular email is for when they are removed from the role, I will phrase it like "You are no longer a(n) owner/maintainer. You can no longer ...".
Does that sounds ok?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, so it is. Sorry, I misread :)

Maybe "you are no longer a project owner/maintainer" to avoid the "a(n)" issue? wdyt?

@@ -0,0 +1,6 @@
Your role in the {{ project }} project has been changed by {{ submitter }}.

You are now a {{ role }}.
Copy link
Contributor

Choose a reason for hiding this comment

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

As above :)

@Mariatta
Copy link
Contributor Author

@nlhkabu I've updated the email text. Let me know what you think. Thanks.

Copy link
Contributor

@nlhkabu nlhkabu left a comment

Choose a reason for hiding this comment

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

Perfect! thank you!

@nlhkabu nlhkabu requested review from di and ewdurbin March 20, 2018 06:23
@nlhkabu
Copy link
Contributor

nlhkabu commented Mar 20, 2018

This is ready on my side! @di or @ewdurbin could you please review the Python code and tests? Thx!

owner_emails = [owner.user.email for owner in owners
if owner.user.email]
if request.user.email in owner_emails:
owner_emails.remove(request.user.email)
Copy link
Member

Choose a reason for hiding this comment

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

We should probably still email the user making the change. This is a relatively major "operation" and if someone has intercepted a password and starts making changes as a user, we'd want them to notify.

Though I it's possible for an attacker to simply remove or replace all active email addresses before making these changes, the primary email address changing would initiate a notification.

owner_emails = [owner.user.email for owner in owners
if owner.user.email]
if request.user.email in owner_emails:
owner_emails.remove(request.user.email)
Copy link
Member

Choose a reason for hiding this comment

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

Notify the user making this change as well.

owner_emails = [owner.user.email for owner in owners
if owner.user.email]
if request.user.email in owner_emails:
owner_emails.remove(request.user.email)
Copy link
Member

Choose a reason for hiding this comment

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

Notify the user making this change as well.

@ewdurbin
Copy link
Member

Thanks @Mariatta! I see that the logic for removing the submitting user from notifications was carried over from existing code, but I think this is a good opportunity to bump the visibility of these kinds of changes.

@Mariatta
Copy link
Contributor Author

No prob. Emails are now being sent to all owners.

)

owner_emails = [owner.user.email for owner in owners
if owner.user.email]
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 all Users should have an email? So if this is causing errors, an email address probably needs added to the fixture in the test where it breaks, rather than adding this filter here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense I've changed this.

)
)
owner_emails = [owner.user.email for owner in owners
if owner.user.email]
Copy link
Member

Choose a reason for hiding this comment

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

Same here as above w/ regards to the filter.

)
)
owner_emails = [owner.user.email for owner in owners
if owner.user.email]
Copy link
Member

Choose a reason for hiding this comment

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

And here.

owner_emails = [owner.user.email for owner in owners
if owner.user.email]

if owner_emails:
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this condition into the send_collaborator_added_email function instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So since we'll always send the email to all owners anyway, and at any time there will always be one owner, I'm assuming that we'll always send the email. So I removed the condition. Is this ok?

role.role_name = form.role_name.data
send_user_role_changed_email(request, role)
if owner_emails:
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this condition into the send_role_changed_for_user_email function instead?

@@ -0,0 +1 @@
Role removed from PyPI
Copy link
Member

Choose a reason for hiding this comment

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

Maybe Role removed on PyPI for project {{ project.name }}?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@@ -0,0 +1 @@
Role changed in PyPI
Copy link
Member

Choose a reason for hiding this comment

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

Maybe Role changed on PyPI for project {{ project.name }}?

@@ -0,0 +1 @@
Role removed from PyPI
Copy link
Member

Choose a reason for hiding this comment

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

Maybe Role removed on PyPI for project {{ project.name }}?

A collaborator's role has been removed from a project you own on PyPI:

Username: {{ username }}
Role: {{ role }}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe "Role was previously:"

[]
)
]
assert send_collaborator_added_email.calls == []
Copy link
Member

Choose a reason for hiding this comment

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

We probably still want this assertion to stay or a similar assertion to replace it.

@brainwane
Copy link
Contributor

@Mariatta hey there -- will you be revising this PR, maybe next week, per the reviews on it? Thanks!

@Mariatta
Copy link
Contributor Author

The test failed in 3.6.1, apparently because the order of the list items matters. I don't know how to properly test that...

@brainwane
Copy link
Contributor

@waseem18 @yeraydiazdiaz do you have any thoughts on how to address the test issue?

@waseem18
Copy link
Contributor

waseem18 commented Mar 31, 2018

@brainwane I'll check now and will comment back.

@waseem18
Copy link
Contributor

waseem18 commented Apr 1, 2018

@Mariatta You can use sorted() on the list so that the order of elements in the list is preserved both in the main code as well as test cases.

In test cases you can change [other_owner.email, owner.email] to sorted([other_owner.email, owner.email]) whereas in warehouse/manage/views.py add sorted() respectively so that owner_emails changes to sorted(owner_emails)

Example:
send_role_changed_for_user_email( request, role, sorted(owner_emails), )

@dstufft
Copy link
Member

dstufft commented Apr 1, 2018

Note that this PR conflicts with #3493 and whichever one lands second will have to be updated to handle the other.

@brainwane
Copy link
Contributor

@di di self-assigned this Apr 2, 2018
@brainwane
Copy link
Contributor

Hey @Mariatta -- we'd like to move forward on this fix, so please let us know whether you'll be revising the PR (to use Wasim's advice to get the tests to pass) within the next few days. If not, I'll find someone else to work on fixing #3264, and if and when you have time to do some Warehouse work in the future, let us know and we'll help you get going. Thanks!

@Mariatta
Copy link
Contributor Author

Thanks for the ping @brainwane. I have some time later this evening (and this evening only) to look into this. My next availability will be at PyCon sprints.
If I couldn't this done, I'll let you know tomorrow. So someone else can continue. Thanks.

@Mariatta
Copy link
Contributor Author

Sorry everyone, I didn't get around working on this last night. If this can't wait until PyCon US sprints, then perhaps it's best for someone else to continue working on this. I'll leave it to you all to close this PR.
Thanks all for the patience, and sorry I couldn't finish this up in time.

@waseem18
Copy link
Contributor

Hey @Mariatta, No worries! I'll add the test case changes today that would fix this PR.

@waseem18
Copy link
Contributor

waseem18 commented Apr 28, 2018

Quick update on this - I'm resolving merge conflicts now and as soon as I'm done with testing I'll push the code.

Edit: I've added a new PR #3853 which fixes the conflicts of this PR. So this PR can be closed now.

@nlhkabu
Copy link
Contributor

nlhkabu commented Apr 29, 2018

Thanks for your work on this @Mariatta, closing in favour of #3853 :)

@nlhkabu nlhkabu closed this Apr 29, 2018
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.

7 participants