mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix: improve error message when deleting organization with resources (#17049)
Closes [coder/internal#477](https://github.com/coder/internal/issues/477)  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
This commit is contained in:
@ -815,6 +815,39 @@ func (s *MethodTestSuite) TestOrganization() {
|
||||
o := dbgen.Organization(s.T(), db, database.Organization{})
|
||||
check.Args(o.ID).Asserts(o, policy.ActionRead).Returns(o)
|
||||
}))
|
||||
s.Run("GetOrganizationResourceCountByID", s.Subtest(func(db database.Store, check *expects) {
|
||||
u := dbgen.User(s.T(), db, database.User{})
|
||||
o := dbgen.Organization(s.T(), db, database.Organization{})
|
||||
|
||||
t := dbgen.Template(s.T(), db, database.Template{
|
||||
CreatedBy: u.ID,
|
||||
OrganizationID: o.ID,
|
||||
})
|
||||
dbgen.Workspace(s.T(), db, database.WorkspaceTable{
|
||||
OrganizationID: o.ID,
|
||||
OwnerID: u.ID,
|
||||
TemplateID: t.ID,
|
||||
})
|
||||
dbgen.Group(s.T(), db, database.Group{OrganizationID: o.ID})
|
||||
dbgen.OrganizationMember(s.T(), db, database.OrganizationMember{
|
||||
OrganizationID: o.ID,
|
||||
UserID: u.ID,
|
||||
})
|
||||
|
||||
check.Args(o.ID).Asserts(
|
||||
rbac.ResourceOrganizationMember.InOrg(o.ID), policy.ActionRead,
|
||||
rbac.ResourceWorkspace.InOrg(o.ID), policy.ActionRead,
|
||||
rbac.ResourceGroup.InOrg(o.ID), policy.ActionRead,
|
||||
rbac.ResourceTemplate.InOrg(o.ID), policy.ActionRead,
|
||||
rbac.ResourceProvisionerDaemon.InOrg(o.ID), policy.ActionRead,
|
||||
).Returns(database.GetOrganizationResourceCountByIDRow{
|
||||
WorkspaceCount: 1,
|
||||
GroupCount: 1,
|
||||
TemplateCount: 1,
|
||||
MemberCount: 1,
|
||||
ProvisionerKeyCount: 0,
|
||||
})
|
||||
}))
|
||||
s.Run("GetDefaultOrganization", s.Subtest(func(db database.Store, check *expects) {
|
||||
o, _ := db.GetDefaultOrganization(context.Background())
|
||||
check.Args().Asserts(o, policy.ActionRead).Returns(o)
|
||||
|
Reference in New Issue
Block a user