1010"""
1111
1212import casbin
13+ import os
14+ from openedx_authz import ROOT_DIRECTORY
1315from django .core .management .base import BaseCommand
1416
1517from openedx_authz .engine .enforcer import enforcer as global_enforcer
@@ -40,13 +42,13 @@ def add_arguments(self, parser) -> None:
4042 parser .add_argument (
4143 "--policy-file-path" ,
4244 type = str ,
43- default = "openedx_authz/engine/config/authz.policy" ,
45+ default = None ,
4446 help = "Path to the Casbin policy file (supports CSV format with policies, roles, and action grouping)" ,
4547 )
4648 parser .add_argument (
4749 "--model-file-path" ,
4850 type = str ,
49- default = "openedx_authz/engine/config/model.conf" ,
51+ default = None ,
5052 help = "Path to the Casbin model configuration file" ,
5153 )
5254
@@ -63,13 +65,18 @@ def handle(self, *args, **options):
6365 Raises:
6466 CommandError: If the policy file is not found or loading fails.
6567 """
66- file_enforcer = casbin .Enforcer (
67- options ["model_file_path" ], options ["policy_file_path" ]
68- )
69- global_enforcer .set_watcher (
70- None
71- ) # Disable watcher during bulk load until it's optional
72- self .migrate_policies (file_enforcer , global_enforcer )
68+ policy_file_path , model_file_path = options ["policy_file_path" ], options ["model_file_path" ]
69+ if policy_file_path is None :
70+ policy_file_path = os .path .join (
71+ ROOT_DIRECTORY , "engine" , "config" , "authz.policy"
72+ )
73+ if model_file_path is None :
74+ model_file_path = os .path .join (
75+ ROOT_DIRECTORY , "engine" , "config" , "model.conf"
76+ )
77+
78+ source_enforcer = casbin .Enforcer (model_file_path , policy_file_path )
79+ self .migrate_policies (source_enforcer , global_enforcer )
7380
7481 def migrate_policies (self , source_enforcer , target_enforcer ):
7582 """Migrate policies from the source enforcer to the target enforcer.
0 commit comments