feat: visual access control in FlowEditor (read-only mode for viewers)

This commit is contained in:
2026-05-03 21:27:36 +05:00
parent ace515f18e
commit 0c19af34c3
4 changed files with 71 additions and 35 deletions
+17 -4
View File
@@ -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