This commit is contained in:
Jamie Brunton committed 2025-12-31 10:40:17 +00:00
1 parent 71667d6104
commit f46f0d59df
24 files changed
+2647 -516

No files matched your search

@@ -1028,6 +1028,7 @@ CREATE POLICY "Users can view own feedback screenshots"
);
-- Chat media policies
-- IMPORTANT: Use storage.objects.name (not just "name") to avoid ambiguity with profiles.name
CREATE POLICY "Users can view chat media in their matches"
ON storage.objects FOR SELECT TO authenticated
USING (
@@ -1035,7 +1036,7 @@ CREATE POLICY "Users can view chat media in their matches"
AND EXISTS (
SELECT 1 FROM matches m
JOIN profiles p ON p.couple_id = m.couple_id
WHERE (storage.foldername(name))[1] = m.id::text
WHERE (storage.foldername(storage.objects.name))[1] = m.id::text
AND p.id = auth.uid()
)
);
@@ -1047,7 +1048,7 @@ CREATE POLICY "Users can upload chat media to their matches"
AND EXISTS (
SELECT 1 FROM matches m
JOIN profiles p ON p.couple_id = m.couple_id
WHERE (storage.foldername(name))[1] = m.id::text
WHERE (storage.foldername(storage.objects.name))[1] = m.id::text
AND p.id = auth.uid()
)
);
@@ -1059,7 +1060,7 @@ CREATE POLICY "Users can delete their own chat media"
AND EXISTS (
SELECT 1 FROM matches m
JOIN profiles p ON p.couple_id = m.couple_id
WHERE (storage.foldername(name))[1] = m.id::text
WHERE (storage.foldername(storage.objects.name))[1] = m.id::text
AND p.id = auth.uid()
)
);
@@ -0,0 +1,46 @@
-- Fix storage policies that incorrectly reference p.name instead of storage.objects.name
-- Bug: Using unqualified "name" in a subquery with profiles table causes Postgres to resolve
-- it to profiles.name instead of storage.objects.name
-- Fix: Explicitly qualify as storage.objects.name to reference the storage object's file path
-- Drop existing broken policies
DROP POLICY IF EXISTS "Users can upload chat media to their matches" ON storage.objects;
DROP POLICY IF EXISTS "Users can view chat media in their matches" ON storage.objects;
DROP POLICY IF EXISTS "Users can delete their own chat media" ON storage.objects;
-- Recreate with explicit table qualification to avoid column name ambiguity
CREATE POLICY "Users can upload chat media to their matches"
ON storage.objects FOR INSERT TO authenticated
WITH CHECK (
bucket_id = 'chat-media'
AND EXISTS (
SELECT 1 FROM matches m
JOIN profiles p ON p.couple_id = m.couple_id
WHERE (storage.foldername(storage.objects.name))[1] = m.id::text
AND p.id = auth.uid()
)
);
CREATE POLICY "Users can view chat media in their matches"
ON storage.objects FOR SELECT TO authenticated
USING (
bucket_id = 'chat-media'
AND EXISTS (
SELECT 1 FROM matches m
JOIN profiles p ON p.couple_id = m.couple_id
WHERE (storage.foldername(storage.objects.name))[1] = m.id::text
AND p.id = auth.uid()
)
);
CREATE POLICY "Users can delete their own chat media"
ON storage.objects FOR DELETE TO authenticated
USING (
bucket_id = 'chat-media'
AND EXISTS (
SELECT 1 FROM matches m
JOIN profiles p ON p.couple_id = m.couple_id
WHERE (storage.foldername(storage.objects.name))[1] = m.id::text
AND p.id = auth.uid()
)
);