diff --git a/SQL Scripts/functions/create_project_rpc.sql b/SQL Scripts/functions/create_project_rpc.sql index ae813ac..a10863f 100644 --- a/SQL Scripts/functions/create_project_rpc.sql +++ b/SQL Scripts/functions/create_project_rpc.sql @@ -1,9 +1,10 @@ CREATE -OR REPLACE FUNCTION create_project_rpc ( + OR REPLACE FUNCTION create_project_rpc ( _name VARCHAR, _description VARCHAR, _is_open_join BOOLEAN, - _is_open_edit BOOLEAN + _is_open_edit BOOLEAN, + _document_view_right DOCUMENT_VIEW_TYPE ) RETURNS SETOF public.projects AS $body$ DECLARE _project_id uuid := gen_random_uuid(); -- The id of the new project @@ -12,16 +13,16 @@ DECLARE BEGIN IF NOT check_action_policy_organization(auth.uid(), 'projects', 'INSERT') THEN RETURN; - END IF; + END IF; - INSERT INTO public.projects (id, created_by, created_at, name, description, is_open_join, is_open_edit) VALUES (_project_id, auth.uid(), NOW(), _name, _description, _is_open_join, _is_open_edit); + INSERT INTO public.projects (id, created_by, created_at, name, description, is_open_join, is_open_edit, document_view_right) VALUES (_project_id, auth.uid(), NOW(), _name, _description, _is_open_join, _is_open_edit, _document_view_right); INSERT INTO public.contexts (id, created_by, created_at, project_id, is_project_default) VALUES (_context_id, auth.uid(), NOW(), _project_id, TRUE); SELECT (id) INTO _default_context_definition_id FROM public.tag_definitions t WHERE t.scope = 'system' AND t.name = 'DEFAULT_CONTEXT'; - INSERT INTO public.tags (created_by, created_at, tag_definition_id, target_id) VALUES (auth.uid(), NOW(), _default_context_definition_id, _context_id); - + INSERT INTO public.tags (created_by, created_at, tag_definition_id, target_id) VALUES (auth.uid(), NOW(), _default_context_definition_id, _context_id); + RETURN QUERY SELECT * FROM public.projects WHERE id = _project_id; END $body$ LANGUAGE plpgsql SECURITY DEFINER; \ No newline at end of file diff --git a/SQL Scripts/tables/projects.sql b/SQL Scripts/tables/projects.sql index 5a0e835..bcb385f 100644 --- a/SQL Scripts/tables/projects.sql +++ b/SQL Scripts/tables/projects.sql @@ -10,7 +10,8 @@ CREATE TABLE description VARCHAR, is_open_join BOOLEAN DEFAULT FALSE, is_open_edit BOOLEAN DEFAULT FALSE, - is_locked BOOLEAN DEFAULT FALSE + is_locked BOOLEAN DEFAULT FALSE, + document_view_right DOCUMENT_VIEW_TYPE DEFAULT 'closed' ); -- Changes 04/21/23 -- @@ -38,4 +39,8 @@ ADD COLUMN is_open_edit BOOLEAN DEFAULT FALSE; -- Changes 9/20/24 ALTER TABLE public.projects -ADD COLUMN is_locked BOOLEAN DEFAULT FALSE; \ No newline at end of file +ADD COLUMN is_locked BOOLEAN DEFAULT FALSE; + +-- Changes 10/18/24 +ALTER TABLE public.projects +ADD COLUMN document_view_right DOCUMENT_VIEW_TYPE DEFAULT 'closed'; \ No newline at end of file diff --git a/supabase/migrations/20241018111105_add_document_view_right_to_projects.sql b/supabase/migrations/20241018111105_add_document_view_right_to_projects.sql new file mode 100644 index 0000000..9a06a66 --- /dev/null +++ b/supabase/migrations/20241018111105_add_document_view_right_to_projects.sql @@ -0,0 +1,32 @@ +create type "public".document_view_type as enum ('closed', 'annotations', 'notes'); + +alter table "public"."projects" add column "document_view_right" document_view_type default 'closed'; + +CREATE + OR REPLACE FUNCTION create_project_rpc ( + _name VARCHAR, + _description VARCHAR, + _is_open_join BOOLEAN, + _is_open_edit BOOLEAN, + _document_view_right DOCUMENT_VIEW_TYPE +) RETURNS SETOF public.projects AS $body$ +DECLARE + _project_id uuid := gen_random_uuid(); -- The id of the new project + _context_id uuid := gen_random_uuid(); -- The id of the default context + _default_context_definition_id uuid; +BEGIN + IF NOT check_action_policy_organization(auth.uid(), 'projects', 'INSERT') THEN + RETURN; + END IF; + + INSERT INTO public.projects (id, created_by, created_at, name, description, is_open_join, is_open_edit, document_view_right) VALUES (_project_id, auth.uid(), NOW(), _name, _description, _is_open_join, _is_open_edit, _document_view_right); + + INSERT INTO public.contexts (id, created_by, created_at, project_id, is_project_default) VALUES (_context_id, auth.uid(), NOW(), _project_id, TRUE); + + SELECT (id) INTO _default_context_definition_id FROM public.tag_definitions t WHERE t.scope = 'system' AND t.name = 'DEFAULT_CONTEXT'; + + INSERT INTO public.tags (created_by, created_at, tag_definition_id, target_id) VALUES (auth.uid(), NOW(), _default_context_definition_id, _context_id); + + RETURN QUERY SELECT * FROM public.projects WHERE id = _project_id; +END +$body$ LANGUAGE plpgsql SECURITY DEFINER; \ No newline at end of file