Skip to content

Commit 8d4a394

Browse files
committed
Further simplifications of the code mainline
1 parent aa51e41 commit 8d4a394

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

ansible_base/rbac/claims.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def get_user_object_roles(user: Model) -> QuerySet:
5353

5454

5555
def _resolve_team_organization_references(
56-
team_ansible_ids: set[str],
5756
object_arrays: dict[str, list],
5857
org_ansible_id_to_index: dict[str, int],
5958
) -> None:
@@ -65,7 +64,6 @@ def _resolve_team_organization_references(
6564
arrays, it will be added.
6665
6766
Args:
68-
team_ansible_ids: Set of team ansible_ids that need organization mapping
6967
object_arrays: Dictionary with model_type -> list of objects (will be modified)
7068
org_ansible_id_to_index: Maps organization ansible_id -> array_position (will be modified)
7169
@@ -74,6 +72,9 @@ def _resolve_team_organization_references(
7472
- Adds missing organizations to object_arrays['organization'] if needed
7573
- Updates org_ansible_id_to_index mappings for any added organizations
7674
"""
75+
# Extract team ansible_ids from the team objects
76+
team_ansible_ids = {team_data['ansible_id'] for team_data in object_arrays['team']}
77+
7778
if not team_ansible_ids:
7879
return
7980

@@ -89,7 +90,7 @@ def _resolve_team_organization_references(
8990
team_org_mapping[team_ansible_id] = {'ansible_id': org_ansible_id, 'name': org_name}
9091

9192
# Update team objects with organization references
92-
for team_data in object_arrays.get('team', []):
93+
for team_data in object_arrays['team']:
9394
team_ansible_id = team_data['ansible_id']
9495
org_info = team_org_mapping.get(team_ansible_id)
9596

@@ -137,11 +138,10 @@ def _build_objects_and_roles(
137138
# Internal tracking for ansible_id to array position mapping
138139
ansible_id_to_index = defaultdict(dict) # { <model_type>: {<ansible_id>: <array_position> } }
139140

140-
# Collect team ansible_ids that need organization mapping
141-
team_ansible_ids = set()
141+
role_assignments = get_user_object_roles(user)
142142

143143
# Single loop: build object_arrays and object_roles
144-
for assignment in get_user_object_roles(user):
144+
for assignment in role_assignments:
145145
role_name = assignment.rd_name
146146
ansible_id = str(assignment.aid)
147147
resource_name = str(assignment.resource_name)
@@ -152,18 +152,12 @@ def _build_objects_and_roles(
152152
if model_type not in object_arrays:
153153
object_arrays[model_type] = []
154154

155-
# Collect team ansible_ids for organization resolution
156-
if model_type == 'team':
157-
team_ansible_ids.add(ansible_id)
158-
159155
# If the ansible_id is not yet indexed
160156
if ansible_id not in ansible_id_to_index[model_type]:
161157
# Cache the array position (current len will be the next index when we append)
162158
ansible_id_to_index[model_type][ansible_id] = len(object_arrays[model_type])
163-
# Add the object to the array (without org reference for teams yet)
159+
# Add the object to the array
164160
object_data = {'ansible_id': ansible_id, 'name': resource_name}
165-
if model_type == 'team':
166-
object_data['org'] = None # Will be resolved later
167161
object_arrays[model_type].append(object_data)
168162

169163
# Get the array position from the cache
@@ -177,7 +171,7 @@ def _build_objects_and_roles(
177171
object_roles[role_name]['objects'].append(array_position)
178172

179173
# Resolve team organization references
180-
_resolve_team_organization_references(team_ansible_ids, object_arrays, ansible_id_to_index['organization'])
174+
_resolve_team_organization_references(object_arrays, ansible_id_to_index['organization'])
181175

182176
return object_arrays, object_roles
183177

0 commit comments

Comments
 (0)