-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from recogito/lwj/add-all-members-to-assignment
Support for Add All Members
- Loading branch information
Showing
12 changed files
with
365 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.