mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +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:
@ -4008,6 +4008,54 @@ func (q *FakeQuerier) GetOrganizationIDsByMemberIDs(_ context.Context, ids []uui
|
||||
return getOrganizationIDsByMemberIDRows, nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) GetOrganizationResourceCountByID(_ context.Context, organizationID uuid.UUID) (database.GetOrganizationResourceCountByIDRow, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
workspacesCount := 0
|
||||
for _, workspace := range q.workspaces {
|
||||
if workspace.OrganizationID == organizationID {
|
||||
workspacesCount++
|
||||
}
|
||||
}
|
||||
|
||||
groupsCount := 0
|
||||
for _, group := range q.groups {
|
||||
if group.OrganizationID == organizationID {
|
||||
groupsCount++
|
||||
}
|
||||
}
|
||||
|
||||
templatesCount := 0
|
||||
for _, template := range q.templates {
|
||||
if template.OrganizationID == organizationID {
|
||||
templatesCount++
|
||||
}
|
||||
}
|
||||
|
||||
organizationMembersCount := 0
|
||||
for _, organizationMember := range q.organizationMembers {
|
||||
if organizationMember.OrganizationID == organizationID {
|
||||
organizationMembersCount++
|
||||
}
|
||||
}
|
||||
|
||||
provKeyCount := 0
|
||||
for _, provKey := range q.provisionerKeys {
|
||||
if provKey.OrganizationID == organizationID {
|
||||
provKeyCount++
|
||||
}
|
||||
}
|
||||
|
||||
return database.GetOrganizationResourceCountByIDRow{
|
||||
WorkspaceCount: int64(workspacesCount),
|
||||
GroupCount: int64(groupsCount),
|
||||
TemplateCount: int64(templatesCount),
|
||||
MemberCount: int64(organizationMembersCount),
|
||||
ProvisionerKeyCount: int64(provKeyCount),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (q *FakeQuerier) GetOrganizations(_ context.Context, args database.GetOrganizationsParams) ([]database.Organization, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
Reference in New Issue
Block a user