mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 09:36:08 +00:00
feat(comments): enhance comment deletion permissions to allow project owners and admins to delete any comment
This commit is contained in:
@@ -276,18 +276,22 @@ export async function DELETE(request: NextRequest, { params }: RouteParams) {
|
|||||||
return apiErrors.notFound('Comment');
|
return apiErrors.notFound('Comment');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const project = comment.version.video.project;
|
||||||
const userId = session?.user?.id ?? null;
|
const userId = session?.user?.id ?? null;
|
||||||
const isAuthor = !!userId && comment.authorId === userId;
|
const isAuthor = !!userId && comment.authorId === userId;
|
||||||
|
|
||||||
let canDeleteOwnComment = isAuthor;
|
// Project owners/admins and workspace admins can delete any comment
|
||||||
if (!userId) {
|
const access = userId ? await checkProjectAccess(project, userId, { intent: 'manage' }) : null;
|
||||||
|
const isPrivilegedUser = !!access?.canEdit;
|
||||||
|
|
||||||
|
let canDelete = isAuthor || isPrivilegedUser;
|
||||||
|
if (!canDelete && !userId) {
|
||||||
const guestIdentityId = getGuestIdentityFromRequest(request);
|
const guestIdentityId = getGuestIdentityFromRequest(request);
|
||||||
const isGuestAuthor = !comment.authorId
|
const isGuestAuthor = !comment.authorId
|
||||||
&& !!comment.guestIdentityId
|
&& !!comment.guestIdentityId
|
||||||
&& guestIdentityId === comment.guestIdentityId;
|
&& guestIdentityId === comment.guestIdentityId;
|
||||||
|
|
||||||
if (isGuestAuthor) {
|
if (isGuestAuthor) {
|
||||||
const project = comment.version.video.project;
|
|
||||||
const shareSession = getShareSessionFromRequest(request, comment.version.video.id);
|
const shareSession = getShareSessionFromRequest(request, comment.version.video.id);
|
||||||
const shareAccess = shareSession
|
const shareAccess = shareSession
|
||||||
? await validateShareLinkAccess({
|
? await validateShareLinkAccess({
|
||||||
@@ -302,12 +306,12 @@ export async function DELETE(request: NextRequest, { params }: RouteParams) {
|
|||||||
if (!hasGuestAccess) {
|
if (!hasGuestAccess) {
|
||||||
return apiErrors.forbidden('Access denied');
|
return apiErrors.forbidden('Access denied');
|
||||||
}
|
}
|
||||||
canDeleteOwnComment = true;
|
canDelete = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!canDeleteOwnComment) {
|
if (!canDelete) {
|
||||||
return apiErrors.forbidden('You can only delete your own comments');
|
return apiErrors.forbidden('You do not have permission to delete this comment');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect all media URLs to delete from R2 (comment + its replies)
|
// Collect all media URLs to delete from R2 (comment + its replies)
|
||||||
|
|||||||
Reference in New Issue
Block a user