feat: visual access control in FlowEditor (read-only mode for viewers)
This commit is contained in:
@@ -11,10 +11,23 @@ export default defineEventHandler(async (event) => {
|
||||
const existing = await prisma.canvas.findUnique({ where: { id } })
|
||||
if (!existing) throw createError({ statusCode: 404, message: 'Canvas not found' })
|
||||
|
||||
// Allow if owner, or if admin, or if canvas is public (for collaborative editing)
|
||||
if (existing.ownerId !== user.id && user.role !== 'admin' && !existing.isPublic) {
|
||||
console.log('[DEBUG 403]', { ownerId: existing.ownerId, userId: user.id, userRole: user.role, isPublic: existing.isPublic })
|
||||
throw createError({ statusCode: 403, message: 'Access denied' })
|
||||
// 1. Проверка прав
|
||||
let canEdit = existing.ownerId === user.id || user.role === 'admin' || existing.isPublic
|
||||
|
||||
if (!canEdit && existing.groupId) {
|
||||
const membership = await prisma.groupMember.findUnique({
|
||||
where: {
|
||||
userId_groupId: { userId: user.id, groupId: existing.groupId }
|
||||
}
|
||||
})
|
||||
// Редакторы и админы группы могут править
|
||||
if (membership && (membership.role === 'admin' || membership.role === 'editor')) {
|
||||
canEdit = true
|
||||
}
|
||||
}
|
||||
|
||||
if (!canEdit) {
|
||||
throw createError({ statusCode: 403, message: 'У вас недостаточно прав для редактирования этой карты' })
|
||||
}
|
||||
|
||||
const { name, nodes, edges, isPublic, groupId } = body
|
||||
|
||||
Reference in New Issue
Block a user