77from  django .conf  import  settings 
88from  django .db .models  import  F , Model , OuterRef , QuerySet 
99
10- from  ansible_base .lib .utils .auth  import  get_organization_model ,  get_team_model 
10+ from  ansible_base .lib .utils .auth  import  get_team_model 
1111
1212from  .models .content_type  import  DABContentType 
1313from  .models .role  import  RoleDefinition 
@@ -55,7 +55,7 @@ def get_user_object_roles(user: Model) -> QuerySet:
5555def  _resolve_team_organization_references (
5656    team_ansible_ids : set [str ],
5757    object_arrays : dict [str , list ],
58-     ansible_id_to_index :  defaultdict [str , dict ],
58+     org_ansible_id_to_index :  dict [str , int ],
5959) ->  None :
6060    """Resolve team organization references by converting ansible_ids to array positions. 
6161
@@ -67,19 +67,16 @@ def _resolve_team_organization_references(
6767    Args: 
6868        team_ansible_ids: Set of team ansible_ids that need organization mapping 
6969        object_arrays: Dictionary with model_type -> list of objects (will be modified) 
70-         ansible_id_to_index : Maps model_type ->  ansible_id -> array_position (will be modified) 
70+         org_ansible_id_to_index : Maps organization  ansible_id -> array_position (will be modified) 
7171
72-     The method modifies object_arrays and ansible_id_to_index  in place: 
72+     The method modifies object_arrays and org_ansible_id_to_index  in place: 
7373    - Updates team objects' 'org' field from ansible_id to array position 
7474    - Adds missing organizations to object_arrays['organization'] if needed 
75-     - Updates ansible_id_to_index  mappings for any added organizations 
75+     - Updates org_ansible_id_to_index  mappings for any added organizations 
7676    """ 
7777    if  not  team_ansible_ids :
7878        return 
7979
80-     # Get organization model type name 
81-     org_model_name  =  DABContentType .objects .get_for_model (get_organization_model ()).model 
82- 
8380    # Query team model to get team -> organization mappings with organization names 
8481    team_cls  =  get_team_model ()
8582    team_org_mapping  =  {}
@@ -101,17 +98,17 @@ def _resolve_team_organization_references(
10198            org_name  =  org_info ['name' ]
10299
103100            # Ensure the organization is in our arrays 
104-             if  org_ansible_id  not  in   ansible_id_to_index [ org_model_name ] :
101+             if  org_ansible_id  not  in   org_ansible_id_to_index :
105102                # Add missing organization using data from the query 
106-                 if  org_model_name  not  in   object_arrays :
107-                     object_arrays [org_model_name ] =  []
108-                 org_index  =  len (object_arrays [org_model_name ])
109-                 ansible_id_to_index [ org_model_name ] [org_ansible_id ] =  org_index 
103+                 if  'organization'  not  in   object_arrays :
104+                     object_arrays ['organization' ] =  []
105+                 org_index  =  len (object_arrays ['organization' ])
106+                 org_ansible_id_to_index [org_ansible_id ] =  org_index 
110107                org_data  =  {'ansible_id' : org_ansible_id , 'name' : org_name }
111-                 object_arrays [org_model_name ].append (org_data )
108+                 object_arrays ['organization' ].append (org_data )
112109
113110            # Set the organization reference to the array position 
114-             team_data ['org' ] =  ansible_id_to_index [ org_model_name ] [org_ansible_id ]
111+             team_data ['org' ] =  org_ansible_id_to_index [org_ansible_id ]
115112
116113
117114def  _build_objects_and_roles (
@@ -180,7 +177,7 @@ def _build_objects_and_roles(
180177        object_roles [role_name ]['objects' ].append (array_position )
181178
182179    # Resolve team organization references 
183-     _resolve_team_organization_references (team_ansible_ids , object_arrays , ansible_id_to_index )
180+     _resolve_team_organization_references (team_ansible_ids , object_arrays , ansible_id_to_index [ 'organization' ] )
184181
185182    return  object_arrays , object_roles 
186183
0 commit comments