diff --git a/cms/djangoapps/contentstore/views/library.py b/cms/djangoapps/contentstore/views/library.py index a8b59a04e939..1d2cc16411b1 100644 --- a/cms/djangoapps/contentstore/views/library.py +++ b/cms/djangoapps/contentstore/views/library.py @@ -276,7 +276,7 @@ def manage_library_users(request, library_key_string): if not user_perms & STUDIO_VIEW_USERS: raise PermissionDenied() site = request.site - if not is_course_org_same_as_site_org(site, library_key, is_studio=True): + if not is_course_org_same_as_site_org(site, library_key): raise PermissionDenied() library = modulestore().get_library(library_key) if library is None: diff --git a/cms/djangoapps/contentstore/views/user.py b/cms/djangoapps/contentstore/views/user.py index b6f98f07c2ac..54f59bab8129 100644 --- a/cms/djangoapps/contentstore/views/user.py +++ b/cms/djangoapps/contentstore/views/user.py @@ -80,7 +80,7 @@ def _manage_users(request, course_key): if not user_perms & STUDIO_VIEW_USERS: raise PermissionDenied() site = request.site - if not is_course_org_same_as_site_org(site, course_key, is_studio=True): + if not is_course_org_same_as_site_org(site, course_key): raise PermissionDenied() course_module = modulestore().get_course(course_key) diff --git a/common/djangoapps/student/auth.py b/common/djangoapps/student/auth.py index d838ede39ec5..76f3ab3f9517 100644 --- a/common/djangoapps/student/auth.py +++ b/common/djangoapps/student/auth.py @@ -120,7 +120,7 @@ def has_studio_write_access(user, course_key): request = get_current_request() site = getattr(request, 'site', None) - if course_key and site and not is_course_org_same_as_site_org(site, course_key, is_studio=True): + if course_key and site and not is_course_org_same_as_site_org(site, course_key): return False return bool(STUDIO_EDIT_CONTENT & get_user_permissions(user, course_key)) @@ -144,7 +144,7 @@ def has_studio_read_access(user, course_key): request = get_current_request() site = getattr(request, 'site', None) - if course_key and site and not is_course_org_same_as_site_org(site, course_key, is_studio=True): + if course_key and site and not is_course_org_same_as_site_org(site, course_key): return False return bool(STUDIO_VIEW_CONTENT & get_user_permissions(user, course_key)) diff --git a/lms/djangoapps/course_wiki/views.py b/lms/djangoapps/course_wiki/views.py index febe8d4c45c5..5fceea0cbd20 100644 --- a/lms/djangoapps/course_wiki/views.py +++ b/lms/djangoapps/course_wiki/views.py @@ -42,7 +42,8 @@ def course_wiki_redirect(request, course_id, wiki_path=""): example, "/6.002x") to keep things simple. """ course_key = CourseKey.from_string(course_id) - if not is_course_org_same_as_site_org(request.site, course_key): + site = getattr(request, 'site', None) + if course_key and site and not is_course_org_same_as_site_org(site, course_key): raise Http404(u"Course not found: {}.".format(six.text_type(course_key))) course = get_course_by_id(course_key) diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index 893a493e65c0..d81136f37749 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -128,7 +128,8 @@ def get_course_with_access(user, action, course_key, depth=0, check_if_enrolled= be plugged in as additional callback checks for different actions. """ request = get_current_request() - if not is_course_org_same_as_site_org(request.site, course_key): + site = getattr(request, 'site', None) + if course_key and site and not is_course_org_same_as_site_org(site, course_key): raise Http404(u"Course not found: {}.".format(six.text_type(course_key))) course = get_course_by_id(course_key, depth) diff --git a/lms/djangoapps/instructor/views/instructor_dashboard.py b/lms/djangoapps/instructor/views/instructor_dashboard.py index 6bfa982a5607..7d7eb43a6cb8 100644 --- a/lms/djangoapps/instructor/views/instructor_dashboard.py +++ b/lms/djangoapps/instructor/views/instructor_dashboard.py @@ -113,7 +113,8 @@ def instructor_dashboard_2(request, course_id): log.error(u"Unable to find course with course key %s while loading the Instructor Dashboard.", course_id) return HttpResponseServerError() - if not is_course_org_same_as_site_org(request.site, course_key): + site = getattr(request, 'site', None) + if course_key and site and not is_course_org_same_as_site_org(site, course_key): raise Http404(u"Course not found: {}.".format(six.text_type(course_key))) course = get_course_by_id(course_key, depth=0) diff --git a/openedx/features/edly/utils.py b/openedx/features/edly/utils.py index 729b53ead561..09b4f2f2f88b 100644 --- a/openedx/features/edly/utils.py +++ b/openedx/features/edly/utils.py @@ -522,15 +522,16 @@ def get_marketing_link(marketing_urls, name): return '' -def is_course_org_same_as_site_org(site, course_id, is_studio=False): +def is_course_org_same_as_site_org(site, course_id): """ Check if the course organization matches with the site organization. """ try: - if is_studio: - edly_sub_org = EdlySubOrganization.objects.get(studio_site=site) - else: - edly_sub_org = EdlySubOrganization.objects.get(lms_site=site) + edly_sub_org = EdlySubOrganization.objects.get( + Q(lms_site=site) | + Q(studio_site=site) | + Q(preview_site=site) + ) except EdlySubOrganization.DoesNotExist: LOGGER.info('No Edly sub organization found for site %s', site) return False