Skip to content

Commit

Permalink
improve guest author selection and add script to fix legacy guest aut…
Browse files Browse the repository at this point in the history
…hors (#1411)
  • Loading branch information
jarosenb authored Aug 21, 2024
1 parent 4dcee2d commit 04b30a8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ export const AuthorSelect: React.FC<{
<Checkbox.Group
style={{ flexDirection: 'column' }}
value={projectUsers
.filter((user) => 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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 04b30a8

Please sign in to comment.