FE-1566: Create avatar links in the web of the image they point at - #9499
FE-1566: Create avatar links in the web of the image they point at#9499claude[bot] wants to merge 3 commits into
Conversation
The web the link is created in decides who can see it. Deriving it from the uploaded file entity keeps a link in the same web as the image it points at.
Each link outside the web of the image it points at is archived and replaced by a link in that web, carrying the same endpoints, properties and public visibility. A link which already has a replacement is only archived, so the migration is safe to re-run.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 4 Skipped Deployments
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9499 +/- ##
=======================================
Coverage 61.03% 61.03%
=======================================
Files 1449 1450 +1
Lines 144693 144755 +62
Branches 6692 6700 +8
=======================================
+ Hits 88307 88356 +49
- Misses 55282 55291 +9
- Partials 1104 1108 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
PR SummaryMedium Risk Overview A startup migration 031 repairs existing links: for each user/org web it finds misplaced Has Avatar links (right entity in another web), creates a replacement in the image's web with the same endpoints, properties, draft state, and public-view policy when applicable, then archives the original. It runs per-web as each web's machine actor and skips creating a second replacement if one already exists, so re-runs stay safe. Reviewed by Cursor Bugbot for commit 832ccbb. Bugbot is set up for automated code reviews on this repo. Configure here. |
Requested by Ciaran Morinan · Slack thread
Before: an organization's avatar is visible only to the person who uploaded it. Every other member of the organization sees the empty "Click to upload" dropzone on the organization's settings page, and no image next to the organization's name elsewhere in the app.
After: every member of the organization sees the avatar. Avatars uploaded before this change are repaired the next time the API starts.
How: the avatar's Image File entity is created in the organization's web, but the
Has Avatarlink to it was created with nowebId.$webIdis optional in thecreateEntitymutation, soapps/hash-api/src/graphql/resolvers/knowledge/entity/entity.ts:115fell back towebId ?? user.accountIdand the link landed in the uploading user's own web, where no other member of the organization holds a role.apps/hash-frontend/src/shared/file-upload-context.tsx:497now passes the web of the file entity the link points at, so the link is created in the same web as the image. The links already stored are repaired by031-move-avatar-links-to-image-web.migration.ts, which walks every user and organization web as that web's machine actor, and for eachHas Avatarlink whose right entity sits in another web creates a replacement in that other web with the same left entity, right entity, properties and public-view policy, then archives the original. A link that already has a replacement is archived without a second replacement being created, so an interrupted run leaves no duplicate behind and the migration is safe to re-run.🔗 Related links
🔍 What does this change?
apps/hash-frontend/src/shared/file-upload-context.tsx:497passeswebIdto thecreateEntitymutation for the link entity, taken from the file entity the link points at.apps/hash-api/src/graph/ensure-system-graph-is-initialized/migrate-ontology-types/migrations/031-move-avatar-links-to-image-web.migration.tsruns the repair for theHas Avatarlink type.apps/hash-api/src/graph/ensure-system-graph-is-initialized/migrate-ontology-types/util/relocate-links.tsholds the repair itself, andutil.tsexportsrelocateLinksToRightEntityWeb, which iterates the webs. Both take the link type as a parameter, so a second link type can reuse them.Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
📜 Does this require a change to the docs?
The changes in this PR:
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
The resolver default is unchanged:
entity.ts:115still assigns a link entity touser.accountIdwhen the caller omitswebId. Only the avatar call site passes awebId, so any other caller that omits one still creates its link in the acting user's web.🐾 Next steps
Suggested follow-ups, none of them in this PR:
webIdto the left entity's web inentity.ts:115, which would cover every caller that omits it.Has Avatarlink's public-view policy from the UI.org-form.tsxanduse-update-profile-avatar.tsxomitlinkedEntityDatawhen the profile already has an avatar, sofile-upload-context.tsx:412returns before any link work and replacing an avatar cannot add a policy the link is missing.makePublicis true and an existing file entity is updated.apps/hash-api/src/graph/knowledge/system-types/file.ts:247and:435attach it only on the create branch. PassingmakePublic: truefromuse-update-profile-avatar.tsx:42, asorg-form.tsx:152does, would match the two call sites.apps/hash-frontend/src/lib/user-and-org.ts:194and:204instead of skipping an unreadable avatar link silently.🛡 What tests cover this?
No automated tests. ESLint and
oxfmtwere run against the four files and are clean.tsc --noEmitand the unit tests could not be run in the environment this branch was written in: both need the generated types from@blockprotocol/type-system, which come from awasm-packandcargo-instabuild driven bymise, and the downloads for those tools are blocked there. CI covers both.❓ How to test this?
yarn workspace @apps/hash-api start:migratetwice against a database holding an avatar link created before this branch. The first run moves the link into the image's web; the second makes no further change.