Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
Emyrk merged 9 commits intomainfromstevenmasley/delete_role
Aug 7, 2024
Merged

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedAug 1, 2024
edited
Loading

When deleting a custom role, the role can still be assigned to a user.

@EmyrkGraphite App
Copy link
MemberAuthor

Emyrk commentedAug 1, 2024
edited
Loading

This stack of pull requests is managed by Graphite.Learn more about stacking.

Join@Emyrk and the rest of your teammates onGraphiteGraphite

@EmyrkEmyrkforce-pushed thestevenmasley/delete_role branch from31f7fe5 tocb91471CompareAugust 1, 2024 20:07
@EmyrkEmyrkforce-pushed thestevenmasley/org_role_routes branch from43cbd73 to938634dCompareAugust 2, 2024 19:42
@EmyrkEmyrkforce-pushed thestevenmasley/delete_role branch fromcb91471 to9225eb1CompareAugust 2, 2024 20:16
Base automatically changed fromstevenmasley/org_role_routes tomainAugust 5, 2024 18:42
@EmyrkEmyrkforce-pushed thestevenmasley/delete_role branch from9225eb1 to2aa9875CompareAugust 6, 2024 16:57
@EmyrkEmyrk marked this pull request as ready for reviewAugust 6, 2024 19:22
@EmyrkEmyrkforce-pushed thestevenmasley/delete_role branch from9d2a42f tof4739c9CompareAugust 6, 2024 19:41
@EmyrkEmyrk requested a review fromf0sselAugust 6, 2024 19:54
Copy link
Member

@aslilacaslilac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

lgtm!

Comment on lines 166 to 170
OrganizationID: organization.ID,
},
},
ExcludeOrgRoles: false,
OrganizationID: organization.ID,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

weird duplication ofOrganizationID 🤔

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yea, it actually is not necessary, but we have a linter that makes you fill out all fields in a struct. This felt more intuitive that doinguuid.Nil. But you have to do something, or the linter yells at you 😢

aslilac reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

tldr on why this field can't be removed?

httpapi.InternalServerError(rw, err)
return
}
aReq.New = database.CustomRole{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

clever 😄

Comment on lines 1 to 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.';
Copy link
Contributor

@f0sself0sselAug 7, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I generally prefer this logic to live in app code in some sort of helper function, probably in a tx. I don't think this has to be changed here since I'm not sure how the team at large feels about this kind of design, but wanted to point out that I think it's easier to follow execution flow and also easier to update the behavior as well since changing this behavior now requires knowledge of sql triggers.

I see the benefits from a data integrity standpoint. Does this serve as some sort of performance advantage as well?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yea, I generally agree with you. In this case the data integrity is a security critical thing though.

Currently when making a new custom_role, you have to have a superset of the permissions to make it. So you cannot make a role that has greater privilege than yourself.

You could imagine a scenario where a role is created with a small set of perms, then deleted. Then a new role is created with the same name that has more permissions, and because a user had the old role, they are granted this new one.

At present, this would be less malicious, and more likely a mistake based on our roles, but the problem still remains.


So essentially, I choose the trigger as a security guarantee. We have some prior art for this for deletinguser api keys.

A golang helper function just feels less safe imo.

Comment on lines 166 to 170
OrganizationID: organization.ID,
},
},
ExcludeOrgRoles: false,
OrganizationID: organization.ID,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

tldr on why this field can't be removed?

@EmyrkEmyrkforce-pushed thestevenmasley/delete_role branch frome72061a toe8f57feCompareAugust 7, 2024 17:21
@Emyrk
Copy link
MemberAuthor

tldr on why this field can't be removed?

We have a linter that requires all struct fields be explicitly set. So you could putuuid.Nil and it would still work, just felt like it might confuse someone else to see auuid.Nil 🤷‍♂️

@EmyrkEmyrk merged commit2c13797 intomainAug 7, 2024
28 checks passed
@EmyrkEmyrk deleted the stevenmasley/delete_role branchAugust 7, 2024 17:37
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsAug 7, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@jaaydenhjaaydenhjaaydenh left review comments

@aslilacaslilacaslilac approved these changes

@f0sself0sself0ssel approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@Emyrk@aslilac@jaaydenh@f0ssel

[8]ページ先頭

©2009-2025 Movatter.jp