Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
d59f87961e
commit
1b454bf090
@@ -0,0 +1,44 @@
|
||||
-- Add BCC default to SMTP settings
|
||||
ALTER TABLE public.smtp_settings
|
||||
ADD COLUMN IF NOT EXISTS default_bcc text;
|
||||
|
||||
-- Email log table
|
||||
CREATE TABLE IF NOT EXISTS public.email_logs (
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
sent_at timestamptz NOT NULL DEFAULT now(),
|
||||
sent_by uuid,
|
||||
to_addresses text[] NOT NULL DEFAULT '{}',
|
||||
cc_addresses text[] NOT NULL DEFAULT '{}',
|
||||
bcc_addresses text[] NOT NULL DEFAULT '{}',
|
||||
reply_to text,
|
||||
from_address text,
|
||||
subject text NOT NULL,
|
||||
body_html text,
|
||||
body_text text,
|
||||
status text NOT NULL DEFAULT 'sent',
|
||||
error_message text,
|
||||
context text,
|
||||
case_id uuid,
|
||||
created_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS email_logs_sent_at_idx ON public.email_logs (sent_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS email_logs_sent_by_idx ON public.email_logs (sent_by);
|
||||
CREATE INDEX IF NOT EXISTS email_logs_case_id_idx ON public.email_logs (case_id);
|
||||
|
||||
ALTER TABLE public.email_logs ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
DROP POLICY IF EXISTS email_logs_select ON public.email_logs;
|
||||
CREATE POLICY email_logs_select ON public.email_logs
|
||||
FOR SELECT TO authenticated
|
||||
USING (public.is_admin(auth.uid()) OR sent_by = auth.uid());
|
||||
|
||||
DROP POLICY IF EXISTS email_logs_insert ON public.email_logs;
|
||||
CREATE POLICY email_logs_insert ON public.email_logs
|
||||
FOR INSERT TO authenticated
|
||||
WITH CHECK (auth.uid() IS NOT NULL);
|
||||
|
||||
DROP POLICY IF EXISTS email_logs_delete ON public.email_logs;
|
||||
CREATE POLICY email_logs_delete ON public.email_logs
|
||||
FOR DELETE TO authenticated
|
||||
USING (public.is_admin(auth.uid()));
|
||||
Reference in New Issue
Block a user