Skip to content

Commit 3cc13cd

Browse files
Nishant Varshnayadorton-adobe
authored andcommitted
changes for non umg changes
1 parent bc6721c commit 3cc13cd

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

user_sync/engine/sign.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def update_sign_users(self, directory_users, sign_connector: SignConnector, org_
236236
else:
237237
desired_groups = set([self.get_primary_group(sign_user, self.sign_user_groups[org_name]).name.lower()])
238238
if not is_umg:
239-
desired_groups = set([directory_user['sign_roups'][0].group_name.lower()])
239+
desired_groups = set([directory_user['sign_groups'][0].group_name.lower()])
240240

241241
groups_to_update = {}
242242
admin_groups = set([g.group_name for g in directory_user['admin_groups'] if g.umapi_name == org_name])
@@ -248,7 +248,7 @@ def update_sign_users(self, directory_users, sign_connector: SignConnector, org_
248248
if group_info is None:
249249
raise AssertionException(f"'{group_name}' isn't a valid Sign group")
250250

251-
is_group_admin = ((not is_umg and directory_user['is_admin_group'])
251+
is_group_admin = ((not is_umg and directory_user['is_group_admin'])
252252
or (group_name in admin_groups))
253253
groups_to_update[group_name] = UserGroupInfo(
254254
id=group_info.groupId,
@@ -257,6 +257,8 @@ def update_sign_users(self, directory_users, sign_connector: SignConnector, org_
257257
isPrimaryGroup=False,
258258
status='ACTIVE',
259259
)
260+
if not is_umg:
261+
groups_to_update[group_name].isPrimaryGroup=True
260262
self.logger.info(f"Assigning group '{group_info.groupName}' to user {sign_user.email}")
261263
if group_name in admin_groups:
262264
self.logger.info(f"Assigning group admin privileges to user {sign_user.email} for group '{group_info.groupName}'")
@@ -309,21 +311,23 @@ def update_sign_users(self, directory_users, sign_connector: SignConnector, org_
309311
)
310312

311313
# figure out primary group for user
312-
sign_groups = set([g.lower() for g in groups_to_update.keys()])\
313-
.union(set([g.lower() for g in assigned_groups.keys()]))
314-
desired_pg = self.resolve_primary_group(sign_groups)
315-
current_pg = [g.name.lower() for g in assigned_groups.values() if g.isPrimaryGroup]
316-
if current_pg:
317-
current_pg = current_pg[0]
318-
else:
319-
current_pg = None
314+
if is_umg:
315+
sign_groups = set([g.lower() for g in groups_to_update.keys()])\
316+
.union(set([g.lower() for g in assigned_groups.keys()]))
317+
desired_pg = self.resolve_primary_group(sign_groups)
318+
current_pg = [g.name.lower() for g in assigned_groups.values() if g.isPrimaryGroup]
319+
if current_pg:
320+
current_pg = current_pg[0]
321+
else:
322+
current_pg = None
320323

321-
if desired_pg is None:
322-
raise AssertionException(f"Can't identify a primary group for user '{sign_user.email}'")
324+
if desired_pg is None:
325+
raise AssertionException(f"Can't identify a primary group for user '{sign_user.email}'")
326+
327+
if current_pg is None or desired_pg.lower() != current_pg:
328+
self.logger.debug(f"Primary group of '{sign_user.email}' is '{desired_pg}'")
329+
groups_to_update[desired_pg.lower()].isPrimaryGroup = True
323330

324-
if current_pg is None or desired_pg.lower() != current_pg:
325-
self.logger.debug(f"Primary group of '{sign_user.email}' is '{desired_pg}'")
326-
groups_to_update[desired_pg.lower()].isPrimaryGroup = True
327331

328332
if groups_to_update:
329333
group_update_data = UserGroupsInfo(groupInfoList=list(groups_to_update.values()))
@@ -518,11 +522,16 @@ def insert_new_users(self, org_name: str, sign_connector: SignConnector, directo
518522
status='ACTIVE',
519523
)
520524
self.logger.info(f"{self.org_string(sign_connector.console_org)}Assigning '{new_user.email}' to group '{group_to_assign.groupName}', group admin?: {wants_group_admin}")
521-
primary_group = self.resolve_primary_group(groups_to_assign.keys())
522-
if primary_group is None:
523-
raise AssertionException(f"Can't identify a primary group for user '{new_user.email}'")
524-
self.logger.debug(f"Primary group of '{new_user.email}' is '{primary_group}'")
525-
groups_to_assign[primary_group.lower()].isPrimaryGroup = True
525+
if is_umg:
526+
primary_group = self.resolve_primary_group(groups_to_assign.keys())
527+
if primary_group is None:
528+
raise AssertionException(f"Can't identify a primary group for user '{new_user.email}'")
529+
self.logger.debug(f"Primary group of '{new_user.email}' is '{primary_group}'")
530+
groups_to_assign[primary_group.lower()].isPrimaryGroup = True
531+
else:
532+
group_to_assign = self.sign_groups[org_name][groups[0].group_name.lower()]
533+
self.logger.debug(f"Primary group of '{new_user.email}' is '{group_to_assign.groupName.lower()}'")
534+
groups_to_assign[group_to_assign.groupName.lower()].isPrimaryGroup = True
526535
user_id = sign_connector.insert_user(new_user)
527536
self.sign_users_created.add(directory_user['email'])
528537
self.logger.info(f"{self.org_string(sign_connector.console_org)}Inserted sign user '{new_user.email}', admin?: {new_user.isAccountAdmin}")

0 commit comments

Comments
 (0)