21
21
from ansible_base .lib .abstract_models import AbstractOrganization , AbstractTeam , CommonModel
22
22
from ansible_base .lib .utils .auth import get_organization_model , get_team_model
23
23
from ansible_base .lib .utils .string import is_empty
24
- from ansible_base .rbac .models import DABContentType
25
- from ansible_base .rbac .remote import get_local_resource_prefix
26
24
27
25
from .trigger_definition import TRIGGER_DEFINITION
28
26
@@ -876,7 +874,10 @@ class RoleUserAssignmentsCache:
876
874
def __init__ (self ):
877
875
self .cache = {}
878
876
# NOTE(cutwater): We may probably execute this query once and cache the query results.
879
- self .content_types = {content_type .model : content_type for content_type in DABContentType .objects .get_for_models (Organization , Team ).values ()}
877
+ self .content_types = {}
878
+ if 'ansible_base.rbac' in settings .INSTALLED_APPS :
879
+ from ansible_base .rbac .models import DABContentType
880
+ self .content_types = {content_type .model : content_type for content_type in DABContentType .objects .get_for_models (Organization , Team ).values ()}
880
881
self .role_definitions = {}
881
882
882
883
def items (self ):
@@ -956,6 +957,11 @@ def cache_existing(self, role_assignments: Iterable[models.Model]) -> None:
956
957
- All cached assignments are marked with STATUS_EXISTING status
957
958
- Role definitions are also cached separately in self.role_definitions
958
959
"""
960
+ local_resource_prefixes = ["shared" ]
961
+ if 'ansible_base.rbac' in settings .INSTALLED_APPS :
962
+ from ansible_base .rbac .remote import get_local_resource_prefix
963
+ local_resource_prefixes .append (get_local_resource_prefix ())
964
+
959
965
for role_assignment in role_assignments :
960
966
# Cache role definition
961
967
if (role_definition := self ._rd_by_id (role_assignment )) is None :
@@ -965,7 +971,7 @@ def cache_existing(self, role_assignments: Iterable[models.Model]) -> None:
965
971
# Skip role assignments that should not be cached
966
972
if not (
967
973
role_assignment .content_type is None # Global/system roles (e.g., System Auditor)
968
- or role_assignment .content_type .service in [ get_local_resource_prefix (), "shared" ]
974
+ or role_assignment .content_type .service in local_resource_prefixes
969
975
): # Local object roles
970
976
continue
971
977
0 commit comments