Skip to content

Commit 3d577ab

Browse files
committed
can't set primary for groups not assigned
1 parent cda1683 commit 3d577ab

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

user_sync/engine/sign.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,18 +348,21 @@ def resolvePrimaryGroupAndGroupAdminState(self, is_umg, groups_to_update, assign
348348
raise AssertionException(f"Can't identify a primary group for user '{sign_user.email}'")
349349

350350
if current_pg is None or desired_pg.lower() != current_pg:
351-
self.logger.debug(f"Primary group of '{sign_user.email}' is '{desired_pg}'")
352351
if desired_pg.lower() in groups_to_update.keys():
353352
groups_to_update[desired_pg.lower()].isPrimaryGroup = True
354353
else:
355354
group_info = assigned_groups.get(desired_pg.lower())
356-
groups_to_update[desired_pg.lower()] = UserGroupInfo(
357-
id=group_info.id,
358-
name=group_info.name,
359-
isGroupAdmin=group_info.isGroupAdmin,
360-
isPrimaryGroup=True,
361-
status='ACTIVE',
362-
)
355+
if group_info is None:
356+
self.logger.warn(f"'{desired_pg}' must be assigned to user {sign_user.email} if designated the primary group")
357+
else:
358+
groups_to_update[desired_pg.lower()] = UserGroupInfo(
359+
id=group_info.id,
360+
name=group_info.name,
361+
isGroupAdmin=group_info.isGroupAdmin,
362+
isPrimaryGroup=True,
363+
status='ACTIVE',
364+
)
365+
self.logger.debug(f"Primary group of '{sign_user.email}' is '{desired_pg}'")
363366

364367
for group in desired_groups:
365368
group_info = assigned_groups.get(group)

0 commit comments

Comments
 (0)