Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document picker #3

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
./node_modules/*
node_modules
.DS_Store
private-scripts
priivate-scripts
hold
30 changes: 30 additions & 0 deletions SQL Scripts/policies/project_documents.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
DROP POLICY IF EXISTS "Users with correct policies can SELECT on project_documents" ON public.project_documents;

CREATE POLICY "Users with correct policies can SELECT on project_documents" ON public.project_documents FOR SELECT TO authenticated
USING (
is_archived IS FALSE AND
(public.check_action_policy_organization(auth.uid(), 'project_documents', 'SELECT') OR
public.check_action_policy_project(auth.uid(), 'project_documents', 'SELECT', project_id))
);

DROP POLICY IF EXISTS "Users with correct policies can INSERT on project_documents" ON public.project_documents;

CREATE POLICY "Users with correct policies can INSERT on project_documents" ON public.project_documents FOR INSERT TO authenticated
WITH CHECK (public.check_action_policy_organization(auth.uid(), 'project_documents', 'INSERT') OR
public.check_action_policy_project(auth.uid(), 'project_documents', 'INSERT', project_id));

DROP POLICY IF EXISTS "Users with correct policies can UPDATE on project_documents" ON public.project_documents;

CREATE POLICY "Users with correct policies can UPDATE on project_documents" ON public.project_documents FOR UPDATE TO authenticated
USING (
public.check_action_policy_organization(auth.uid(), 'project_documents', 'UPDATE') OR
public.check_action_policy_project(auth.uid(), 'project_documents', 'UPDATE', project_id)
)
WITH CHECK (public.check_action_policy_organization(auth.uid(), 'project_documents', 'UPDATE') OR
public.check_action_policy_project(auth.uid(), 'project_documents', 'UPDATE', project_id));

DROP POLICY IF EXISTS "Users with correct policies can DELETE on project_documents" ON public.project_documents;

CREATE POLICY "Users with correct policies can DELETE on project_documents" ON public.project_documents FOR DELETE TO authenticated
USING (public.check_action_policy_organization(auth.uid(), 'project_documents', 'DELETE') OR
public.check_action_policy_project(auth.uid(), 'project_documents', 'DELETE', project_id));
5 changes: 4 additions & 1 deletion SQL Scripts/tables/bodies.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- bodies table --
CREATE TYPE body_types AS ENUM ('TextualBody');

CREATE TYPE body_formats AS ENUM ('TextPlain', 'TextHtml');
CREATE TYPE body_formats AS ENUM ('TextPlain', 'TextHtml', 'Quill');

CREATE TABLE bodies
(
Expand Down Expand Up @@ -44,3 +44,6 @@ ALTER TABLE public.bodies
-- Changes 7/26/23 --
ALTER TABLE public.bodies
ADD COLUMN is_archived bool DEFAULT FALSE;

-- Changes 11/10/23 ---
ALTER TYPE body_formats ADD VALUE 'Quill';
11 changes: 11 additions & 0 deletions SQL Scripts/tables/project_documents.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE public.project_documents
(
id uuid NOT NULL DEFAULT uuid_generate_v4() PRIMARY KEY,
created_at timestamp WITH TIME ZONE DEFAULT NOW(),
created_by uuid REFERENCES public.profiles,
updated_at timestamptz,
updated_by uuid REFERENCES public.profiles,
is_archived bool DEFAULT FALSE,
project_id uuid REFERENCES public.projects,
document_id uuid REFERENCES public.documents
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP TRIGGER IF EXISTS on_project_document_created
ON public.project_documents;
CREATE TRIGGER on_project_document_created
BEFORE INSERT ON public.project_documents
FOR EACH ROW EXECUTE PROCEDURE create_dates_and_user();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP TRIGGER IF EXISTS on_project_document_updated
ON public.project_documents;
CREATE TRIGGER on_project_document_updated
BEFORE INSERT ON public.project_documents
FOR EACH ROW EXECUTE PROCEDURE update_dates_and_user();
76 changes: 76 additions & 0 deletions supabase/migrations/20231031155910_add_project_documents.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
create type "public"."render_type_types" as enum ('text', 'lexical');

create table "public"."project_documents" (
"id" uuid not null default uuid_generate_v4(),
"created_at" timestamp with time zone default now(),
"created_by" uuid,
"updated_at" timestamp with time zone,
"updated_by" uuid,
"is_archived" boolean default false,
"project_id" uuid,
"document_id" uuid
);


alter table "public"."project_documents" enable row level security;

alter table "public"."bodies" add column "render_type" render_type_types default 'text'::render_type_types;

CREATE UNIQUE INDEX project_documents_pkey ON public.project_documents USING btree (id);

alter table "public"."project_documents" add constraint "project_documents_pkey" PRIMARY KEY using index "project_documents_pkey";

alter table "public"."project_documents" add constraint "project_documents_created_by_fkey" FOREIGN KEY (created_by) REFERENCES profiles(id) not valid;

alter table "public"."project_documents" validate constraint "project_documents_created_by_fkey";

alter table "public"."project_documents" add constraint "project_documents_document_id_fkey" FOREIGN KEY (document_id) REFERENCES documents(id) not valid;

alter table "public"."project_documents" validate constraint "project_documents_document_id_fkey";

alter table "public"."project_documents" add constraint "project_documents_project_id_fkey" FOREIGN KEY (project_id) REFERENCES projects(id) not valid;

alter table "public"."project_documents" validate constraint "project_documents_project_id_fkey";

alter table "public"."project_documents" add constraint "project_documents_updated_by_fkey" FOREIGN KEY (updated_by) REFERENCES profiles(id) not valid;

alter table "public"."project_documents" validate constraint "project_documents_updated_by_fkey";

create policy "Users with correct policies can DELETE on project_documents"
on "public"."project_documents"
as permissive
for delete
to authenticated
using ((check_action_policy_organization(auth.uid(), 'project_documents'::character varying, 'DELETE'::operation_types) OR check_action_policy_project(auth.uid(), 'project_documents'::character varying, 'DELETE'::operation_types, project_id)));


create policy "Users with correct policies can INSERT on project_documents"
on "public"."project_documents"
as permissive
for insert
to authenticated
with check ((check_action_policy_organization(auth.uid(), 'project_documents'::character varying, 'INSERT'::operation_types) OR check_action_policy_project(auth.uid(), 'project_documents'::character varying, 'INSERT'::operation_types, project_id)));


create policy "Users with correct policies can SELECT on project_documents"
on "public"."project_documents"
as permissive
for select
to authenticated
using (((is_archived IS FALSE) AND (check_action_policy_organization(auth.uid(), 'project_documents'::character varying, 'SELECT'::operation_types) OR check_action_policy_project(auth.uid(), 'project_documents'::character varying, 'SELECT'::operation_types, project_id))));


create policy "Users with correct policies can UPDATE on project_documents"
on "public"."project_documents"
as permissive
for update
to authenticated
using ((check_action_policy_organization(auth.uid(), 'project_documents'::character varying, 'UPDATE'::operation_types) OR check_action_policy_project(auth.uid(), 'project_documents'::character varying, 'UPDATE'::operation_types, project_id)))
with check ((check_action_policy_organization(auth.uid(), 'project_documents'::character varying, 'UPDATE'::operation_types) OR check_action_policy_project(auth.uid(), 'project_documents'::character varying, 'UPDATE'::operation_types, project_id)));


CREATE TRIGGER on_project_document_created BEFORE INSERT ON public.project_documents FOR EACH ROW EXECUTE FUNCTION create_dates_and_user();

CREATE TRIGGER on_project_document_updated BEFORE INSERT ON public.project_documents FOR EACH ROW EXECUTE FUNCTION update_dates_and_user();


39 changes: 39 additions & 0 deletions supabase/migrations/20231110202445_add_quill_body_format_type.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
drop trigger if exists "on_project_document_created" on "public"."project_documents";

drop trigger if exists "on_project_document_updated" on "public"."project_documents";

drop policy "Users with correct policies can DELETE on project_documents" on "public"."project_documents";

drop policy "Users with correct policies can INSERT on project_documents" on "public"."project_documents";

drop policy "Users with correct policies can SELECT on project_documents" on "public"."project_documents";

drop policy "Users with correct policies can UPDATE on project_documents" on "public"."project_documents";

alter table "public"."project_documents" drop constraint "project_documents_created_by_fkey";

alter table "public"."project_documents" drop constraint "project_documents_document_id_fkey";

alter table "public"."project_documents" drop constraint "project_documents_project_id_fkey";

alter table "public"."project_documents" drop constraint "project_documents_updated_by_fkey";

alter table "public"."project_documents" drop constraint "project_documents_pkey";

drop index if exists "public"."project_documents_pkey";

drop table "public"."project_documents";

alter type "public"."body_formats" rename to "body_formats__old_version_to_be_dropped";

create type "public"."body_formats" as enum ('TextPlain', 'TextHtml', 'Quill');

alter table "public"."bodies" alter column format type "public"."body_formats" using format::text::"public"."body_formats";

drop type "public"."body_formats__old_version_to_be_dropped";

alter table "public"."bodies" drop column "render_type";

drop type "public"."render_type_types";


Loading