Skip to content

Commit c5a7e91

Browse files
Merge pull request #208 from eduNEXT/MJG/fix-validate-org-async
fix: get settings course_org_filter when validating org for async proc
2 parents a40a5ab + d4987ca commit c5a7e91

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Backend for the CourseKey validations that works under the open-release/maple.master tag
5+
"""
6+
# pylint: disable=import-error, protected-access
7+
from __future__ import absolute_import, unicode_literals
8+
9+
from django.conf import settings
10+
from opaque_keys import InvalidKeyError
11+
from opaque_keys.edx.keys import CourseKey
12+
from rest_framework.serializers import ValidationError
13+
14+
try:
15+
from openedx.core.djangoapps.site_configuration.helpers import get_all_orgs, get_current_site_orgs
16+
except ImportError:
17+
get_all_orgs, get_current_site_orgs = object, object # pylint: disable=invalid-name
18+
19+
20+
def get_valid_course_key(course_id):
21+
"""
22+
Return the CourseKey if the course_id is valid
23+
"""
24+
try:
25+
return CourseKey.from_string(course_id)
26+
except InvalidKeyError:
27+
raise ValidationError(f"Invalid course_id {course_id}") from InvalidKeyError
28+
29+
30+
def validate_org(course_id):
31+
"""
32+
Validate the course organization against all possible orgs for the site
33+
34+
To determine if the Org is valid we must look at 3 things
35+
1 Orgs in the current site
36+
2 Orgs in other sites
37+
3 flag EOX_CORE_USER_ENABLE_MULTI_TENANCY
38+
"""
39+
40+
if not settings.EOX_CORE_USER_ENABLE_MULTI_TENANCY:
41+
return True
42+
43+
course_key = get_valid_course_key(course_id)
44+
course_org_filter = getattr(settings, "course_org_filter", [])
45+
course_org_filter = course_org_filter if isinstance(course_org_filter, list) else [course_org_filter]
46+
current_site_orgs = get_current_site_orgs() or course_org_filter or []
47+
48+
if not current_site_orgs: # pylint: disable=no-else-return
49+
if course_key.org in get_all_orgs():
50+
return False
51+
return True
52+
else:
53+
return course_key.org in current_site_orgs

eox_core/settings/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def plugin_settings(settings):
3838
settings.DATA_API_DEF_PAGE_SIZE = 1000
3939
settings.DATA_API_MAX_PAGE_SIZE = 5000
4040
settings.EOX_CORE_COURSES_BACKEND = "eox_core.edxapp_wrapper.backends.courses_h_v1"
41-
settings.EOX_CORE_COURSEKEY_BACKEND = "eox_core.edxapp_wrapper.backends.coursekey_h_v1"
41+
settings.EOX_CORE_COURSEKEY_BACKEND = "eox_core.edxapp_wrapper.backends.coursekey_m_v1"
4242
settings.EOX_CORE_SITE_CONFIGURATION = "eox_core.edxapp_wrapper.backends.site_configuration_h_v1"
4343
settings.EOX_CORE_COURSE_MANAGEMENT_REQUEST_TIMEOUT = 1000
4444
settings.EOX_CORE_USER_ENABLE_MULTI_TENANCY = True

0 commit comments

Comments
 (0)