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

Send email when a 2fa method is added or removed #6930

Merged
merged 7 commits into from
Feb 8, 2020
Merged

Send email when a 2fa method is added or removed #6930

merged 7 commits into from
Feb 8, 2020

Conversation

rascalking
Copy link
Contributor

This addresses #5808.

I'm hoping for some feedback on the approach before I go in and add tests. The "stash in session.info on flush, retrieve on commit" dance seemed to be a fairly common pattern, but none of them needed the request, so I'm not sure how folks will feel about stashing the it in there as well. I didn't see any other way to get the email service without the request.

@di
Copy link
Member

di commented Jan 14, 2020

Thanks for working on this and sorry for the delay!

I appreciate the thoroughness of hooking into the database events here (and I see that it was suggested in #5808) but I wonder if it's necessary? We could just call send_2fa_added_email/send_2fa_removed_email directly in the views instead.

@rascalking
Copy link
Contributor Author

If folks aren't worried about it timing out the request, yup, that'd certainly simplify things. I'll redo this with that approach.

@rascalking
Copy link
Contributor Author

Oh, I'd forgotten, part of the reason for doing it this way is so that we're only sending the email if the db commit succeeds. I'm not sure how often a commit failing happens in practice, but we probably shouldn't send the email if it does, right?

@di
Copy link
Member

di commented Jan 21, 2020

@rascalking The email gets added to a queue, so not really at risk for timing out the request, but I appreciate you considering it.

The commits don't usually fail (and would not likely fail here) but I think that's probably a valid concern. Curious if @ewdurbin has any thoughts here as well.

@ewdurbin
Copy link
Member

That's an interesting concern. I suppose we haven't really considered it in other task enqueuing.

I suppose we have to choose one of two cases:

  • Task enqueue succeeds, commit fails
  • Commit succeeds, task enqueue fails

Both are similarly possible. I think I'd prefer the first case as far as account notifications are concerned. If someone tried to add or remove a 2FA method on my account I'd like to know about it... even if they got an error :)

@di
Copy link
Member

di commented Jan 21, 2020

I think I'd prefer the first case as far as account notifications are concerned.

I think I agree, at least for the scope of this PR.

@dstufft
Copy link
Member

dstufft commented Jan 27, 2020

That's an interesting concern. I suppose we haven't really considered it in other task enqueuing.

I suppose we have to choose one of two cases:

  • Task enqueue succeeds, commit fails
  • Commit succeeds, task enqueue fails

Both are similarly possible. I think I'd prefer the first case as far as account notifications are concerned. If someone tried to add or remove a 2FA method on my account I'd like to know about it... even if they got an error :)

Actually, our Celery integration is already setup to only enqueue in the case that the database commit goes through successfully. It also ensures that the task gets queued after the database has been written to, to avoid conditions where you fire off a task, the celery worker grabs it and starts a database transaction before you've actually submitted your own.

This is all taken care of here in warehouse/tasks.py#L93-L113.

@di di self-requested a review January 27, 2020 16:52
@rascalking
Copy link
Contributor Author

Wow, nice bit of plumbing.

Copy link
Member

@ewdurbin ewdurbin left a comment

Choose a reason for hiding this comment

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

This looks great, I'd like to see us change from 2fa to two_factor in the code and email template names before shipping, but that's all!

@@ -201,6 +201,18 @@ def send_added_as_collaborator_email(request, user, *, submitter, project_name,
return {"project": project_name, "submitter": submitter.username, "role": role}


@_email("2fa-added")
Copy link
Member

Choose a reason for hiding this comment

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

I feel like 2fa should be spelled out as two_factor here and other places in this changeset. This is more consistent with what we in other places in the code base.

@rascalking
Copy link
Contributor Author

All set.

@ewdurbin
Copy link
Member

ewdurbin commented Feb 8, 2020

Thanks @rascalking!

@ewdurbin ewdurbin merged commit 148adc0 into pypi:master Feb 8, 2020
@brainwane
Copy link
Contributor

Thank you very much @rascalking! Really appreciated. If you are interested in continuing to contribute to Warehouse and would like suggestions on what to do next, reply to let us know!

@rascalking rascalking deleted the 5808-email-on-2fa-enable-disable branch February 10, 2020 20:50
@rascalking
Copy link
Contributor Author

Yup, I just grabbed a bunch of things that looked like useful low-hanging fruit for hacktoberfest, but if there's other stuff that needs working on, I'm happy to pick some of that up.

@brainwane
Copy link
Contributor

@rascalking could you take a look at #5867 ?

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.

5 participants