-
Notifications
You must be signed in to change notification settings - Fork 943
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6a140af
chore: implement deleting custom roles
Emyrk cff829b
add trigger to delete role from organization members on delete
Emyrk 19ca988
update dbauthz test
Emyrk 9063675
add to unit test
Emyrk 6b0ac00
add pg comment
Emyrk 817bb4b
typo
Emyrk 5033ee8
add unit test for site wide custom role deletE
Emyrk 3b9790a
chore: add comments to explain populated field
Emyrk e8f57fe
bump migration
Emyrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add trigger to delete role from organization members on delete
- Loading branch information
commit cff829b5dc5ba362711843978ec6b3ef91597625
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,2 @@ | ||
DROP TRIGGER IF EXISTS remove_organization_member_custom_role ON custom_roles; | ||
DROP FUNCTION IF EXISTS remove_organization_member_role; |
29 changes: 29 additions & 0 deletions
29
coderd/database/migrations/000240_delete_user_roles.up.sql
This file contains hidden or 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 @@ | ||
-- 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(); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.