Skip to content

Commit

Permalink
Fix getting 404 on course preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulmanann committed Dec 3, 2024
1 parent 557077e commit 55b0d3d
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/views/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions common/djangoapps/student/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/course_wiki/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/courseware/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/instructor/views/instructor_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions openedx/features/edly/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55b0d3d

Please sign in to comment.