8000 fix: improve error message when deleting organization with resources by brettkolodny · Pull Request #17049 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

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 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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter < 8000 /summary>

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: implement dbauthz and dbmem for new query
  • Loading branch information
brettkolodny committed Mar 21, 2025
commit e94e7c9eca3f87a79f86ea0d959426a31def68ef
29 changes: 29 additions & 0 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,35 @@ func (q *querier) GetOrganizationIDsByMemberIDs(ctx context.Context, ids []uuid.
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.GetOrganizationIDsByMemberIDs)(ctx, ids)
}

func (q *querier) GetOrganizationResourceCountByID(ctx context.Context, organizationID uuid.UUID) (database.GetOrganizationResourceCountByIDRow, error) {
// Can read org members
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceOrganizationMember.InOrg(organizationID)); err != nil {
return database.GetOrganizationResourceCountByIDRow{}, err
}

// Can read org workspaces
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceWorkspace.InOrg(organizationID)); err != nil {
return database.GetOrganizationResourceCountByIDRow{}, err
}

// Can read org groups
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceGroup.InOrg(organizationID)); err != nil {
return database.GetOrganizationResourceCountByIDRow{}, err
}

// Can read org templates
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceTemplate.InOrg(organizationID)); err != nil {
return database.GetOrganizationResourceCountByIDRow{}, err
}

// Can read org provisioner jobs
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceProvisionerJobs.InOrg(organizationID)); err != nil {
return database.GetOrganizationResourceCountByIDRow{}, err
}

return q.db.GetOrganizationResourceCountByID(ctx, organizationID)
}

func (q *querier) GetOrganizations(ctx context.Context, args database.GetOrganizationsParams) ([]database.Organization, error) {
fetch := func(ctx context.Context, _ interface{}) ([]database.Organization, error) {
return q.db.GetOrganizations(ctx, args)
Expand Down
48 changes: 48 additions & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -3974,6 +3974,54 @@ func (q *FakeQuerier) GetOrganizationIDsByMemberIDs(_ context.Context, ids []uui
return getOrganizationIDsByMemberIDRows, nil
}

func (q *FakeQuerier) GetOrganizationResourceCountByID(ctx 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()
Expand Down
7 changes: 7 additions & 0 deletions coderd/database/dbmetrics/querymetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions coderd/database/dbmock/dbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0