Skip to content

Commit 3f1e9c0

Browse files
authored
feat(coderd): add endpoints for editing and deleting organizations (#13287)
1 parent 0a86d6d commit 3f1e9c0

File tree

19 files changed

+757
-63
lines changed

19 files changed

+757
-63
lines changed

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@
195195
"**.pb.go": true,
196196
"**/*.gen.json": true,
197197
"**/testdata/*": true,
198-
"**Generated.ts": true,
199198
"coderd/apidoc/**": true,
200199
"docs/api/*.md": true,
201200
"docs/templates/*.md": true,

coderd/apidoc/docs.go

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 75 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,8 @@ func New(options *Options) *API {
812812
httpmw.ExtractOrganizationParam(options.Database),
813813
)
814814
r.Get("/", api.organization)
815+
r.Patch("/", api.patchOrganization)
816+
r.Delete("/", api.deleteOrganization)
815817
r.Post("/templateversions", api.postTemplateVersionsByOrganization)
816818
r.Route("/templates", func(r chi.Router) {
817819
r.Post("/", api.postTemplateByOrganization)

coderd/database/dbauthz/dbauthz.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,10 @@ func (q *querier) DeleteOldWorkspaceAgentStats(ctx context.Context) error {
984984
return q.db.DeleteOldWorkspaceAgentStats(ctx)
985985
}
986986

987+
func (q *querier) DeleteOrganization(ctx context.Context, id uuid.UUID) error {
988+
return deleteQ(q.log, q.auth, q.db.GetOrganizationByID, q.db.DeleteOrganization)(ctx, id)
989+
}
990+
987991
func (q *querier) DeleteReplicasUpdatedBefore(ctx context.Context, updatedAt time.Time) error {
988992
if err := q.authorizeContext(ctx, policy.ActionDelete, rbac.ResourceSystem); err != nil {
989993
return err
@@ -2853,6 +2857,13 @@ func (q *querier) UpdateOAuth2ProviderAppSecretByID(ctx context.Context, arg dat
28532857
return q.db.UpdateOAuth2ProviderAppSecretByID(ctx, arg)
28542858
}
28552859

2860+
func (q *querier) UpdateOrganization(ctx context.Context, arg database.UpdateOrganizationParams) (database.Organization, error) {
2861+
fetch := func(ctx context.Context, arg database.UpdateOrganizationParams) (database.Organization, error) {
2862+
return q.db.GetOrganizationByID(ctx, arg.ID)
2863+
}
2864+
return updateWithReturn(q.log, q.auth, fetch, q.db.UpdateOrganization)(ctx, arg)
2865+
}
2866+
28562867
func (q *querier) UpdateProvisionerDaemonLastSeenAt(ctx context.Context, arg database.UpdateProvisionerDaemonLastSeenAtParams) error {
28572868
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceProvisionerDaemon); err != nil {
28582869
return err

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ func (s *MethodTestSuite) TestOrganization() {
624624
s.Run("InsertOrganization", s.Subtest(func(db database.Store, check *expects) {
625625
check.Args(database.InsertOrganizationParams{
626626
ID: uuid.New(),
627-
Name: "random",
627+
Name: "new-org",
628628
}).Asserts(rbac.ResourceOrganization, policy.ActionCreate)
629629
}))
630630
s.Run("InsertOrganizationMember", s.Subtest(func(db database.Store, check *expects) {
@@ -639,6 +639,23 @@ func (s *MethodTestSuite) TestOrganization() {
639639
rbac.ResourceAssignRole.InOrg(o.ID), policy.ActionAssign,
640640
rbac.ResourceOrganizationMember.InOrg(o.ID).WithID(u.ID), policy.ActionCreate)
641641
}))
642+
s.Run("UpdateOrganization", s.Subtest(func(db database.Store, check *expects) {
643+
o := dbgen.Organization(s.T(), db, database.Organization{
644+
Name: "something-unique",
645+
})
646+
check.Args(database.UpdateOrganizationParams{
647+
ID: o.ID,
648+
Name: "something-different",
649+
}).Asserts(o, policy.ActionUpdate)
650+
}))
651+
s.Run("DeleteOrganization", s.Subtest(func(db database.Store, check *expects) {
652+
o := dbgen.Organization(s.T(), db, database.Organization{
653+
Name: "doomed",
654+
})
655+
check.Args(
656+
o.ID,
657+
).Asserts(o, policy.ActionDelete)
658+
}))
642659
s.Run("UpdateMemberRoles", s.Subtest(func(db database.Store, check *expects) {
643660
o := dbgen.Organization(s.T(), db, database.Organization{})
644661
u := dbgen.User(s.T(), db, database.User{})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy