fix(company): enforce workspace membership and roles via CompanyMembership instead of accepted Invitations
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- postgresql, typescript
調査の方向性
Start with packages/prisma/schema.prisma and the listed methods in apps/api/src/company/company.service.ts; trace how workspace creation, invite acceptance, account listing, switching, role updates, and removal use membership data. Review the migration and existing tests for those flows. Done means CompanyMembership is authoritative, removed members cannot regain access, and demoted roles remain in effect after switching workspaces.
索引モデルが issue の本文から書いたものです。
説明
Problem Description
In apps/api/src/company/company.service.ts, workspace access and roles during multi-workspace switching rely on historical accepted Invitation records:
-
Removed members can rejoin:
removeTeamMemberclearsuser.companyId = nulland resetsuser.role = 'VIEWER', but does not delete or revoke the user's acceptedInvitationrows. BecausegetUserAccountsandswitchAccountauthorize access to any company matchinginvitations: { some: { email: userEmail, acceptedAt: { not: null } } }, a removed member can still see the workspace and callPOST /api/accounts/switchto rejoin. -
Demoted members can escalate their role:
updateTeamMemberRoleupdatesuser.role, but leaves the acceptedInvitation.roleunchanged. WhenswitchAccountruns, it setstargetRole = company.invitations[0].role, allowing a demoted member (e.g.,ADMIN -> VIEWER) to restore their originalADMINrole viaPOST /api/accounts/switch.
Expected Behavior
- Workspace membership and per-workspace roles must have a single, authoritative source of truth (
CompanyMembership). Invitationrecords must only represent pending/consumed invites and must never be used to authorizegetUserAccountsorswitchAccountor to determine a user's active role.- Removing a member must immediately revoke their workspace access across all endpoints; demoting a member must persist across workspace switches.
Where to Look
packages/prisma/schema.prisma(User,Company,Invitation)apps/api/src/company/company.service.ts(getUserAccounts,switchAccount,updateTeamMemberRole,removeTeamMember,acceptInvitation)
Solution / Implementation Guide (Recommended Enterprise Plan)
-
Add
CompanyMembershipmodel (packages/prisma/schema.prisma):- Create
CompanyMembershipwith{ id, userId, companyId, role, createdAt, updatedAt },@@unique([userId, companyId]), andonDelete: Cascaderelations toUserandCompany. - Backfill existing
User.companyId+User.roleand valid activeInvitationrelationships in the Prisma migration.
- Create
-
Use
CompanyMembershipas the single source of truth (company.service.ts):- Accepting an invite / creating a company: Upsert a
CompanyMembershiprow for(userId, companyId, role)when a user creates a workspace or accepts anInvitation. getUserAccounts&switchAccount: QueryCompanyMembershipforuserId(instead ofinvitations) to list accessible workspaces and resolvetargetRolefrommembership.role.updateTeamMemberRole: UpdateCompanyMembership.role(anduser.roleifuser.companyId === companyId) inside a transaction.removeTeamMember: Delete theCompanyMembershiprow for(userId, companyId)(and clearuser.companyId/ resetuser.roleif that was their active workspace).
- Accepting an invite / creating a company: Upsert a
- 主要言語
- TypeScript
- スター
- 2
- フォーク
- 1
- 平均マージ
- 6分
- マージ済み PR(30日)
- 27
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
sumamakhan761/tryinstance のほかの issue
-
backend good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
sumamakhan761/tryinstance#65 ·
メンテナーはふだん 1 日以内に返信
-
backend good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
sumamakhan761/tryinstance#64 ·
メンテナーはふだん 1 日以内に返信
-
backend good first issue
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
sumamakhan761/tryinstance#63 ·
メンテナーはふだん 1 日以内に返信
-
backend good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
sumamakhan761/tryinstance#62 ·
メンテナーはふだん 1 日以内に返信
-
backend good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
sumamakhan761/tryinstance#60 ·
メンテナーはふだん 1 日以内に返信
sumamakhan761/tryinstance の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
makecindy/cindy#15342 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
kwitsch/claude-code-plugin-tooling#219 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
no-repo-link tool-submission
難易度 1/5 1時間未満 初心者へのやさしさ 74/100
BraveOPotato/NoSignups#2618 ·
-
enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100