mitodl / teachersportal

MIT ODL Teacher's Portal
0 stars 0 forks source link

If there's a missing userinfo, error rather than 500 #430

Closed justinabrahms closed 8 years ago

justinabrahms commented 8 years ago

What are the relevant tickets?

Fixes #406

What's this PR do?

Wraps guards around times we expect to have userinfo objects and raises a validation error if it doesn't.

Where should the reviewer start?

checkout.py

How should this be manually tested?

Create a superuser. Go do TP things (view courses, etc) and you shouldn't get 500s.

Any background context you want to provide?

Screenshots (if appropriate)

What GIF best describes this PR or how it makes you feel?

noisecapella commented 8 years ago

There's a edge case here, from webpack.py:

try:
    email = request.user.email
    name = request.user.userinfo.full_name
except (AttributeError, ObjectDoesNotExist):
    # AnonymousUser doesn't have an email address
    # or incorrectly built user, as it lacks a userinfo property.
    email = ""
    name = ""

If the user lacks a userinfo object we should still get their email address, though this is not critical as it's just used to inform Stripe so it can prepopulate the email in the form

justinabrahms commented 8 years ago

Updated with tests and suggested improvement.

noisecapella commented 8 years ago

Looks good :+1: