File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222from openedx_authz .api .permissions import get_permission_from_policy
2323from openedx_authz .engine .enforcer import AuthzEnforcer
2424
25-
2625__all__ = [
2726 "get_permissions_for_single_role" ,
2827 "get_permissions_for_roles" ,
Original file line number Diff line number Diff line change 33"""
44
55from django .apps import AppConfig
6- from django .core .exceptions import ImproperlyConfigured
76
87
98class OpenedxAuthzConfig (AppConfig ):
@@ -40,10 +39,3 @@ class OpenedxAuthzConfig(AppConfig):
4039 },
4140 },
4241 }
43-
44- def ready (self ):
45- """Initialization layer for the openedx_authz app."""
46- # DO NOT initialize the enforcer here to avoid issues when
47- # apps are not fully loaded (e.g., while pulling translations).
48- # It's best to lazy load the enforcer when needed it's first used.
49- pass
Original file line number Diff line number Diff line change 1+ """Initialization for the casbin_adapter Django application.
2+
3+ This overrides the default AppConfig to avoid making queries to the database
4+ when the app is not fully loaded (e.g., while pulling translations). Moved
5+ the initialization of the enforcer to a lazy load when it's first used.
6+
7+ See openedx_authz/engine/enforcer.py for the enforcer implementation.
8+ """
9+
110from django .apps import AppConfig
2- from django .conf import settings
3- from django .core .exceptions import ImproperlyConfigured
411
512
613class CasbinAdapterConfig (AppConfig ):
714 name = "casbin_adapter"
815
916 def ready (self ):
10- """Initialization layer for the casbin_adapter app."""
17+ """Initialize the casbin_adapter app."""
1118 # DO NOT initialize the enforcer here to avoid issues when
1219 # apps are not fully loaded (e.g., while pulling translations).
1320 # It's best to lazy load the enforcer when needed it's first used.
14- pass
Original file line number Diff line number Diff line change 1919import logging
2020
2121from casbin import FastEnforcer
22+ from casbin_adapter .enforcer import initialize_enforcer
2223from django .conf import settings
2324
2425from openedx_authz .engine .adapter import ExtendedAdapter
2526from openedx_authz .engine .watcher import Watcher
26- from casbin_adapter .enforcer import initialize_enforcer
2727
2828logger = logging .getLogger (__name__ )
2929
@@ -86,7 +86,7 @@ def _initialize_enforcer() -> FastEnforcer:
8686 # Best to lazy load it when it's first used to ensure the database is ready and avoid
8787 # issues when the app is not fully loaded (e.g., while pulling translations, etc.).
8888 initialize_enforcer (db_alias )
89- except Exception as e : # pylint: disable=broad-exception-caught
89+ except Exception as e :
9090 logger .error (f"Failed to initialize Casbin enforcer with DB alias '{ db_alias } ': { e } " )
9191 raise
9292
Original file line number Diff line number Diff line change 1616from openedx_authz .engine .utils import migrate_policy_between_enforcers
1717
1818
19-
2019class Command (BaseCommand ):
2120 """Django management command to load policies into the authorization Django model.
2221
Original file line number Diff line number Diff line change 3535from openedx_authz .engine .utils import migrate_policy_between_enforcers
3636
3737
38-
3938class BaseRolesTestCase (TestCase ):
4039 """Base test case with helper methods for roles testing.
4140
You can’t perform that action at this time.
0 commit comments