Skip to content
Closed
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
30 changes: 17 additions & 13 deletions common/djangoapps/student/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@
from six.moves.urllib.parse import urlencode
from slumber.exceptions import HttpClientError, HttpServerError
from user_util import user_util
from organizations.models import UserOrganizationMapping, OrganizationCourse
from organizations.models import OrganizationCourse

from tahoe_sites.api import (
deprecated_is_existing_email_but_not_linked_yet,
get_organization_user_by_email,
get_organization_user_by_username_or_email,
is_exist_organization_user_by_email,
)
from openedx.core.djangoapps.theming.helpers import (
get_current_request,
get_current_site,
Expand Down Expand Up @@ -331,14 +338,11 @@ def email_exists_or_retired(email, check_for_new_site=False):
"""
if settings.FEATURES.get('APPSEMBLER_MULTI_TENANT_EMAILS', False):
if check_for_new_site:
exists = User.objects.filter(
email=email,
userorganizationmapping__isnull=True, # Allow learners to signup for trial site, but ensure the trial
# workflow is completed.
).exists()
# Allow learners to signup for trial site, but ensure the trial workflow is completed.
exists = deprecated_is_existing_email_but_not_linked_yet(email=email)
else:
current_org = get_current_organization()
exists = current_org.userorganizationmapping_set.filter(user__email=email).exists()
exists = is_exist_organization_user_by_email(email=email, organization=current_org)
else:
exists = User.objects.filter(email=email).exists()
check_within_organization = not check_for_new_site # Allow existing learners to spin their new Tahoe trial
Expand Down Expand Up @@ -1630,9 +1634,9 @@ def enroll_by_email_in_organization(cls, email, course_id, mode=None, ignore_err
try:
site = get_current_site()
organization = get_organization_for_site(site)
user = organization.userorganizationmapping_set.get(user__email=email).user
user = get_organization_user_by_email(email=email, organization=organization)
return cls.enroll(user, course_id, mode)
except UserOrganizationMapping.DoesNotExist:
except User.DoesNotExist:
err_msg = u"Tried to enroll email {} into course {}, but user not found"
log.error(err_msg.format(email, course_id))
if ignore_errors:
Expand Down Expand Up @@ -2494,10 +2498,10 @@ def get_user_by_username_or_email_inside_organization(username_or_email):
# there should be one user with either username or email equal to username_or_email
site = get_current_site()
organization = get_organization_for_site(site)
try:
user = organization.userorganizationmapping_set.get(Q(user__email=username_or_email) | Q(user__username=username_or_email)).user
except UserOrganizationMapping.DoesNotExist:
raise User.DoesNotExist
user = get_organization_user_by_username_or_email(
username_or_email=username_or_email,
organization=organization
)

if user.username == username_or_email:
UserRetirementRequest = apps.get_model('user_api', 'UserRetirementRequest')
Expand Down
3 changes: 2 additions & 1 deletion common/djangoapps/student/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from opaque_keys.edx.keys import CourseKey
from pytz import UTC
from six import text_type
from tahoe_sites.api import is_exist_organization_user_by_email

import track.views
from bulk_email.models import Optout
Expand Down Expand Up @@ -753,7 +754,7 @@ def confirm_email_change(request, key):

if settings.FEATURES.get('APPSEMBLER_MULTI_TENANT_EMAILS', False):
current_org = get_current_organization()
email_exists = len(current_org.userorganizationmapping_set.filter(user__email=pec.new_email)) != 0
email_exists = is_exist_organization_user_by_email(email=pec.new_email, organization=current_org)
else:
email_exists = len(User.objects.filter(email=pec.new_email)) != 0

Expand Down
3 changes: 2 additions & 1 deletion common/djangoapps/third_party_auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from django.conf import settings
from django.contrib.auth.models import User
from tahoe_sites.api import is_exist_organization_user_by_email

from openedx.core.djangoapps.appsembler.sites.utils import get_current_organization

Expand Down Expand Up @@ -35,7 +36,7 @@ def user_exists(details):
current_org = get_current_organization()

if email:
return current_org.userorganizationmapping_set.filter(user__email=email).exists()
return is_exist_organization_user_by_email(email=email, organization=current_org)
elif username:
try:
user = User.objects.get(username=username)
Expand Down
3 changes: 2 additions & 1 deletion requirements/edx/appsembler.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ https://github.com/edx-solutions/xblock-google-drive/archive/589d9f51f9b.tar.gz

# Tahoe plugins and customizations
django-tiers==0.2.4
tahoe-sites==0.1.5
# tahoe-sites==0.1.5 plus new APIs
-e git+https://github.com/appsembler/tahoe-sites.git@2bffb54a96b469005d5f397a400b74a8af4d05db#egg=tahoe-sites==0.1.5-newapis
Comment on lines +25 to +26

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
# tahoe-sites==0.1.5 plus new APIs
-e git+https://github.com/appsembler/tahoe-sites.git@2bffb54a96b469005d5f397a400b74a8af4d05db#egg=tahoe-sites==0.1.5-newapis
tahoe-sites==0.1.6

tahoe-lti==0.3.0
site-configuration-client==0.1.3