Feat: Implement Audit Logging and integrate into Reservation actions
This commit is contained in:
@@ -95,3 +95,28 @@ $$ language plpgsql security definer;
|
||||
create trigger on_auth_user_created
|
||||
after insert on auth.users
|
||||
for each row execute procedure public.handle_new_user();
|
||||
|
||||
-- Create Audit Logs Table
|
||||
create table audit_logs (
|
||||
id uuid default uuid_generate_v4() primary key,
|
||||
user_id uuid references auth.users(id),
|
||||
action text not null,
|
||||
entity_type text not null,
|
||||
entity_id uuid,
|
||||
details jsonb,
|
||||
created_at timestamp with time zone default timezone('utc'::text, now()) not null
|
||||
);
|
||||
|
||||
-- RLS for Audit Logs
|
||||
alter table audit_logs enable row level security;
|
||||
|
||||
create policy "Admins can read all logs" on audit_logs
|
||||
for select using (
|
||||
exists (
|
||||
select 1 from profiles
|
||||
where profiles.id = auth.uid() and profiles.role = 'admin'
|
||||
)
|
||||
);
|
||||
|
||||
create policy "Users can insert logs" on audit_logs
|
||||
for insert with check (auth.uid() = user_id);
|
||||
|
||||
Reference in New Issue
Block a user