Fix RLS policy for deletion

This commit is contained in:
gpt-engineer-app[bot]
2025-09-29 02:24:36 +00:00
parent 8e35ea90d6
commit fb29398eb4
2 changed files with 23 additions and 1 deletions

View File

@@ -418,7 +418,12 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
const skippedPhotos: string[] = []; const skippedPhotos: string[] = [];
if (item.content?.photos && Array.isArray(item.content.photos)) { if (item.content?.photos && Array.isArray(item.content.photos)) {
console.log('Processing photos from content:', item.content.photos);
for (const photo of item.content.photos) { for (const photo of item.content.photos) {
console.log('Processing photo object:', photo);
console.log('Photo keys:', Object.keys(photo));
console.log('photo.imageId:', photo.imageId, 'type:', typeof photo.imageId);
let imageId = ''; let imageId = '';
// First try to use the stored imageId directly // First try to use the stored imageId directly
@@ -507,7 +512,19 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
throw error; throw error;
} }
console.log('Submission successfully deleted from database'); // Verify the deletion actually worked
const { data: checkData, error: checkError } = await supabase
.from('content_submissions')
.select('id')
.eq('id', item.id)
.single();
if (checkData && !checkError) {
console.error('DELETION FAILED: Item still exists in database after delete operation');
throw new Error('Deletion failed - item still exists in database');
} else {
console.log('Verified: Submission successfully deleted from database');
}
const deletedCount = validImageIds.length; const deletedCount = validImageIds.length;
const orphanedCount = skippedPhotos.length; const orphanedCount = skippedPhotos.length;

View File

@@ -0,0 +1,5 @@
-- Add DELETE policy for moderators on content_submissions table
CREATE POLICY "Moderators can delete content submissions"
ON public.content_submissions
FOR DELETE
USING (is_moderator(auth.uid()));