feat(api): allow search API in read-only mode

This commit is contained in:
yiling
2026-06-17 22:30:09 +08:00
parent d81fc275f4
commit f4276a19aa
2 changed files with 13 additions and 1 deletions
+11
View File
@@ -28,6 +28,7 @@ describe('authMiddleware', () => {
.use('*', authMiddleware)
.get('/test', (c) => c.text('ok'))
.post('/test', (c) => c.text('ok'))
.post('/test/search', (c) => c.text('ok'))
beforeEach(() => {
vi.resetAllMocks()
@@ -78,6 +79,16 @@ describe('authMiddleware', () => {
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 () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
vi.mocked(auth.api.getSession).mockResolvedValue({ user: { id: 'user1' } } as any)
+2 -1
View File
@@ -31,7 +31,8 @@ export const authMiddleware = createMiddleware<{
if (process.env.REVIEWER_READ_ONLY === '1') {
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({
where: {
userId: user.id,