mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-25 12:18:44 +00:00
feat(api): implement read-only mode for reviewers controlled by REVIEWER_READ_ONLY env
This commit is contained in:
@@ -28,6 +28,23 @@ export const authMiddleware = createMiddleware<{
|
||||
}
|
||||
|
||||
c.set('user', user)
|
||||
|
||||
if (process.env.REVIEWER_READ_ONLY === '1') {
|
||||
const method = c.req.method.toUpperCase()
|
||||
if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(method)) {
|
||||
const member = await prisma.teamMember.findFirst({
|
||||
where: {
|
||||
userId: user.id,
|
||||
role: { in: ['owner', 'editor'] },
|
||||
},
|
||||
})
|
||||
|
||||
if (!member) {
|
||||
return c.json({ error: 'System is in read-only mode' }, 403)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await next()
|
||||
} catch {
|
||||
return c.json({ error: 'Authentication failed' }, 401)
|
||||
|
||||
Reference in New Issue
Block a user