user-role-cluster #760

Merged
philipp merged 10 commits from user-role-cluster into staging 2024-10-11 11:20:59 +02:00
Showing only changes of commit 9bacbb9395 - Show all commits

View File

@ -222,15 +222,19 @@ CREATE TABLE IF NOT EXISTS "distance" (
);
CREATE UNIQUE INDEX one_role_per_group_per_user ON user_role
WHERE EXISTS (
CREATE TRIGGER prevent_multiple_roles_same_cluster
BEFORE INSERT ON user_role
BEGIN
SELECT CASE
WHEN EXISTS (
SELECT 1
FROM role r1
JOIN role r2 ON r1.id = user_role.role_id
WHERE r1."group" = r2."group"
AND r2.id IN (
SELECT role_id
FROM user_role ur2
WHERE ur2.user_id = user_role.user_id
FROM user_role ur
JOIN role r1 ON ur.role_id = r1.id
JOIN role r2 ON r1."cluster" = r2."cluster"
WHERE ur.user_id = NEW.user_id
AND r2.id = NEW.role_id
AND r1.id != NEW.role_id
)
);
THEN RAISE(ABORT, 'User already has a role in this cluster')
END;
END;