- Notifications
You must be signed in to change notification settings - Fork927
chore: implement deleting custom roles#14101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
6a140af
cff829b
19ca988
9063675
6b0ac00
817bb4b
5033ee8
3b9790a
e8f57fe
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DROP TRIGGER IF EXISTS remove_organization_member_custom_role ON custom_roles; | ||
DROP FUNCTION IF EXISTS remove_organization_member_role; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
-- When a custom role is deleted, we need to remove the assigned role | ||
-- from all organization members that have it. | ||
-- This action cannot be reverted, so deleting a custom role should be | ||
-- done with caution. | ||
CREATE OR REPLACE FUNCTION remove_organization_member_role() | ||
RETURNS TRIGGER AS | ||
$$ | ||
BEGIN | ||
-- Delete the role from all organization members that have it. | ||
-- TODO: When site wide custom roles are supported, if the | ||
--organization_id is null, we should remove the role from the 'users' | ||
--table instead. | ||
IF OLD.organization_id IS NOT NULL THEN | ||
UPDATE organization_members | ||
-- this is a noop if the role is not assigned to the member | ||
SET roles = array_remove(roles, OLD.name) | ||
WHERE | ||
-- Scope to the correct organization | ||
organization_members.organization_id = OLD.organization_id; | ||
END IF; | ||
RETURN OLD; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
-- Attach the function to deleting the custom role | ||
CREATE TRIGGER remove_organization_member_custom_role | ||
BEFORE DELETE ON custom_roles FOR EACH ROW | ||
EXECUTE PROCEDURE remove_organization_member_role(); | ||
COMMENT ON TRIGGER | ||
remove_organization_member_custom_role | ||
ON custom_roles IS | ||
'When a custom_role is deleted, this trigger removes the role from all organization members.'; |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.