Skip to content

Commit

Permalink
Handle empty fields in usersync _parse_csv() (#1098)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulineribeyre authored May 18, 2023
1 parent 525be0d commit f5a9ee4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
17 changes: 9 additions & 8 deletions fence/sync/sync_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,16 @@ def _parse_csv(self, file_dict, sess, dbgap_config={}, encrypted=True):
) as f:
csv = DictReader(f, quotechar='"', skipinitialspace=True)
for row in csv:
username = row.get("login", "")
username = row.get("login") or ""
if username == "":
continue

phsid_privileges = {}
if dbgap_config.get("allow_non_dbGaP_whitelist", False):
phsid = row.get("phsid", row.get("project_id", "")).split(".")
phsid = (
row.get("phsid") or (row.get("project_id") or "")
).split(".")
else:
phsid = row.get("phsid", "").split(".")
phsid = (row.get("phsid") or "").split(".")

dbgap_project = phsid[0]
# There are issues where dbgap has a wrong entry in their whitelist. Since we do a bulk arborist request, there are wrong entries in it that invalidates the whole request causing other correct entries not to be added
Expand Down Expand Up @@ -620,8 +621,8 @@ def _parse_csv(self, file_dict, sess, dbgap_config={}, encrypted=True):

dbgap_project += "." + consent_code

display_name = row.get("user name", "")
tags = {"dbgap_role": row.get("role", "")}
display_name = row.get("user name") or ""
tags = {"dbgap_role": row.get("role") or ""}

# some dbgap telemetry files have information about a researchers PI
if "downloader for" in row:
Expand All @@ -632,9 +633,9 @@ def _parse_csv(self, file_dict, sess, dbgap_config={}, encrypted=True):
tags["pi"] = row["downloader for names"]

user_info[username] = {
"email": row.get("email", ""),
"email": row.get("email") or "",
"display_name": display_name,
"phone_number": row.get("phone", ""),
"phone_number": row.get("phone") or "",
"tags": tags,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ USER F,USERF,eRA,PI,helloF@com,"123-456-789",active,phs000178.v9.p8.c1,"General
USER F,USERF,eRA,PI,helloF@com,"123-456-789",active,phs000178.v9.p8.c2,"General Research Use",2013-03-19 12:32:12.600,2015-05-14 16:01:16.923,2016-05-14 00:00:00.000,
USER B,TESTUSERB,eRA,PI,helloB@com,"123-456-789",active,phs000178.v9.p8.c1,"General Research Use",2013-03-19 12:32:12.600,2015-05-14 16:01:16.923,2016-05-14 00:00:00.000,
USER C,USERC,eRA,PI,helloC@com,"123-456-789",active,phs000178.v9.p8.c999,"General Research Use",2013-03-19 12:32:12.600,2015-05-14 16:01:16.923,2016-05-14 00:00:00.000,
EMPTY_PHSID,EMPTY_PHSID,eRA,PI,helloC@com,"123-456-789",active

0 comments on commit f5a9ee4

Please sign in to comment.