diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index a332d2f96292..a513894c3f9a 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -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, @@ -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 @@ -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: @@ -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') diff --git a/common/djangoapps/student/views/management.py b/common/djangoapps/student/views/management.py index ad4e8cd1ecc1..57a869e7ca80 100644 --- a/common/djangoapps/student/views/management.py +++ b/common/djangoapps/student/views/management.py @@ -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 @@ -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 diff --git a/common/djangoapps/third_party_auth/utils.py b/common/djangoapps/third_party_auth/utils.py index 4462aa350968..0d9554d1df57 100644 --- a/common/djangoapps/third_party_auth/utils.py +++ b/common/djangoapps/third_party_auth/utils.py @@ -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 @@ -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) diff --git a/requirements/edx/appsembler.txt b/requirements/edx/appsembler.txt index 683c37089ab8..c1f31d044d88 100644 --- a/requirements/edx/appsembler.txt +++ b/requirements/edx/appsembler.txt @@ -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 tahoe-lti==0.3.0 site-configuration-client==0.1.3