feat(members): allow owners to manage roles and remove members

This commit is contained in:
yiling
2026-06-07 15:28:05 +08:00
parent e0aa642549
commit 62a2cb3589
13 changed files with 404 additions and 31 deletions
+42
View File
@@ -9,6 +9,7 @@ import {
updateProjectRequestSchema,
listProjectsRequestSchema,
recentlyDeletedRequestSchema,
updateProjectMemberRoleRequestSchema,
} from '@shumai/dtos'
import { listMembersQuerySchema } from '@shumai/dtos'
import type { Prisma } from '@shumai/db'
@@ -244,5 +245,46 @@ const route = new Hono<{ Variables: { user: User } }>()
return c.body(null, 204)
})
.patch(
'/projects/:projectId/members/:userId',
zValidator('json', updateProjectMemberRoleRequestSchema),
async (c) => {
const user = c.get('user')
const projectId = c.req.param('projectId')
const userId = c.req.param('userId')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Project,
id: projectId,
})
await projectService.updateMemberRole({
projectId,
userId,
role: req.role,
})
return c.json({ success: true })
},
)
.delete('/projects/:projectId/members/:userId', async (c) => {
const user = c.get('user')
const projectId = c.req.param('projectId')
const userId = c.req.param('userId')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Project,
id: projectId,
})
await projectService.removeMember(projectId, userId)
return c.json({ success: true })
})
export default route
+42
View File
@@ -12,6 +12,7 @@ import {
listMembersQuerySchema,
updateSandboxSettingsRequestSchema,
updateMeRequestSchema,
updateTeamMemberRoleRequestSchema,
} from '@shumai/dtos'
import { updateUserMetadataRequestSchema } from '@shumai/dtos'
import type { Prisma } from '@shumai/db'
@@ -112,6 +113,47 @@ const route = new Hono<{ Variables: { user: User } }>()
return c.json(members)
})
.patch(
'/teams/:teamId/members/:userId',
zValidator('json', updateTeamMemberRoleRequestSchema),
async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
const userId = c.req.param('userId')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Team,
id: teamId,
})
await teamService.updateMemberRole({
teamId,
userId,
role: req.role,
})
return c.json({ success: true })
},
)
.delete('/teams/:teamId/members/:userId', async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
const userId = c.req.param('userId')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Team,
id: teamId,
})
await teamService.removeMember(teamId, userId)
return c.json({ success: true })
})
.get('/teams/:teamId/settings', async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')