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

fix: improve error message when deleting organization with resources#17049

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

Conversation

brettkolodny
Copy link
Contributor

Closescoder/internal#477

Screenshot 2025-03-21 at 11 25 57 AM

I'm solving this issue in two parts:

  1. Updated the postgres function so that it doesn't omit 0 values in the error
  2. Created a new query to fetch the number of resources associated with an organization and using that information to provider a cleaner error message to the frontend

NOTE: SQL is not my strong suit, and the code was created with the help of AI. So I'd take extra time looking over what I wrote there

@brettkolodnybrettkolodny marked this pull request as ready for reviewMarch 21, 2025 20:31
@brettkolodny
Copy link
ContributorAuthor

Also I'm not sure what permissions I should be checking for for reading from theprovisioner_keys table. Right now I'm checking forrbac.ResourceProvisionerDaemon.InOrg(<org ID>), policy.ActionRead but that's just a guess

Comment on lines 9 to 10
workspace_count int;
template_count int;
Copy link
Member

Choose a reason for hiding this comment

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

classic tabs vs spaces moment (you've got 4 spaces on one line and a tab on the next)

Comment on lines 47 to 52
-- Fail the deletion if one of the following:
-- * the organization has 1 or more workspaces
-- * the organization has 1 or more templates
-- * the organization has 1 or more groups other than "Everyone" group
-- * the organization has 1 or more members other than the organization owner
-- * the organization has 1 or more provisioner keys
Copy link
Member

Choose a reason for hiding this comment

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

goes back and forth again here, and actually a lot throughout the file 😅 I usually normalize to tabs, but I don't think we really have a consistent indentation style in sql. it is nice to pick one and stick with it within a file at least.

Copy link
Member

Choose a reason for hiding this comment

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

it looks like right now your down migration is just a copy of your up migration.

  • up migrations should add your new things
  • down migrations should revert them

I think your down migration really only needs to be

droptrigger if exists protect_deleting_organizationson organizations;dropfunction if exists protect_deleting_organizations;

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Sorry, I think there were some copy paste errors as I changed from another branch to this one (long story). Probably also why there is the tabs vs spaces issue.

The down migration can't just be dropping the function since the function already exists, as far as I understand I'd have to re-declare the original function from a previous migration

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Actually taking a closer look now the down migration is correct, or at least what I meant it to be. In it we drop the existing functions and triggers and re-create the old one frommigration 296

@@ -0,0 +1,96 @@
DROP TRIGGER IF EXISTS protect_deleting_organizations ON organizations;
Copy link
Member

Choose a reason for hiding this comment

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

seems a bit over defensive, but also doesn't really hurt anything.

mostly I'm just wondering if you think this needs to stay or if this is just some weird thing that your little buddy dreamt up 😂

brettkolodny reacted with laugh emoji
Copy link
Member

Choose a reason for hiding this comment

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

and this file also has inconsistent indentation throughout. we're really not usually picky about sql formatting, but sticking with a consistent indentation character/width is nice.

brettkolodny reacted with thumbs up emoji
Comment on lines +70 to +76
SELECT
(SELECT COUNT(*) FROM workspaces WHERE workspaces.organization_id = $1 AND workspaces.deleted = false) AS workspace_count,
(SELECT COUNT(*) FROM groups WHERE groups.organization_id = $1) AS group_count,
(SELECT COUNT(*) FROM templates WHERE templates.organization_id = $1 AND templates.deleted = false) AS template_count,
(SELECT COUNT(*) FROM organization_members WHERE organization_members.organization_id = $1) AS member_count,
(SELECT COUNT(*) FROM provisioner_keys WHERE provisioner_keys.organization_id = $1) AS provisioner_key_count;

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should declare this as a function so that it could be used inprotect_deleting_organizations. this is super nice, readable, and concise, but the code for accomplishing the same counting inprotect_deleting_organizations is like 20 lines longer. 🤔


// There will always be one member and group so instead we need to check that
// the count is greater than one.
addDetailPart("member", orgResourcesRow.MemberCount-1)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if members should actually prevent deletion. it's not quite as serious as deleting the others which aren't recoverable. workspaces, templates, and groups are all more work to configure, but removing a member doesn't delete the user, and adding them back is quite simple.

I think@Emyrk and I talked about this forever ago and I convinced him that members shouldn't block deletion.

Copy link
Member

Choose a reason for hiding this comment

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

Yea, it is a tough one. If we keep members, their roles in that org I think are still fetched on every auth. Maybe we should omit them in that call?

I'd rather be strict today, and loosen it up later

Copy link
Member

Choose a reason for hiding this comment

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

we could still delete all the members from the database tho, and probably even should so that the admin who deletes the org isn't the only one paying that penalty

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Is this something we wan to do in this PR or should we make an issue for it and get to it later?

Copy link
Member

Choose a reason for hiding this comment

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

@brettkolodny let's not delete things for the user at this time.

I think we will want to add some "cleanup" button later that the user clicks to explictly delete all the resources required to cleanup an org.

brettkolodny reacted with thumbs up emoji
@aslilac
Copy link
Member

aslilac commentedMar 21, 2025
edited
Loading

but that's just a guess

// ResourceProvisionerDaemon
// Valid Actions
// - "ActionCreate" :: create a provisioner daemon/key
// - "ActionDelete" :: delete a provisioner daemon/key
// - "ActionRead" :: read provisioner daemon
// - "ActionUpdate" :: update a provisioner daemon
ResourceProvisionerDaemon=Object{
Type:"provisioner_daemon",
}

good guess! we use the same resource type for provisioners and their keys right now

brettkolodny reacted with hooray emoji

@brettkolodnybrettkolodny merged commitcf10d98 intomainMar 25, 2025
30 checks passed
@brettkolodnybrettkolodny deleted the brett-66783/clarify-language-in-server-error-returne branchMarch 25, 2025 19:31
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMar 25, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@EmyrkEmyrkEmyrk left review comments

@aslilacaslilacaslilac approved these changes

Assignees

@brettkolodnybrettkolodny

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Clarify language in server error returned when attempting to delete an org with resources
3 participants
@brettkolodny@aslilac@Emyrk

[8]ページ先頭

©2009-2025 Movatter.jp