diff --git a/client/modules/datafiles/src/projects/forms/_fields/AuthorSelect.tsx b/client/modules/datafiles/src/projects/forms/_fields/AuthorSelect.tsx index 796d101891..6e5c0d1bbd 100644 --- a/client/modules/datafiles/src/projects/forms/_fields/AuthorSelect.tsx +++ b/client/modules/datafiles/src/projects/forms/_fields/AuthorSelect.tsx @@ -23,7 +23,14 @@ export const AuthorSelect: React.FC<{ value?.some((v) => user.email === v.email)) + .filter((user) => + value?.some( + (v) => + (user.email || '') === (v.email || '') && + user.fname === v.fname && + user.lname === v.lname + ) + ) .map((v) => JSON.stringify(v) ?? [])} options={options} onChange={onChangeCallback} diff --git a/designsafe/apps/api/projects_v2/migration_utils/project_db_ingest.py b/designsafe/apps/api/projects_v2/migration_utils/project_db_ingest.py index b8ed38c96c..165f9a63eb 100644 --- a/designsafe/apps/api/projects_v2/migration_utils/project_db_ingest.py +++ b/designsafe/apps/api/projects_v2/migration_utils/project_db_ingest.py @@ -164,6 +164,47 @@ def get_complete_author(partial_author): meta.save() +def fix_guest_members(): + """Fix guest members if they have not been added to the overall users field""" + base_projects = ProjectMetadata.objects.filter(name="designsafe.project") + project_schema = SCHEMA_MAPPING["designsafe.project"] + count = 0 + for prj in base_projects: + existing_users = prj.value["users"] + legacy_guests = prj.value.get("guestMembers", []) + + if legacy_guests: + print(prj.project_id) + for guest in legacy_guests: + already_added = any( + ( + u + for u in existing_users + if ( + u["role"] == "guest" + and u["fname"] == guest["fname"] + and u["lname"] == guest["lname"] + and u.get("email", "") == guest.get("email", "") + ) + ) + ) + if not already_added: + prj.value["users"].append( + { + "role": "guest", + "inst": guest.get("inst", ""), + "fname": guest.get("fname", ""), + "lname": guest.get("lname", ""), + "email": guest.get("email", ""), + } + ) + project_schema.model_validate(prj.value) + + ProjectMetadata.objects.filter(uuid=prj.uuid).update(value=prj.value) + count += 1 + print(f"{count} projects migrated.") + + def fix_modified_dates(): """Set last_updated time to match existing metadata""" name = "designsafe.project"