mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 10:11:13 -05:00
Fix park type and moderator ID
This commit is contained in:
@@ -93,14 +93,14 @@ interface ParkFormProps {
|
||||
}
|
||||
|
||||
const parkTypes = [
|
||||
'Theme Park',
|
||||
'Amusement Park',
|
||||
'Water Park',
|
||||
'Family Entertainment Center',
|
||||
'Adventure Park',
|
||||
'Safari Park',
|
||||
'Carnival',
|
||||
'Fair'
|
||||
{ value: 'theme_park', label: 'Theme Park' },
|
||||
{ value: 'amusement_park', label: 'Amusement Park' },
|
||||
{ value: 'water_park', label: 'Water Park' },
|
||||
{ value: 'family_entertainment', label: 'Family Entertainment Center' },
|
||||
{ value: 'adventure_park', label: 'Adventure Park' },
|
||||
{ value: 'safari_park', label: 'Safari Park' },
|
||||
{ value: 'carnival', label: 'Carnival' },
|
||||
{ value: 'fair', label: 'Fair' }
|
||||
];
|
||||
|
||||
const statusOptions = [
|
||||
@@ -363,8 +363,8 @@ export function ParkForm({ onSubmit, onCancel, initialData, isEditing = false }:
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{parkTypes.map((type) => (
|
||||
<SelectItem key={type} value={type}>
|
||||
{type}
|
||||
<SelectItem key={type.value} value={type.value}>
|
||||
{type.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
-- Update log_moderation_action to use session variable for moderator_id
|
||||
-- This allows edge functions using service role to pass the actual moderator ID
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.log_moderation_action(
|
||||
_submission_id uuid,
|
||||
_action text,
|
||||
_previous_status text DEFAULT NULL::text,
|
||||
_new_status text DEFAULT NULL::text,
|
||||
_notes text DEFAULT NULL::text,
|
||||
_metadata jsonb DEFAULT '{}'::jsonb
|
||||
)
|
||||
RETURNS uuid
|
||||
LANGUAGE plpgsql
|
||||
SECURITY DEFINER
|
||||
SET search_path TO 'public'
|
||||
AS $function$
|
||||
DECLARE
|
||||
_log_id UUID;
|
||||
_metadata_record record;
|
||||
_moderator_id UUID;
|
||||
BEGIN
|
||||
-- Get moderator ID from session variable (set by edge function) or auth.uid()
|
||||
BEGIN
|
||||
_moderator_id := COALESCE(
|
||||
current_setting('app.moderator_id', true)::uuid,
|
||||
auth.uid()
|
||||
);
|
||||
EXCEPTION WHEN OTHERS THEN
|
||||
_moderator_id := auth.uid();
|
||||
END;
|
||||
|
||||
-- Insert into moderation_audit_log (without metadata JSONB column)
|
||||
INSERT INTO public.moderation_audit_log (
|
||||
submission_id,
|
||||
moderator_id,
|
||||
action,
|
||||
previous_status,
|
||||
new_status,
|
||||
notes
|
||||
) VALUES (
|
||||
_submission_id,
|
||||
_moderator_id,
|
||||
_action,
|
||||
_previous_status,
|
||||
_new_status,
|
||||
_notes
|
||||
)
|
||||
RETURNING id INTO _log_id;
|
||||
|
||||
-- Write metadata to relational moderation_audit_metadata table
|
||||
IF _metadata IS NOT NULL AND jsonb_typeof(_metadata) = 'object' THEN
|
||||
FOR _metadata_record IN
|
||||
SELECT key, value::text as text_value
|
||||
FROM jsonb_each_text(_metadata)
|
||||
LOOP
|
||||
INSERT INTO public.moderation_audit_metadata (
|
||||
audit_log_id,
|
||||
metadata_key,
|
||||
metadata_value
|
||||
) VALUES (
|
||||
_log_id,
|
||||
_metadata_record.key,
|
||||
_metadata_record.text_value
|
||||
);
|
||||
END LOOP;
|
||||
END IF;
|
||||
|
||||
RETURN _log_id;
|
||||
END;
|
||||
$function$;
|
||||
Reference in New Issue
Block a user