Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions common/djangoapps/student/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@
from openedx.core.djangoapps.user_api.preferences import api as preferences_api
from openedx.core.djangoapps.catalog.utils import get_programs_data

# try to import appsembler fork of edx-organizations (if it's installed)
try:
from organizations.models import UserOrganizationMapping
except ImportError:
pass

log = logging.getLogger("edx.student")
AUDIT_LOG = logging.getLogger("audit")
Expand Down Expand Up @@ -1857,13 +1862,21 @@ def create_account_with_params(request, params):
else:
registration.activate()
_enroll_user_in_pending_courses(user) # Enroll student in any pending courses

#if using custom Appsembler backend from edx-organizations
if u'organizations.backends.OrganizationMemberBackend' in settings.AUTHENTICATION_BACKENDS:
organization = request.site.organizations.first()
if organization:
UserOrganizationMapping.objects.get_or_create(user=user, organization=organization, is_active=False)

# Immediately after a user creates an account, we log them in. They are only
# logged in until they close the browser. They can't log in again until they click
# the activation link from the email.
new_user = authenticate(username=user.username, password=params['password'])
login(request, new_user)
request.session.set_expiry(0)

if not settings.APPSEMBLER_FEATURES.get('SKIP_LOGIN_AFTER_REGISTRATION', False):
login(request, new_user)
request.session.set_expiry(0)

try:
record_registration_attributions(request, new_user)
Expand Down
11 changes: 11 additions & 0 deletions lms/envs/aws_appsembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,14 @@
if 'LMS_AUTHENTICATION_BACKENDS' in APPSEMBLER_FEATURES.keys():
#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
# if it works, then also add the middleware
try:
from organizations.models import UserOrganizationMapping
MIDDLEWARE_CLASSES += (
'organizations.middleware.OrganizationMiddleware',
)
except ImportError:
pass

12 changes: 12 additions & 0 deletions lms/envs/devstack_appsembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,15 @@
if 'LMS_AUTHENTICATION_BACKENDS' in APPSEMBLER_FEATURES.keys():
#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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not specific to this PR at all. But we do need to DRY in the envs/*_appsembler.py files.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

# if it works, then also add the middleware
try:
from organizations.models import UserOrganizationMapping
MIDDLEWARE_CLASSES += (
'organizations.middleware.OrganizationMiddleware',
)
except ImportError:
pass