Skip to content

Commit d51a1a4

Browse files
committed
feat: add IS_GLOB attribute in scope classes
1 parent 8cce705 commit d51a1a4

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

openedx_authz/api/data.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@
1212
from opaque_keys.edx.keys import CourseKey
1313
from opaque_keys.edx.locator import LibraryLocatorV2
1414

15-
try:
16-
from openedx.core.djangoapps.content_libraries.models import ContentLibrary
17-
except ImportError:
18-
ContentLibrary = None
15+
from openedx_authz.models.scopes import get_content_library_model, get_course_overview_model
1916

20-
try:
21-
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
22-
except ImportError:
23-
CourseOverview = None
17+
ContentLibrary = get_content_library_model()
18+
CourseOverview = get_course_overview_model()
2419

2520
__all__ = [
2621
"UserData",
@@ -381,6 +376,7 @@ class ScopeData(AuthZData, metaclass=ScopeMeta):
381376
# 2. Custom global scopes that don't map to specific domain objects (e.g., 'global:some_scope')
382377
# Subclasses like ContentLibraryData ('lib') represent concrete resource types with their own namespaces.
383378
NAMESPACE: ClassVar[str] = "global"
379+
IS_GLOB: ClassVar[bool] = False
384380

385381
@classmethod
386382
def validate_external_key(cls, _: str) -> bool:
@@ -558,6 +554,8 @@ class OrgLibraryGlobData(ContentLibraryData):
558554
a library scope with a wildcard is created.
559555
"""
560556

557+
IS_GLOB: ClassVar[bool] = True
558+
561559
@property
562560
def org(self) -> str | None:
563561
"""Get the organization identifier from the glob pattern.
@@ -779,6 +777,8 @@ class OrgCourseGlobData(CourseOverviewData):
779777
a course scope with a wildcard is created.
780778
"""
781779

780+
IS_GLOB: ClassVar[bool] = True
781+
782782
@property
783783
def org(self) -> str | None:
784784
"""Get the organization identifier from the glob pattern.

openedx_authz/models/scopes.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from opaque_keys.edx.keys import CourseKey
1212
from opaque_keys.edx.locator import LibraryLocatorV2
1313

14-
from openedx_authz.api.data import GLOBAL_SCOPE_WILDCARD, ScopeData
1514
from openedx_authz.models.core import Scope
1615

1716

@@ -82,7 +81,7 @@ class ContentLibraryScope(Scope):
8281
)
8382

8483
@classmethod
85-
def get_or_create_for_external_key(cls, scope: ScopeData) -> "ContentLibraryScope":
84+
def get_or_create_for_external_key(cls, scope) -> "ContentLibraryScope":
8685
"""Get or create a ContentLibraryScope for the given external key.
8786
8887
Args:
@@ -95,7 +94,7 @@ def get_or_create_for_external_key(cls, scope: ScopeData) -> "ContentLibraryScop
9594
"""
9695
# For glob scopes we don't create a Scope object since
9796
# they don't represent a specific content library
98-
if GLOBAL_SCOPE_WILDCARD in scope.external_key:
97+
if scope.IS_GLOB:
9998
return None
10099

101100
library_key = LibraryLocatorV2.from_string(scope.external_key)
@@ -131,7 +130,7 @@ class CourseScope(Scope):
131130
)
132131

133132
@classmethod
134-
def get_or_create_for_external_key(cls, scope: ScopeData) -> "CourseScope":
133+
def get_or_create_for_external_key(cls, scope) -> "CourseScope":
135134
"""Get or create a CourseScope for the given external key.
136135
137136
Args:
@@ -144,7 +143,7 @@ def get_or_create_for_external_key(cls, scope: ScopeData) -> "CourseScope":
144143
"""
145144
# For glob scopes we don't create a Scope object
146145
# since they don't represent a specific course
147-
if GLOBAL_SCOPE_WILDCARD in scope.external_key:
146+
if scope.IS_GLOB:
148147
return None
149148

150149
course_key = CourseKey.from_string(scope.external_key)

0 commit comments

Comments
 (0)