Skip to content

feat: add a label to invitations - #334

Merged
uniqueg merged 4 commits into
devfrom
feat/invitation-label
Nov 3, 2026
Merged

uniqueg merged 4 commits into
devfrom
feat/invitation-label

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Summary

Invitations can carry an optional label, so that owners can tell what a link is for and don't send the wrong one.

  • label in InvitationRegister, Invitation and InvitationCreated (shared schema InvitationLabel): plain text, one line, not blank, at most 100 characters; no control or direction-changing characters, no unpaired surrogates; whitespace around it is removed.
  • Optional: scripts and stored invitations keep working, and invitations without one have no such field. Whether a client requires it is up to the client.
  • Served only to those who can list the invitations, not to the user who accepts it; the registry doesn't log it.
  • Removed with the invitation, and from accepted invitations when the user's roles on the service are revoked (they may name that user, and accepted invitations can't be revoked).
  • Docs: access control (labels may name people, how long they are kept, when they can appear in logs) and upgrade notes. docs/reference.md renders the module's docstrings; docs/api.md lists endpoints and problem codes only, and neither change.

Closes #331

Verification

  • Pre-commit, all hooks (ruff, semgrep, gitleaks, actionlint, ast-grep, mypy): passed on the final commit.
  • mkdocs build --strict: passed.
  • Full suite on the first commit: 100% coverage on mongomock, and the only failures on mongomock and MongoDB 7.0 were 265 tests that need the chart dependency, which hadn't been built. Those 265 passed after helm dependency build deployment.
  • After the review fixes, only tests/test_invitations.py was 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).
  • CI on the final commit, the full suite included: all checks passed, including Test (mongomock), Test (MongoDB 7.0), Chart, Docs, Smoke test, Scan image and codecov.
  • Sourcery reviewed; its five threads are answered and resolved (two fixed, three declined with reasons). Copilot posted no review within 15 minutes.

Declined review findings

  • FOCA logs rejected values (medium): a label refused by schema validation is quoted in FOCA's log message at INFO, as any rejected request value is. This is documented rather than changed; moving validation into the controller would hide the constraints from the API spec, and the proper fix belongs in FOCA.
  • Other invisible characters (low): soft hyphen, U+FFF9 and fillers such as U+3164 still pass, so a label can look blank. Only owners and admins create and see labels, and joiners must stay allowed for names in some scripts.

Open questions

None.

🤖 Generated with Claude Code

https://claude.ai/code/session_011FSoqMUX3EU35poH13xMgG

uniqueg and others added 3 commits November 3, 2026 03:18
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
@sourcery-ai

sourcery-ai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Introduces 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 labels

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Add an optional, privacy-aware invitation label across the API and storage model.
  • Define the shared label schema with length, text-safety, and non-blank validation rules.
  • Accept labels when creating invitations, trim surrounding whitespace, and omit the field for unlabeled records.
  • Return labels only from invitation listing/creation flows available to managers, while keeping them out of acceptance responses.
  • Remove labels when invitations are deleted or when roles for accepted invitees are revoked.
cloud_registry/api/additions.openapi.yaml
cloud_registry/ga4gh/registry/invitations.py
cloud_registry/ga4gh/registry/permissions.py
Document label visibility, privacy, retention, and upgrade behavior.
  • Explain label usage, access restrictions, sanitization, logging behavior, and lifecycle in access-control documentation.
  • Document backward-compatible upgrades and the optional response field.
docs/access-control.md
docs/upgrading.md
Add comprehensive invitation-label coverage and test support.
  • Extend invitation test helpers to pass arbitrary request fields.
  • Cover validation, trimming, Unicode handling, optional-field compatibility, visibility, logging, retention, and service renames.
tests/test_invitations.py

Possibly linked issues

  • feat: add a label to invitations #331: The PR implements the issue’s requested optional invitation labels, storage, restricted visibility, retention behavior, and documentation updates.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9a6dc48) to head (91e6a91).
⚠️ Report is 1 commits behind head on dev.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 3, 2026 02:47

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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
@uniqueg
uniqueg merged commit 92f990a into dev Nov 3, 2026
32 checks passed
@uniqueg
uniqueg deleted the feat/invitation-label branch November 3, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add a label to invitations

1 participant