1818from django .db .utils import Error , IntegrityError
1919from requests import HTTPError
2020
21- from ansible_base .rbac . models . role import AssignmentBase , RoleDefinition , RoleTeamAssignment , RoleUserAssignment
21+ from ansible_base .lib . utils . apps import is_rbac_installed
2222from ansible_base .resource_registry .models import Resource , ResourceType
2323from ansible_base .resource_registry .models .service_identifier import service_id
2424from ansible_base .resource_registry .registry import get_registry
@@ -139,7 +139,9 @@ def fetch_manifest(
139139 return [ManifestItem (** row ) for row in csv_reader ]
140140
141141
142- def get_ansible_id_or_pk (assignment : AssignmentBase ) -> str :
142+ def get_ansible_id_or_pk (assignment ) -> str :
143+ if not is_rbac_installed ():
144+ raise RuntimeError ("get_ansible_id_or_pk requires ansible_base.rbac to be installed" )
143145 # For object-scoped assignments, try to get the object's ansible_id
144146 if assignment .content_type .model in ('organization' , 'team' ):
145147 object_resource = Resource .objects .filter (object_id = assignment .object_id , content_type__model = assignment .content_type .model ).first ()
@@ -153,7 +155,9 @@ def get_ansible_id_or_pk(assignment: AssignmentBase) -> str:
153155 return str (ansible_id_or_pk )
154156
155157
156- def get_content_object (role_definition : RoleDefinition , assignment_tuple : AssignmentTuple ) -> Any :
158+ def get_content_object (role_definition , assignment_tuple : AssignmentTuple ) -> Any :
159+ if not is_rbac_installed ():
160+ raise RuntimeError ("get_content_object requires ansible_base.rbac to be installed" )
157161 content_object = None
158162 if role_definition .content_type .model in ('organization' , 'team' ):
159163 object_resource = Resource .objects .get (ansible_id = assignment_tuple .ansible_id_or_pk )
@@ -238,6 +242,10 @@ def get_remote_assignments(api_client: ResourceAPIClient) -> set[AssignmentTuple
238242
239243def get_local_assignments () -> set [AssignmentTuple ]:
240244 """Get local assignments and convert to tuples."""
245+ if not is_rbac_installed ():
246+ raise RuntimeError ("get_local_assignments requires ansible_base.rbac to be installed" )
247+ from ansible_base .rbac .models .role import RoleTeamAssignment , RoleUserAssignment
248+
241249 assignments = set ()
242250
243251 # Get user assignments
@@ -294,6 +302,10 @@ def get_local_assignments() -> set[AssignmentTuple]:
294302
295303def delete_local_assignment (assignment_tuple : AssignmentTuple ) -> bool :
296304 """Delete a local assignment based on the tuple."""
305+ if not is_rbac_installed ():
306+ raise RuntimeError ("delete_local_assignment requires ansible_base.rbac to be installed" )
307+ from ansible_base .rbac .models .role import RoleDefinition
308+
297309 try :
298310 role_definition = RoleDefinition .objects .get (name = assignment_tuple .role_definition_name )
299311
@@ -320,6 +332,10 @@ def delete_local_assignment(assignment_tuple: AssignmentTuple) -> bool:
320332
321333def create_local_assignment (assignment_tuple : AssignmentTuple ) -> bool :
322334 """Create a local assignment based on the tuple."""
335+ if not is_rbac_installed ():
336+ raise RuntimeError ("create_local_assignment requires ansible_base.rbac to be installed" )
337+ from ansible_base .rbac .models .role import RoleDefinition
338+
323339 try :
324340 role_definition = RoleDefinition .objects .get (name = assignment_tuple .role_definition_name )
325341
@@ -694,6 +710,10 @@ def _sync_assignments(self):
694710 if not self .sync_assignments :
695711 return
696712
713+ if not is_rbac_installed ():
714+ self .write (">>> Skipping role assignments sync (rbac not installed)" )
715+ return
716+
697717 self .write (">>> Syncing role assignments" )
698718
699719 try :
0 commit comments