Skip login after registration (mostly for NYIF) - #174
Conversation
OmarIthawi
left a comment
There was a problem hiding this comment.
Looks good to me. Only two changes to go!
| organization = request.site.organizations.first() | ||
| if organization: | ||
| UserOrganizationMapping.objects.get_or_create(user=user, organization=organization, is_active=False) | ||
| except: |
There was a problem hiding this comment.
except: -> except NameError: to ensure that anything other than missing UserOrganizationMapping being catched (well, at least most of the errors).
There was a problem hiding this comment.
@tkeemon don't take my word for it. Please double check whether this works or not.
Generally it's advisable to avoid except: and except Exception: whenever possible.
There was a problem hiding this comment.
@OmarIthawi thanks for catching this. This is definitely a bad habit of mine.
Take a look and let me know if this addresses your concern.
| login(request, new_user) | ||
| request.session.set_expiry(0) | ||
|
|
||
| if not settings.APPSEMBLER_FEATURES.get('SKIP_LOGIN_AFTER_REGISTRATION',False): |
There was a problem hiding this comment.
...ION',False) -> ...ION', False) space after comma.
| #default behavior is to replace the existing backends with those in APPSEMBLER_FEATURES | ||
| AUTHENTICATION_BACKENDS = tuple(APPSEMBLER_FEATURES['LMS_AUTHENTICATION_BACKENDS']) | ||
|
|
||
| #attempt to import model from our custom fork of edx-organizations |
There was a problem hiding this comment.
Not specific to this PR at all. But we do need to DRY in the envs/*_appsembler.py files.
There was a problem hiding this comment.
Agreed. And @johnbaldwin has raised this same point as well:
https://trello.com/c/wfj1jPTd/98-dry-up-awsappsembler-and-devstackappsembler-py-files
That's what I was attempting to do with the appsembler.py file. Initially, this file was supposed to be imported by both aws_appsembler.py and devstack_appsembler.py, so settings could be shared across both of production and devstack deployments.
But with this setup we were running into some problems. I can't remember specifically, but I think it was related to the fact that this file was called without importing common.py, so variables like INSTALLED_APPS didn't yet exist. And if we defined INSTALLED_APPS in appsembler.py, then it would nuke all of the values from common.py and aws.py when imported into aws_appsembler.py.
We can definitely do this, we just need to be careful about how we structure the imports.
|
@tkeemon somewhere the PEP8 there's a good practice:
|
|
@tkeemon One additional read about the |
OmarIthawi
left a comment
There was a problem hiding this comment.
One suggestion and we're good to!
| pass | ||
| else: | ||
| if organization: | ||
| UserOrganizationMapping.objects.get_or_create(user=user, organization=organization, is_active=False) |
There was a problem hiding this comment.
Looks much better. I'd like to take it further:
Why not completely avoid the try/except? I think having if u'organizations.backends.OrganizationMemberBackend' in settings.AUTHENTICATION_BACKENDS: makes it safe to assume that all the rest will go well:
if u'organizations.backends.OrganizationMemberBackend' in settings.AUTHENTICATION_BACKENDS:
organization = request.site.organizations.first()
UserOrganizationMapping.objects.get_or_create(user=user, organization=organization, is_active=False)
Do we expect that organization = request.site.organizations.first() to be None? If so, let's keep the if organization: part.
There was a problem hiding this comment.
That's a good point. I'll remove the try/except. I do expect organization = request.site.organizations.first() to return None when the site in question is the default site, so I'm going to leave that last if statement in there.
Making that change and merging.
I've added two major changes to the account registration workflow here:
APPSEMBLER_FEATURES['SKIP_LOGIN_AFTER_REGISTRATION']. If set toTrue, users aren't automatically redirected to /dashboard after creating a new account.The default behavior for each change is:
SKIP_LOGIN_AFTER_REGISTRATIONdoesn't exist, then the normal registration workflow takes place and the user is logged in and redirected to /dashboard after registration.Related commits:
https://github.com/noderabbit-team/edx-configs/commit/6df426793ef349659e503bf05aea95a9ed6d19d7