mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 05:51:23 -05:00
feat: Implement full inline editing enhancement
This commit is contained in:
@@ -1118,6 +1118,38 @@ export type Database = {
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
item_edit_history: {
|
||||||
|
Row: {
|
||||||
|
changes: Json
|
||||||
|
edited_at: string
|
||||||
|
editor_id: string
|
||||||
|
id: string
|
||||||
|
item_id: string
|
||||||
|
}
|
||||||
|
Insert: {
|
||||||
|
changes: Json
|
||||||
|
edited_at?: string
|
||||||
|
editor_id: string
|
||||||
|
id?: string
|
||||||
|
item_id: string
|
||||||
|
}
|
||||||
|
Update: {
|
||||||
|
changes?: Json
|
||||||
|
edited_at?: string
|
||||||
|
editor_id?: string
|
||||||
|
id?: string
|
||||||
|
item_id?: string
|
||||||
|
}
|
||||||
|
Relationships: [
|
||||||
|
{
|
||||||
|
foreignKeyName: "item_edit_history_item_id_fkey"
|
||||||
|
columns: ["item_id"]
|
||||||
|
isOneToOne: false
|
||||||
|
referencedRelation: "submission_items"
|
||||||
|
referencedColumns: ["id"]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
list_items: {
|
list_items: {
|
||||||
Row: {
|
Row: {
|
||||||
created_at: string | null
|
created_at: string | null
|
||||||
@@ -4563,6 +4595,27 @@ export type Database = {
|
|||||||
}
|
}
|
||||||
Relationships: []
|
Relationships: []
|
||||||
}
|
}
|
||||||
|
item_edit_history_view: {
|
||||||
|
Row: {
|
||||||
|
changes: Json | null
|
||||||
|
edited_at: string | null
|
||||||
|
editor_avatar_url: string | null
|
||||||
|
editor_display_name: string | null
|
||||||
|
editor_id: string | null
|
||||||
|
editor_username: string | null
|
||||||
|
id: string | null
|
||||||
|
item_id: string | null
|
||||||
|
}
|
||||||
|
Relationships: [
|
||||||
|
{
|
||||||
|
foreignKeyName: "item_edit_history_item_id_fkey"
|
||||||
|
columns: ["item_id"]
|
||||||
|
isOneToOne: false
|
||||||
|
referencedRelation: "submission_items"
|
||||||
|
referencedColumns: ["id"]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
moderation_sla_metrics: {
|
moderation_sla_metrics: {
|
||||||
Row: {
|
Row: {
|
||||||
avg_resolution_hours: number | null
|
avg_resolution_hours: number | null
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
-- Phase 4: Create edit history tracking table
|
||||||
|
CREATE TABLE IF NOT EXISTS public.item_edit_history (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
item_id UUID NOT NULL REFERENCES public.submission_items(id) ON DELETE CASCADE,
|
||||||
|
editor_id UUID NOT NULL REFERENCES auth.users(id) ON DELETE CASCADE,
|
||||||
|
changes JSONB NOT NULL,
|
||||||
|
edited_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Add index for efficient querying
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_item_edit_history_item_id ON public.item_edit_history(item_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_item_edit_history_edited_at ON public.item_edit_history(edited_at DESC);
|
||||||
|
|
||||||
|
-- Enable RLS
|
||||||
|
ALTER TABLE public.item_edit_history ENABLE ROW LEVEL SECURITY;
|
||||||
|
|
||||||
|
-- Allow moderators and admins to view edit history
|
||||||
|
CREATE POLICY "Moderators can view edit history"
|
||||||
|
ON public.item_edit_history
|
||||||
|
FOR SELECT
|
||||||
|
TO authenticated
|
||||||
|
USING (
|
||||||
|
public.has_role(auth.uid(), 'moderator') OR
|
||||||
|
public.has_role(auth.uid(), 'admin') OR
|
||||||
|
public.has_role(auth.uid(), 'superuser')
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Allow system to insert edit history (via service role)
|
||||||
|
CREATE POLICY "System can insert edit history"
|
||||||
|
ON public.item_edit_history
|
||||||
|
FOR INSERT
|
||||||
|
TO authenticated
|
||||||
|
WITH CHECK (
|
||||||
|
public.has_role(auth.uid(), 'moderator') OR
|
||||||
|
public.has_role(auth.uid(), 'admin') OR
|
||||||
|
public.has_role(auth.uid(), 'superuser')
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Create view to get edit history with user info
|
||||||
|
CREATE OR REPLACE VIEW public.item_edit_history_view AS
|
||||||
|
SELECT
|
||||||
|
ieh.id,
|
||||||
|
ieh.item_id,
|
||||||
|
ieh.editor_id,
|
||||||
|
ieh.changes,
|
||||||
|
ieh.edited_at,
|
||||||
|
p.username as editor_username,
|
||||||
|
p.display_name as editor_display_name,
|
||||||
|
p.avatar_url as editor_avatar_url
|
||||||
|
FROM public.item_edit_history ieh
|
||||||
|
LEFT JOIN public.profiles p ON p.user_id = ieh.editor_id
|
||||||
|
ORDER BY ieh.edited_at DESC;
|
||||||
|
|
||||||
|
-- Grant access to the view
|
||||||
|
GRANT SELECT ON public.item_edit_history_view TO authenticated;
|
||||||
Reference in New Issue
Block a user