Skip to content

Commit

Permalink
Merge pull request #36 from recogito/dl/86_document_default_view
Browse files Browse the repository at this point in the history
#86 - Document Default View
  • Loading branch information
dleadbetter authored Oct 24, 2024
2 parents 7076a2c + 540f1dd commit 0261b1d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
13 changes: 7 additions & 6 deletions SQL Scripts/functions/create_project_rpc.sql
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
9 changes: 7 additions & 2 deletions SQL Scripts/tables/projects.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down Expand Up @@ -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;
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';
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 0261b1d

Please sign in to comment.