From e45640ac2af589093afa7b715ee96b696443e162 Mon Sep 17 00:00:00 2001 From: Kyle Burton Date: Wed, 22 Jan 2025 10:36:35 -0600 Subject: [PATCH] Testing --- fence/sync/sync_users.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/fence/sync/sync_users.py b/fence/sync/sync_users.py index 5a11c4ac6..ffa1586a4 100644 --- a/fence/sync/sync_users.py +++ b/fence/sync/sync_users.py @@ -659,9 +659,13 @@ def _parse_csv(self, file_dict, sess, dbgap_config={}, encrypted=True): tags["pi"] = row["downloader for names"] user_info[username] = { - "email": row.get("email") or user_info[username].get('email') or "", + "email": row.get("email") + or user_info[username].get("email") + or "", "display_name": display_name, - "phone_number": row.get("phone") or user_info[username].get('phone_number') or "", + "phone_number": row.get("phone") + or user_info[username].get("phone_number") + or "", "tags": tags, } @@ -967,10 +971,10 @@ def sync_to_storage_backend(self, user_project, user_info, sess, expires): google_group_user_mapping = {} get_or_create_proxy_group_id( expires=expires, - user_id=user_info['user_id'], - username=user_info['username'], + user_id=user_info["user_id"], + username=user_info["username"], session=sess, - storage_manager=self.storage_manager + storage_manager=self.storage_manager, ) # TODO: eventually it'd be nice to remove this step but it's required @@ -987,14 +991,11 @@ def sync_to_storage_backend(self, user_project, user_info, sess, expires): for project, _ in projects.items(): syncing_user_project_list.add((username.lower(), project)) - to_add = set(syncing_user_project_list) # when updating users we want to maintain case sensitivity in the username so # pass the original, non-lowered user_info dict - self._upsert_userinfo(sess, { - user_info['username'].lower(): user_info - }) + self._upsert_userinfo(sess, {user_info["username"].lower(): user_info}) self._grant_from_storage( to_add, @@ -1473,6 +1474,7 @@ def _process_user_projects( dbgap_config, sess, ): + user_projects_to_modify = copy.deepcopy(user_projects) for username in user_projects.keys(): for project in user_projects[username].keys(): phsid = project.split(".") @@ -1509,7 +1511,7 @@ def _process_user_projects( privileges, username, sess, - user_projects, + user_projects_to_modify, dbgap_config, ) @@ -1520,9 +1522,12 @@ def _process_user_projects( privileges, username, sess, - user_projects, + user_projects_to_modify, dbgap_config, ) + for k, v in user_projects.items(): + if v != user_projects_to_modify[k]: + user_projects[k] = user_projects_to_modify[k] def sync(self): if self.session: @@ -2485,8 +2490,8 @@ def sync_single_user_visas(self, user, ga4gh_visas, sess=None, expires=None): projects = {**projects, **project} parsed_visas.append(visa) - info['user_id'] = user.id - info['username'] = user.username + info["user_id"] = user.id + info["username"] = user.username user_projects[user.username] = projects user_projects = self.parse_projects(user_projects) @@ -2511,9 +2516,7 @@ def sync_single_user_visas(self, user, ga4gh_visas, sess=None, expires=None): if user_projects: self.logger.info("Sync to storage backend [sync_single_user_visas]") - self.sync_to_storage_backend( - user_projects, info, sess, expires=expires - ) + self.sync_to_storage_backend(user_projects, info, sess, expires=expires) else: self.logger.info("No users for syncing")