mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-05 15:44:28 +00:00
feat(api): allow search API in read-only mode
This commit is contained in:
@@ -28,6 +28,7 @@ describe('authMiddleware', () => {
|
|||||||
.use('*', authMiddleware)
|
.use('*', authMiddleware)
|
||||||
.get('/test', (c) => c.text('ok'))
|
.get('/test', (c) => c.text('ok'))
|
||||||
.post('/test', (c) => c.text('ok'))
|
.post('/test', (c) => c.text('ok'))
|
||||||
|
.post('/test/search', (c) => c.text('ok'))
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks()
|
vi.resetAllMocks()
|
||||||
@@ -78,6 +79,16 @@ describe('authMiddleware', () => {
|
|||||||
expect(await res.json()).toEqual({ error: 'System is in read-only mode' })
|
expect(await res.json()).toEqual({ error: 'System is in read-only mode' })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('allows POST /search for reviewer', async () => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
vi.mocked(auth.api.getSession).mockResolvedValue({ user: { id: 'user1' } } as any)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
vi.mocked(prisma.user.findUnique).mockResolvedValue({ id: 'user1' } as any)
|
||||||
|
|
||||||
|
const res = await app.request('/test/search', { method: 'POST' })
|
||||||
|
expect(res.status).toBe(200)
|
||||||
|
})
|
||||||
|
|
||||||
it('allows POST for owner', async () => {
|
it('allows POST for owner', async () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
vi.mocked(auth.api.getSession).mockResolvedValue({ user: { id: 'user1' } } as any)
|
vi.mocked(auth.api.getSession).mockResolvedValue({ user: { id: 'user1' } } as any)
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ export const authMiddleware = createMiddleware<{
|
|||||||
|
|
||||||
if (process.env.REVIEWER_READ_ONLY === '1') {
|
if (process.env.REVIEWER_READ_ONLY === '1') {
|
||||||
const method = c.req.method.toUpperCase()
|
const method = c.req.method.toUpperCase()
|
||||||
if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(method)) {
|
const path = c.req.path
|
||||||
|
if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(method) && !path.endsWith('/search')) {
|
||||||
const member = await prisma.teamMember.findFirst({
|
const member = await prisma.teamMember.findFirst({
|
||||||
where: {
|
where: {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user