Skip to content

Commit

Permalink
Various fixes on open edit
Browse files Browse the repository at this point in the history
  • Loading branch information
lwjameson committed May 16, 2024
1 parent d075d0a commit 23b00bb
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 38 deletions.
33 changes: 14 additions & 19 deletions SQL Scripts/functions/check_for_project_open_edit_change.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DECLARE
_record RECORD;
_layer_record RECORD;
_context_id uuid;
_layer_group_id uuid;
_role_id uuid;
_project_group_id uuid;
_id uuid;
BEGIN
Expand All @@ -18,26 +18,21 @@ BEGIN

-- RAISE LOG 'Found default context: %', _context_id;

FOR _layer_record IN SELECT * FROM public.layers l
INNER JOIN public.layer_contexts lc ON lc.context_id = _context_id AND l.project_id = OLD.id
LOOP

-- Get the layer group
SELECT lg.id INTO _layer_group_id FROM public.layer_groups lg WHERE lg.layer_id = _layer_record.id and is_default IS TRUE;
-- RAISE LOG 'Found layer_group: %', _layer_group_id;
-- Get the layer group
SELECT g.role_id INTO _role_id FROM public.default_groups g WHERE g.group_type = 'layer' AND g.is_default = TRUE;
-- RAISE LOG 'Found layer_group: %', _layer_group_id;

-- Get the project group
SELECT pg.id INTO _project_group_id FROM public.project_groups pg WHERE pg.project_id = NEW.id AND is_default IS TRUE;
-- RAISE LOG 'Found project_group: %', _project_group_id;
-- Get the project group
SELECT pg.id INTO _project_group_id FROM public.project_groups pg WHERE pg.project_id = NEW.id AND is_default IS TRUE;
-- RAISE LOG 'Found project_group: %', _project_group_id;

-- Add all project members to default layer group
FOR _record IN SELECT * FROM public.group_users WHERE group_type = 'project' AND type_id = _project_group_id
LOOP
-- RAISE LOG 'Adding % to layer group', _record.user_id;
INSERT INTO public.group_users (group_type, user_id, type_id)
VALUES ('layer',_record.user_id, _layer_group_id);
END LOOP;
END LOOP;
-- Add all project members to the default context
FOR _record IN SELECT * FROM public.group_users WHERE group_type = 'project' AND type_id = _project_group_id
LOOP
-- RAISE LOG 'Adding % to layer group', _record.user_id;
INSERT INTO public.context_users (context_id, user_id, role_id)
VALUES (_context_id,_record.user_id, _role_id);
END LOOP;
END IF;

RETURN NEW;
Expand Down
16 changes: 6 additions & 10 deletions SQL Scripts/functions/check_group_users_for_open_edit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ DECLARE
_is_default_group BOOLEAN;
_context_id uuid;
_is_open_edit BOOLEAN;
_record RECORD;
_layer_group_id uuid;
_role_id uuid;
BEGIN
-- Is this a project group?
IF NEW.group_type = 'project' THEN
Expand All @@ -22,15 +21,12 @@ BEGIN
-- Get the default context
SELECT c.id INTO _context_id FROM public.contexts c WHERE c.project_id = _project_id AND c.is_project_default IS TRUE;

-- Iterate all of the layers and add the users
FOR _record IN SELECT * from public.layer_contexts l WHERE l.context_id = _context_id LOOP
-- Get the role id
SELECT g.role_id INTO _role_id FROM public.default_groups g WHERE g.group_type = 'layer' AND g.is_default = TRUE;

-- Get the layer group
SELECT (id) INTO _layer_group_id FROM public.layer_groups g WHERE g.layer_id = _record.layer_id and g.is_default IS TRUE;

INSERT INTO public.group_users (group_type, user_id, type_id)
VALUES ('layer',NEW.user_id, _layer_group_id);
END LOOP;
-- Add the user to the context
INSERT INTO public.context_users (context_id, user_id, role_id)
VALUES (_context_id,NEW.user_id, _role_id);
END IF;
END IF;
RETURN NEW;
Expand Down
14 changes: 8 additions & 6 deletions SQL Scripts/functions/check_layer_context_for_open_edit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@ DECLARE
_is_open_edit BOOLEAN;
_record RECORD;
_project_group_id uuid;
_layer_group_id uuid;
_role_id uuid;
_id uuid;
BEGIN
-- See if the layer is in the default context on an open edit project
SELECT c.project_id, c.name, c.is_project_default INTO _project_id, _context_name, _is_project_default FROM public.contexts c WHERE c.id = NEW.context_id;
SELECT is_open_edit INTO _is_open_edit FROM public.projects p WHERE p.id = _project_id;

RAISE LOG 'check_layer_context_for_open_edit';

IF _is_open_edit AND _is_project_default IS TRUE THEN
-- Get the project group
SELECT (id) INTO _project_group_id FROM public.project_groups WHERE project_id = _project_id and is_default = TRUE;

-- Get the layer group
SELECT (id) INTO _layer_group_id FROM public.layer_groups WHERE layer_id = NEW.layer_id and is_default IS TRUE;
-- Get the role_id
SELECT g.role_id INTO _role_id FROM public.default_groups g WHERE g.group_type = 'layer' AND g.is_default = TRUE;

-- Add all project members to default layer group
-- Add all project members to default context
FOR _record IN SELECT * FROM public.group_users WHERE group_type = 'project' AND type_id = _project_group_id
LOOP
INSERT INTO public.group_users (group_type, user_id, type_id)
VALUES ('layer',_record.user_id, _layer_group_id);
INSERT INTO public.context_users (context_id, user_id, role_id)
VALUES (_context_id,_record.user_id, _role_id);
END LOOP;
END IF;

Expand Down
3 changes: 0 additions & 3 deletions SQL Scripts/functions/get_available_layers_rpc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ BEGIN
FOR _contexts_row IN SELECT * FROM public.contexts c
WHERE c.project_id = _project_id
LOOP
RAISE LOG 'Context %', _contexts_row.id;
FOR _layer_context_row IN SELECT * FROM public.layer_contexts lcx
WHERE lcx.context_id = _contexts_row.id AND lcx.is_archived IS NOT TRUE
LOOP
RAISE LOG 'Layer Context %', _layer_context_row.id;
FOR _layer_row IN SELECT * FROM public.layers l
WHERE l.id = _layer_context_row.layer_id AND l.document_id = _document_id AND l.is_archived IS NOT TRUE
LOOP
RAISE LOG 'Layer %', _layer_row.id;
document_id := _document_id;
context_id := _contexts_row.id;
is_active := _layer_context_row.is_active_layer;
Expand Down
Loading

0 comments on commit 23b00bb

Please sign in to comment.