fix(company): enforce workspace membership and roles via CompanyMembership instead of accepted Invitations
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- postgresql, typescript
- Área
- authentication, backend, databases
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- TypeScript
- Estrellas
- 2
- Forks
- 1
- Merge medio
- 6 min
- PR fusionados (30 d)
- 27
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de sumamakhan761/tryinstance
-
backend good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
sumamakhan761/tryinstance#65 ·
Los mantenedores suelen responder en 1 día
-
backend good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
sumamakhan761/tryinstance#64 ·
Los mantenedores suelen responder en 1 día
-
backend good first issue
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
sumamakhan761/tryinstance#63 ·
Los mantenedores suelen responder en 1 día
-
backend good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
sumamakhan761/tryinstance#62 ·
Los mantenedores suelen responder en 1 día
-
backend good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
sumamakhan761/tryinstance#60 ·
Los mantenedores suelen responder en 1 día
Todos los issues de sumamakhan761/tryinstance
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
makecindy/cindy#15342 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
kwitsch/claude-code-plugin-tooling#219 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
no-repo-link tool-submission
Dificultad 1/5 Menos de una hora Aptitud para principiantes 74/100
BraveOPotato/NoSignups#2618 ·
-
enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100