Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/recogito/recogito-server
Browse files Browse the repository at this point in the history
…into dl/139_document_metadata
  • Loading branch information
dleadbetter committed Jan 7, 2025
2 parents 7902fb7 + 1d21123 commit 2831f91
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 36 deletions.
3 changes: 3 additions & 0 deletions SQL Scripts/functions/accept_join_request_rpc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ BEGIN
-- Delete the request
DELETE FROM public.join_requests WHERE id = _request_id;

-- Check for assign_all contexts
PERFORM do_assign_all_check_for_user(_project_id, _request.user_id);

RETURN TRUE;
END
$body$ LANGUAGE plpgsql SECURITY DEFINER;
2 changes: 2 additions & 0 deletions SQL Scripts/functions/accept_project_invite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ BEGIN
INSERT INTO public.group_users
(group_type, user_id, type_id)
VALUES ('project', auth.uid(), NEW.project_group_id);

PERFORM do_assign_all_check_for_user(NEW.project_id, auth.uid());
END IF;
RETURN NEW;
END;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BEGIN
_exists = EXISTS(SELECT 1

FROM public.profiles pr
INNER JOIN public.layer_context lc ON lc.context_id = $4 AND lc.is_active_layer = TRUE
INNER JOIN public.layer_contexts lc ON lc.context_id = $4 AND lc.is_active_layer = TRUE
INNER JOIN public.context_users cu ON cu.context_id = lc.context_id AND cu.user_id = $1
INNER JOIN public.roles r ON cu.role_id = r.id
INNER JOIN public.role_policies rp ON r.id = rp.role_id
Expand Down
29 changes: 29 additions & 0 deletions SQL Scripts/functions/do_assign_all_check_for_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CREATE
OR REPLACE FUNCTION do_assign_all_check_for_user (_project_id UUID, _user_id UUID) RETURNS VOID AS $body$
DECLARE
_context public.contexts % rowtype;
_role_id uuid;
BEGIN
-- Get the default group
SELECT g.role_id INTO _role_id
FROM public.default_groups g
WHERE g.group_type = 'layer' AND g.is_default = TRUE;

-- Iterate all context in the project and check for the assign_all_members flag
FOR _context IN SELECT * FROM public.contexts c WHERE c.project_id = _project_id
LOOP
IF _context.assign_all_members IS TRUE
THEN
IF NOT EXISTS(SELECT 1 FROM public.context_users cu WHERE cu.context_id = _context.id AND cu.user_id = _user_id)
THEN
INSERT INTO public.context_users
(context_id, user_id, role_id)
VALUES
(_context.id, _user_id, _role_id);
END IF;
END IF;
END LOOP;

RETURN;
END
$body$ LANGUAGE plpgsql SECURITY DEFINER;
4 changes: 4 additions & 0 deletions SQL Scripts/functions/join_project_rpc.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CREATE
OR REPLACE FUNCTION join_project_rpc (_project_id UUID) RETURNS BOOLEAN AS $body$
DECLARE
_is_open_join BOOLEAN;
_context BOOLEAN;
_project_group_id uuid;
BEGIN

Expand All @@ -20,6 +21,9 @@ BEGIN
VALUES
('project', auth.uid(), _project_group_id);

-- Check for assign_all contexts
PERFORM do_assign_all_check_for_user(_project_id, auth.uid());

RETURN TRUE;
END
$body$ LANGUAGE plpgsql SECURITY DEFINER;
60 changes: 60 additions & 0 deletions SQL Scripts/functions/set_context_to_all_members.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
CREATE
OR REPLACE FUNCTION set_context_to_all_members (
_context_id uuid,
_is_all_members BOOLEAN
) RETURNS BOOLEAN AS $body$
DECLARE
_project_id uuid;
_project_group_id uuid;
_role_id uuid;
_record RECORD;
BEGIN

-- Find the project for this context
SELECT p.id INTO _project_id FROM public.projects p
INNER JOIN public.contexts c ON c.id = _context_id
WHERE p.id = c.project_id;

-- Check user has the right policy
IF NOT (check_action_policy_organization(auth.uid(), 'contexts', 'UPDATE')
OR check_action_policy_project(auth.uid(), 'contexts', 'INSERT', _project_id))
THEN
RETURN FALSE;
END IF;

-- Update the context
UPDATE public.contexts c
SET assign_all_members = _is_all_members
WHERE c.id = _context_id;

-- If we are setting assign_all_members to TRUE
IF _is_all_members
THEN

-- Get the default group
SELECT g.role_id INTO _role_id
FROM public.default_groups g
WHERE g.group_type = 'layer' AND g.is_default = TRUE;

-- Get the project group
SELECT pg.id INTO _project_group_id
FROM public.project_groups pg
WHERE pg.project_id = _project_id AND pg.is_default = TRUE;

-- Iterate all team members and add to context
FOR _record IN SELECT *
FROM public.group_users
WHERE group_type = 'project' AND type_id = _project_group_id
LOOP
IF NOT EXISTS(SELECT 1 FROM public.context_users cu WHERE cu.context_id = _context_id AND cu.user_id = _record.user_id)
THEN
INSERT INTO public.context_users
(context_id, user_id, role_id)
VALUES(_context_id, _record.user_id, _role_id);
END IF;
END LOOP;
END IF;

RETURN TRUE;
END
$body$ LANGUAGE plpgsql SECURITY DEFINER;
6 changes: 5 additions & 1 deletion SQL Scripts/tables/contexts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ ADD COLUMN description VARCHAR;

-- Changes 1/25/24 --
ALTER TABLE public.contexts
ADD COLUMN is_project_default BOOLEAN DEFAULT FALSE;
ADD COLUMN is_project_default BOOLEAN DEFAULT FALSE;

-- Changes 11/26/24
ALTER TABLE public.contexts
ADD COLUMN assign_all_members BOOLEAN DEFAULT FALSE;
2 changes: 1 addition & 1 deletion jest/tests/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ async function processInvite(
}
}

// console.log("Invite Error: ", result.error);
console.log('Invite Error: ', result.error);

return false;
}
Expand Down
27 changes: 2 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions supabase/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ redirect_uri = ""
# Overrides the default auth provider URL. Used to support self-hosted gitlab, single-tenant Azure,
# or any other third-party OIDC providers.
url = ""

[analytics]
enabled = false
Loading

0 comments on commit 2831f91

Please sign in to comment.