Title: fix(webapp): don't apply an invite's role to an existing org member by claude[bot] · Pull Request #4409 · triggerdotdev/trigger.dev · GitHub
Open Graph Title: fix(webapp): don't apply an invite's role to an existing org member by claude[bot] · Pull Request #4409 · triggerdotdev/trigger.dev
X Title: fix(webapp): don't apply an invite's role to an existing org member by claude[bot] · Pull Request #4409 · triggerdotdev/trigger.dev
Description: Requested via Slack thread Summary Accepting an old invitation could change the role of someone who was already in the organization. A long-pending invite can carry a lower role than the member has since been promoted to, so accepting it was a silent demotion. When the accepting user was the organization's only Owner, the role layer refused that demotion, and the refusal (an expected, protective outcome) was logged as an error. An invitation now only sets a role on a membership the accept actually created, and people who are already in an organization are skipped when invitations are sent. How acceptInvite already skipped the OrgMember create when it found an existing membership, but the rbac.setUserRole call below it was gated only on invite.rbacRoleId. It now also tracks whether this accept created the membership. A create that loses the unique-constraint race counts as pre-existing, since whichever flow won it owns that membership's role. Skipping existing members outright would regress one case: a member with no RBAC role at all would never receive the invitation's role. ensureOrgMember handles that with healMissingRoleAssignment, which fills in a null role but never overwrites a real one, so assignInviteRbacRole takes the same gate. An established role is never touched; an absent one is filled in. assignInviteRbacRole branches on the result's machine-readable code instead of logging every refusal at error. last_owner goes to logger.info, matching the two directory-sync role paths; everything else, including a refusal that carries no code, goes to logger.warn. The helper is best-effort and never throws, so no outcome it produces warrants error. No string matching on the error text is involved. inviteMembers resolves the organization's members by email and skips those addresses before creating invites. The invite table's @@unique([organizationId, email]) only dedupes pending invites, so it could never catch this. Invite surfaces Skipping addresses means a batch can now come back empty, and neither caller handled that: The dashboard action built its redirect from invites[0].organization, so a batch where every address was skipped threw a TypeError that reached the admin as a raw error string. It also reported the submitted count rather than the created one. It now names what it skipped ("No invitations sent: 1 already a member of this organization") and counts what it actually created. The invites API derived alreadyInvited as "everything not created", so an existing member was reported as though they had already been invited. inviteMembers now returns the two groups separately and the endpoint reports alreadyMembers alongside alreadyInvited. Testing apps/webapp/test/member.server.test.ts passes 16/16 locally, up from 12. Getting there needed a harness fix. The ~/db.server mock did not export Prisma, so any code reaching PrismaNamespace.PrismaClientKnownRequestError threw before it could branch, leaving every duplicate-key path in member.server.ts unreachable from tests. The mock now re-exports the real Prisma, and there is a case covering the pending-invite skip. New cases: the invite role is applied when the accept creates the membership; it is not applied when the member already has a role; it is applied when an existing member has no role assigned; the organization is still joined when the assignment is refused with last_owner; and inviteMembers reports members separately from pending invites. Forcing the gate off fails exactly the "already has a role" case, so the coverage is load-bearing. pnpm run typecheck --filter webapp and oxfmt --check both pass. Changelog Accepting an old invitation could change the role of someone who was already in the organization. An invitation now leaves an existing member's role untouched, people who are already in an organization are no longer sent invitations to it, and the invite form says which addresses it skipped instead of failing with an unhelpful error. ✅ Checklist I have followed every step in the contributing guide The PR title follows the convention. I ran and tested the code works. Screenshots No visual changes. The invite form's toast copy changes, as described above.
Open Graph Description: Requested via Slack thread Summary Accepting an old invitation could change the role of someone who was already in the organization. A long-pending invite can carry a lower role than the member has...
X Description: Requested via Slack thread Summary Accepting an old invitation could change the role of someone who was already in the organization. A long-pending invite can carry a lower role than the member has...
Opengraph URL: https://github.com/triggerdotdev/trigger.dev/pull/4409
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:2873213e-d44e-c790-04fa-087efb9e661f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D75A:2884AC:69BF:9785:6AFB08A6 |
| html-safe-nonce | 216ed2531faaa8e066c5801b7827e06d0d82f2672667e38add817b5f218fa008 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzVBOjI4ODRBQzo2OUJGOjk3ODU6NkFGQjA4QTYiLCJ2aXNpdG9yX2lkIjoiOTAzNTYwMDQ2MjIyMDAzNjI2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 86e5b98b32c012723a92058fa8f021e9204254dccf4be3f792322a451d515bb7 |
| hovercard-subject-tag | pull_request:4152992743 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/triggerdotdev/trigger.dev/pull/4409/files |
| twitter:image | https://avatars.githubusercontent.com/in/1236702?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/in/1236702?s=400&v=4 |
| og:image:alt | Requested via Slack thread Summary Accepting an old invitation could change the role of someone who was already in the organization. A long-pending invite can carry a lower role than the member has... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 76fb13cb43f1834708971f45a9cfcab5df3177a7582086613d7cdc6e98c4bfde |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/triggerdotdev/trigger.dev git https://github.com/triggerdotdev/trigger.dev.git |
| octolytics-dimension-user_id | 95297378 |
| octolytics-dimension-user_login | triggerdotdev |
| octolytics-dimension-repository_id | 572570113 |
| octolytics-dimension-repository_nwo | triggerdotdev/trigger.dev |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 572570113 |
| octolytics-dimension-repository_network_root_nwo | triggerdotdev/trigger.dev |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | afc998826cdd963c8f91a96ae5372809ab5e296b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width