Skip to content

Commit d3d4238

Browse files
committed
refactor: remove organization model retrieval from settings
1 parent e498015 commit d3d4238

7 files changed

Lines changed: 10 additions & 43 deletions

File tree

.annotation_safe_list.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ waffle.Switch:
4141
".. no_pii:": "This model has no PII"
4242
casbin_adapter.CasbinRule:
4343
".. no_pii:": "This model stores authorization policy rules and contains no PII"
44+
organizations.HistoricalOrganization:
45+
".. no_pii:": "Historical snapshot of organization metadata and contains no PII"
46+
organizations.HistoricalOrganizationCourse:
47+
".. no_pii:": "Historical relation between organizations and courses and contains no PII"

openedx_authz/api/data.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@
1111
from opaque_keys import InvalidKeyError
1212
from opaque_keys.edx.keys import CourseKey
1313
from opaque_keys.edx.locator import LibraryLocatorV2
14+
from organizations.models import Organization
1415

15-
from openedx_authz.models.scopes import (
16-
get_content_library_model,
17-
get_course_overview_model,
18-
get_organization_model,
19-
)
16+
from openedx_authz.models.scopes import get_content_library_model, get_course_overview_model
2017

2118
ContentLibrary = get_content_library_model()
2219
CourseOverview = get_course_overview_model()
23-
Organization = get_organization_model()
2420

2521
__all__ = [
2622
"ActionData",

openedx_authz/models/scopes.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,8 @@ def get_course_overview_model():
5050
return None
5151

5252

53-
def get_organization_model():
54-
"""Return the Organization model class specified by settings.
55-
56-
The setting `OPENEDX_AUTHZ_ORGANIZATION_MODEL` should be an
57-
app_label.ModelName string (e.g. 'organizations.Organization').
58-
"""
59-
ORGANIZATION_MODEL = getattr(
60-
settings,
61-
"OPENEDX_AUTHZ_ORGANIZATION_MODEL",
62-
"organizations.Organization",
63-
)
64-
try:
65-
app_label, model_name = ORGANIZATION_MODEL.split(".")
66-
return apps.get_model(app_label, model_name, require_ready=False)
67-
except LookupError:
68-
return None
69-
70-
7153
ContentLibrary = get_content_library_model()
7254
CourseOverview = get_course_overview_model()
73-
Organization = get_organization_model()
7455

7556

7657
class ContentLibraryScope(Scope):

openedx_authz/settings/common.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ def plugin_settings(settings):
5050
if not hasattr(settings, "OPENEDX_AUTHZ_COURSE_OVERVIEW_MODEL"):
5151
settings.OPENEDX_AUTHZ_COURSE_OVERVIEW_MODEL = "course_overviews.CourseOverview"
5252

53-
# Set default Organization model for swappable dependency
54-
if not hasattr(settings, "OPENEDX_AUTHZ_ORGANIZATION_MODEL"):
55-
settings.OPENEDX_AUTHZ_ORGANIZATION_MODEL = "organizations.Organization"
56-
5753
# Set default CASBIN_LOG_LEVEL if not already set.
5854
# This setting defines the logging level for the Casbin enforcer.
5955
if not hasattr(settings, "CASBIN_LOG_LEVEL"):

openedx_authz/settings/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def plugin_settings(settings): # pylint: disable=unused-argument
3838
"openedx_authz.engine.apps.CasbinAdapterConfig",
3939
"openedx_authz.apps.OpenedxAuthzConfig",
4040
"openedx_authz.tests.stubs.apps.StubsConfig",
41+
"organizations",
4142
)
4243

4344
MIDDLEWARE = [
@@ -77,4 +78,3 @@ def plugin_settings(settings): # pylint: disable=unused-argument
7778
# Use stub model for testing instead of the real content_libraries app
7879
OPENEDX_AUTHZ_CONTENT_LIBRARY_MODEL = "stubs.ContentLibrary"
7980
OPENEDX_AUTHZ_COURSE_OVERVIEW_MODEL = "stubs.CourseOverview"
80-
OPENEDX_AUTHZ_ORGANIZATION_MODEL = "stubs.Organization"

openedx_authz/tests/api/test_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ def test_get_org(self, external_key, expected_org):
761761
"""Test organization extraction from library glob pattern."""
762762
self.assertEqual(OrgContentLibraryGlobData.get_org(external_key), expected_org)
763763

764+
@patch("openedx_authz.api.data.Organization", Organization)
764765
def test_exists_true_when_org_exists(self):
765766
"""exists() returns True when the org exists."""
766767
org_name = "DemoX"
@@ -832,6 +833,7 @@ def test_get_org(self, external_key, expected_org):
832833
"""Test organization extraction from course glob pattern."""
833834
self.assertEqual(OrgCourseOverviewGlobData.get_org(external_key), expected_org)
834835

836+
@patch("openedx_authz.api.data.Organization", Organization)
835837
def test_exists_true_when_org_exists(self):
836838
"""exists() returns True when the org exists."""
837839
org_name = "OpenedX"

openedx_authz/tests/stubs/models.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,7 @@
1010
from opaque_keys.edx.django.models import CourseKeyField, UsageKeyField
1111
from opaque_keys.edx.keys import CourseKey
1212
from opaque_keys.edx.locator import LibraryLocatorV2
13-
14-
15-
class Organization(models.Model):
16-
"""Stub model representing an organization for testing purposes.
17-
18-
.. no_pii:
19-
"""
20-
21-
name = models.CharField(max_length=255)
22-
short_name = models.CharField(max_length=100)
23-
24-
def __str__(self):
25-
return str(self.name)
13+
from organizations.models import Organization
2614

2715

2816
class ContentLibraryManager(models.Manager):

0 commit comments

Comments
 (0)