mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 10:06:35 +00:00
feat(project): support adding existing team members and prioritize project-specific roles
This commit is contained in:
@@ -196,4 +196,54 @@ describe('project api', () => {
|
||||
})
|
||||
expect(assetService.emptyTrash).toHaveBeenCalledWith('p1')
|
||||
})
|
||||
|
||||
it('POST /projects/:projectId/members', async () => {
|
||||
vi.mocked(projectService.addProjectMember).mockResolvedValue(undefined)
|
||||
|
||||
const res = await app.request('/projects/p1/members', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ userId: 'user2', role: 'editor' }),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json).toEqual({ success: true })
|
||||
expect(authzService.hasPermission).toHaveBeenCalledWith({
|
||||
user: expect.anything(),
|
||||
permission: Permission.Admin,
|
||||
type: ResourceType.Project,
|
||||
id: 'p1',
|
||||
})
|
||||
expect(projectService.addProjectMember).toHaveBeenCalledWith({
|
||||
projectId: 'p1',
|
||||
userId: 'user2',
|
||||
role: 'editor',
|
||||
})
|
||||
})
|
||||
|
||||
it('GET /projects/:projectId/me', async () => {
|
||||
vi.mocked(projectService.getProjectMe).mockResolvedValue({
|
||||
id: 'user1',
|
||||
name: 'Test User',
|
||||
role: 'editor',
|
||||
})
|
||||
|
||||
const res = await app.request('/projects/p1/me')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const json = await res.json()
|
||||
expect(json).toEqual({
|
||||
id: 'user1',
|
||||
name: 'Test User',
|
||||
role: 'editor',
|
||||
})
|
||||
expect(authzService.hasPermission).toHaveBeenCalledWith({
|
||||
user: expect.anything(),
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Project,
|
||||
id: 'p1',
|
||||
})
|
||||
expect(projectService.getProjectMe).toHaveBeenCalledWith('p1', 'user1')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
listProjectsRequestSchema,
|
||||
recentlyDeletedRequestSchema,
|
||||
updateProjectMemberRoleRequestSchema,
|
||||
addProjectMemberRequestSchema,
|
||||
} from '@shumai/dtos'
|
||||
import { listMembersQuerySchema } from '@shumai/dtos'
|
||||
import type { Prisma } from '@shumai/db'
|
||||
@@ -301,5 +302,44 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
|
||||
return c.json({ success: true })
|
||||
})
|
||||
.post(
|
||||
'/projects/:projectId/members',
|
||||
zValidator('json', addProjectMemberRequestSchema),
|
||||
async (c) => {
|
||||
const user = c.get('user')
|
||||
const projectId = c.req.param('projectId')
|
||||
const req = c.req.valid('json')
|
||||
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Admin,
|
||||
type: ResourceType.Project,
|
||||
id: projectId,
|
||||
})
|
||||
|
||||
await projectService.addProjectMember({
|
||||
projectId,
|
||||
userId: req.userId,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
role: req.role as any,
|
||||
})
|
||||
|
||||
return c.json({ success: true })
|
||||
},
|
||||
)
|
||||
.get('/projects/:projectId/me', async (c) => {
|
||||
const user = c.get('user')
|
||||
const projectId = c.req.param('projectId')
|
||||
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Project,
|
||||
id: projectId,
|
||||
})
|
||||
|
||||
const me = await projectService.getProjectMe(projectId, user.id)
|
||||
return c.json(me)
|
||||
})
|
||||
|
||||
export default route
|
||||
|
||||
Reference in New Issue
Block a user