2121from ansible_base .lib .abstract_models import AbstractOrganization , AbstractTeam , CommonModel
2222from ansible_base .lib .utils .auth import get_organization_model , get_team_model
2323from 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
2624
2725from .trigger_definition import TRIGGER_DEFINITION
2826
3230User = get_user_model ()
3331
3432
33+ is_rbac_installed = 'ansible_base.rbac' in settings .INSTALLED_APPS
34+
35+
3536class TriggerResult (Enum ):
3637 ALLOW = auto ()
3738 DENY = auto ()
@@ -722,7 +723,7 @@ def reconcile_user_claims(cls, user: AbstractUser, authenticator_user: Authentic
722723
723724 claims = getattr (user , 'claims' , authenticator_user .claims )
724725
725- if 'ansible_base.rbac' in settings . INSTALLED_APPS :
726+ if is_rbac_installed :
726727 cls (claims , user , authenticator_user ).manage_permissions ()
727728 else :
728729 logger .info (_ ("Skipping user claims with RBAC roles, because RBAC app is not installed" ))
@@ -876,7 +877,11 @@ class RoleUserAssignmentsCache:
876877 def __init__ (self ):
877878 self .cache = {}
878879 # 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 ()}
880+ self .content_types = {}
881+ if is_rbac_installed :
882+ from ansible_base .rbac .models import DABContentType
883+
884+ self .content_types = {content_type .model : content_type for content_type in DABContentType .objects .get_for_models (Organization , Team ).values ()}
880885 self .role_definitions = {}
881886
882887 def items (self ):
@@ -956,6 +961,12 @@ def cache_existing(self, role_assignments: Iterable[models.Model]) -> None:
956961 - All cached assignments are marked with STATUS_EXISTING status
957962 - Role definitions are also cached separately in self.role_definitions
958963 """
964+ local_resource_prefixes = ["shared" ]
965+ if is_rbac_installed :
966+ from ansible_base .rbac .remote import get_local_resource_prefix
967+
968+ local_resource_prefixes .append (get_local_resource_prefix ())
969+
959970 for role_assignment in role_assignments :
960971 # Cache role definition
961972 if (role_definition := self ._rd_by_id (role_assignment )) is None :
@@ -965,7 +976,7 @@ def cache_existing(self, role_assignments: Iterable[models.Model]) -> None:
965976 # Skip role assignments that should not be cached
966977 if not (
967978 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" ]
979+ or role_assignment .content_type .service in local_resource_prefixes
969980 ): # Local object roles
970981 continue
971982
0 commit comments