-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Hooking the logistration page into the new HTTP endpoint for email opt in #6079
Conversation
""" | ||
course_id = request.DATA['course_id'] | ||
org = locator.CourseLocator.from_string(course_id).org | ||
optin = request.DATA['optIn'].lower() != 'false' # Only check for false. All other values are True. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got a few questions here.
- Since
course_id
andoptIn
are POST parameters, why not get them fromrequest.POST
instead ofrequest.DATA
? - Speaking of getting parameters, wouldn't it be better to use
request.DATA.get(parameter)
instead ofrequest.DATA[parameter]
, so that you can check forNone
if one of those parameters isn't available? - It kind of bothers me that the underscore-separated variable name (
course_id
) is being mixed with a camel-cased parameter name (optIn
). Seems like we're using underscores in our other GET parameter names, so maybe it would be better to useopt_in
instead ofoptIn
. - Speaking of variable names, I see there's another variable here named
optin
. Maybe this could also be namedopt_in
, for consistency with the parameter name. - Finally, wouldn't it be better to set
optin
toTrue
if the opt-in GET parameter is equal to "true", and set it toFalse
otherwise? That is,optin = request.DATA['optIn'].lower() == 'true'
. This is the assumption I made in the student views. It doesn't seem like we should opt someone in to receiving email unless value of the parameter is exactly what we expect (i.e.,true
). If you userequest.DATA.get(parameter)
instead ofrequest.DATA[parameter]
, you can also use this equality check to setoptin
toFalse
if the opt-in GET parameter isNone
.
In summary, I'd change this line to look like this:
opt_in = request.POST.get('opt_in') == 'true'
Phew!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heya, thanks for the input Renzo!
- I'm fine with the names course_id and opt_in. Sounds good to me.
- By the UI design, "True" is the default setting for opting in, so I made that the default value when False is not explicit. For the sake of having uniform contracts, I'll go with your default = false to avoid confusion.
- My understanding of DATA vs. POST is that DATA is offered as a useful utility by the Django REST framework to parse more parameters than just the POST form data. http://www.django-rest-framework.org/api-guide/requests/ By design I always use this over POST.
- On line 874 I check that the opt_in and course_id parameters are set via a decorator, or the function throws an exception before it is even executed. At this point I would prefer the code to fail loudly if it somehow went beyond this call. To that note, I can add a unit test that will fail if anyone tries to remove the decorator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, using DATA over POST seems reasonable; thanks for the link. I see the decorators you mentioned, too. Adding an extra test which fails if someone removes them sounds like a good idea.
@rlucioni updated per comments. waiting on tests. |
Nice. 👍 |
queryParams = this.queryParams(); | ||
|
||
// Set the email opt in preference. | ||
if (queryParams.emailOptIn !== undefined && queryParams.enrollmentAction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use Underscore.js here to check if queryParams.emailOptIn
is undefined? It takes care of some corner cases and gotchas related to determining if a variable is undefined. Should be as straight-forward as _.isUndefined(queryParams.emailOptIn)
.
Edit: Since you're trying to check that queryParams.emailOptIn
is defined, you're going to want !_.isUndefined(queryParams.emailOptIn)
. Sorry about adding another comment after giving the thumbs-up!
…t in. Update the PR based on Code Review comments, and additional tests. Using underscore js
7523c4d
to
32c9230
Compare
🚢 |
👍, thanks for swapping in Underscore. |
The only test failure is a Video Bok Choy test: This is a known flakey test: https://openedx.atlassian.net/browse/TNL-662 |
Hooking the logistration page into the new HTTP endpoint for email opt in
Updating the Login and Registration page to accept the email_opt_in parameter, which will set an organization-wide setting for receiving emails.
Related to the ECOM-525 story, sub task ECOM-680
@rlucioni @wedaly