mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 01:47:36 +00:00
refactor(authz): move to domain-based authz and flatten routes
This commit is contained in:
+18
-4
@@ -7,7 +7,7 @@ import {
|
||||
localUploadQuerySchema,
|
||||
} from '@/dtos/upload'
|
||||
import { paginationParamsSchema } from '@/dtos/pagination'
|
||||
import { authzService, Permission } from '@/services/authz/authz'
|
||||
import { authzService, Permission, ResourceType } from '@/services/authz/authz'
|
||||
import { notificationService } from '@/services/notification/notification'
|
||||
import { NotificationType } from '@/generated/prisma/client'
|
||||
import { s3Service, verifyLocalUrlSignature } from '@/services/s3/s3'
|
||||
@@ -48,9 +48,17 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
return c.json({ success: true })
|
||||
})
|
||||
.get('/teams/:teamId/upload/tasks', zValidator('query', paginationParamsSchema), async (c) => {
|
||||
const teamId = c.req.param('teamId')
|
||||
const user = c.get('user')
|
||||
const params = c.req.valid('query')
|
||||
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Read,
|
||||
type: ResourceType.Team,
|
||||
id: teamId,
|
||||
})
|
||||
|
||||
const tasks = await uploadService.listUploadTasks(user.id, params)
|
||||
return c.json(tasks)
|
||||
})
|
||||
@@ -58,15 +66,14 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
'/teams/:teamId/upload/tasks',
|
||||
zValidator('json', createUploadTaskRequestSchema),
|
||||
async (c) => {
|
||||
const teamId = c.req.param('teamId')
|
||||
const user = c.get('user')
|
||||
const req = c.req.valid('json')
|
||||
|
||||
await authzService.hasPermission({
|
||||
teamId,
|
||||
assetId: req.parentId,
|
||||
user,
|
||||
permission: Permission.Edit,
|
||||
type: ResourceType.Asset,
|
||||
id: req.parentId,
|
||||
})
|
||||
|
||||
const resp = await uploadService.createUploadTask(user.id, req)
|
||||
@@ -82,6 +89,13 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
const user = c.get('user')
|
||||
const req = c.req.valid('json')
|
||||
|
||||
await authzService.hasPermission({
|
||||
user,
|
||||
permission: Permission.Edit,
|
||||
type: ResourceType.Team,
|
||||
id: teamId,
|
||||
})
|
||||
|
||||
await uploadService.confirmFileUpload(user.id, taskId, req)
|
||||
|
||||
if (!req.errorMessage) {
|
||||
|
||||
Reference in New Issue
Block a user