Hooking the logistration page into the new HTTP endpoint for email opt in - #6079
Conversation
There was a problem hiding this comment.
I've got a few questions here.
- Since
course_idandoptInare POST parameters, why not get them fromrequest.POSTinstead 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 forNoneif 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_ininstead 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
optintoTrueif the opt-in GET parameter is equal to "true", and set it toFalseotherwise? 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 setoptintoFalseif 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.
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.
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. 👍 |
There was a problem hiding this comment.
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