Repository navigation
feat: add a label to invitations - #334
Conversation
An invitation only shows its role and dates, so it's easy to send the wrong link. Add an optional label: plain text of one line, at most 100 characters. It's served to those who can list invitations only, never logged, and documented as possibly naming people. Closes #331 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Refuse labels that can't be stored (400 instead of 500) or that hide or reorder text, remove labels of accepted invitations with the user's roles, and state exactly how long labels are kept and when they can appear in logs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Reviewer's GuideIntroduces optional invitation labels with schema validation, normalized storage, manager-only visibility, privacy-preserving lifecycle cleanup, updated documentation, and comprehensive tests while preserving compatibility for unlabeled invitations. Sequence diagram for privacy-aware invitation labelssequenceDiagram
actor Owner
actor Invitee
participant Registry
participant Invitations
participant Permissions
Owner->>Registry: postServiceInvitation(label)
Registry->>Registry: check_strings(invitation)
Registry->>Invitations: Store invitation with label.strip()
Registry-->>Owner: Invitation with token
Owner->>Registry: getServiceInvitations()
Registry->>Invitations: Read invitations
Invitations-->>Registry: Invitation including label
Registry-->>Owner: Invitation with label
Invitee->>Registry: Accept invitation
Registry->>Invitations: Consume invitation
Registry-->>Invitee: Acceptance result without label
Permissions->>Invitations: _delete_roles()
Invitations->>Invitations: Remove label from accepted invitation
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #334 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 22 22
Lines 2368 2375 +7
=========================================
+ Hits 2368 2375 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cloud_registry/ga4gh/registry/permissions.py" line_range="621" />
<code_context>
get_collection(INVITATIONS).update_many(
{"service_id": serviceId, "accepted.user_id": subject},
- {"$unset": {"accepted.name": "", "accepted.email": ""}},
+ {"$unset": {"accepted.name": "", "accepted.email": "", "label": ""}},
)
</code_context>
<issue_to_address>
**Replaced roles retain invitation labels**
When an accepted user's role is replaced through invitation acceptance or `PUT /services/{serviceId}/permissions/{userId}`, `put_role()` replaces the existing role without calling `_delete_roles()`, so the accepted invitation's label remains stored and visible to invitation managers after the role is replaced.
Run accepted-invitation label cleanup whenever `put_role()` replaces an existing role, including both paths.
</issue_to_address>
### Comment 2
<location path="cloud_registry/ga4gh/registry/permissions.py" line_range="621" />
<code_context>
get_collection(INVITATIONS).update_many(
{"service_id": serviceId, "accepted.user_id": subject},
- {"$unset": {"accepted.name": "", "accepted.email": ""}},
+ {"$unset": {"accepted.name": "", "accepted.email": "", "label": ""}},
)
</code_context>
<issue_to_address>
**Failed cleanup leaves labels behind**
When the invitation update fails after `revoke_roles()` removes the user's role, `_delete_roles()` propagates the MongoDB error; a retry finds no role and skips cleanup, leaving the label stored and visible to managers until the invitation expires.
Make label cleanup retryable or compensate for its failure even after the role has been removed.
</issue_to_address>
### Comment 3
<location path="cloud_registry/ga4gh/registry/permissions.py" line_range="621" />
<code_context>
get_collection(INVITATIONS).update_many(
{"service_id": serviceId, "accepted.user_id": subject},
- {"$unset": {"accepted.name": "", "accepted.email": ""}},
+ {"$unset": {"accepted.name": "", "accepted.email": "", "label": ""}},
)
</code_context>
<issue_to_address>
**Concurrent acceptance loses label**
When an invitation acceptance claims the invitation, then a concurrent request revokes that user’s existing role before the acceptance request reaches `put_role()`, `_delete_roles()` unsets the label after revoking the invitee’s existing role, then the acceptance request’s `put_role()` can grant the invitee a role. The final state has a role but no label on its accepted invitation.
Coordinate acceptance and role revocation so label cleanup is consistent with the final role state.
</issue_to_address>
### Comment 4
<location path="cloud_registry/ga4gh/registry/invitations.py" line_range="195" />
<code_context>
"expires_at": format_time(invitation["expires_at"]),
}
+ if LABEL in invitation:
+ served[LABEL] = invitation[LABEL]
accepted = invitation.get(ACCEPTED)
if accepted is not None:
</code_context>
<issue_to_address>
**Revoked users’ labels can remain visible**
When an accepted invitation still has a stored label after its accepting user no longer has a role on the service, such as when cleanup failed, `_serve()` copies the label before checking whether the accepted user still has a role; its later filter removes only the accepted name and email. A stale label therefore remains visible in the invitation list after that user loses their role.
When serving an accepted invitation, omit its label if the accepted user is absent from the service’s user-role set.
</issue_to_address>
### Comment 5
<location path="cloud_registry/ga4gh/registry/invitations.py" line_range="357" />
<code_context>
"expires_at": created_at + timedelta(days=expiry_days),
}
+ if LABEL in invitation:
+ document[LABEL] = invitation[LABEL].strip()
collection = get_collection(INVITATIONS)
collection.insert_one(document)
</code_context>
<issue_to_address>
**Failed creation retains label**
When a process or dependency fails after the insert but before the post-insert checks complete, `postServiceInvitation()` has already inserted the labeled document when its post-insert service or creator recheck raises an unexpected exception. The request fails without returning the token, but the invitation and label remain stored until revoked or expired; a client retry creates another invitation.
Make failed creation recoverable by ensuring the inserted invitation is removed or reconciled when post-insert validation cannot complete.
</issue_to_address>Linked issues
#331 feat: add a label to invitations · 5 of 5 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Add an optional plain-text label of about 100 characters to InvitationRegister, Invitation and InvitationCreated. | ✅ Met | The OpenAPI schemas add the optional shared InvitationLabel schema, with text and length constraints, to all three invitation schemas. |
| 2 | Store and return the label; keep it optional so scripts and existing invitations keep working. | ✅ Met | Labels are stored and included in served invitations when present; invitations without labels remain without a label field. |
| 3 | Only people who can list a service's invitations see the label, not the person accepting. | ✅ Met | Labels are included in invitation creation and listing responses, but not acceptance responses; the added tests cover visibility. |
| 4 | Say in the docs that labels may name people and how long they are kept. | ✅ Met | The access-control docs describe that labels may name people and explain removal on revocation or invitation expiry, plus backup retention. |
| 5 | Update the API docs, access control docs and upgrade notes. | ✅ Met | The OpenAPI specification documents the label contract, and the access-control and upgrade documentation are updated. |
Sourcery assessment
Needs a human reviewer. 5 findings to address first, and a label may name a person, and rejected labels are quoted in the validation log, where reverting this change will not remove existing entries. Accepted labels are also stored with invitations and may remain in database backups after the invitation expires or is revoked.
Blocking findings: cloud_registry/ga4gh/registry/permissions.py:621, cloud_registry/ga4gh/registry/permissions.py:621, cloud_registry/ga4gh/registry/permissions.py:621, cloud_registry/ga4gh/registry/invitations.py:195, cloud_registry/ga4gh/registry/invitations.py:357
Also if removing the label failed when the role was revoked, as for the user's name and email address. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG
Summary
Invitations can carry an optional
label, so that owners can tell what a link is for and don't send the wrong one.labelinInvitationRegister,InvitationandInvitationCreated(shared schemaInvitationLabel): plain text, one line, not blank, at most 100 characters; no control or direction-changing characters, no unpaired surrogates; whitespace around it is removed.docs/reference.mdrenders the module's docstrings;docs/api.mdlists endpoints and problem codes only, and neither change.Closes #331
Verification
mkdocs build --strict: passed.helm dependency build deployment.tests/test_invitations.pywas rerun locally, not the full suite: 81 passed and 1 skipped on mongomock (100% coverage of the module), 82 passed on MongoDB 7.0, with the concurrency test. After the last two fixes, the label tests only (mongomock).Declined review findings
Open questions
None.
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG