Skip to content

Commit 7751257

Browse files
committed
Merge branch 'edit-and-delete-orgs' into org-management-ui
2 parents 6160318 + dda30ec commit 7751257

File tree

19 files changed

+736
-23
lines changed

19 files changed

+736
-23
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
@@ -983,6 +983,10 @@ func (q *querier) DeleteOldWorkspaceAgentStats(ctx context.Context) error {
983983
return q.db.DeleteOldWorkspaceAgentStats(ctx)
984984
}
985985

986+
func (q *querier) DeleteOrganization(ctx context.Context, id uuid.UUID) error {
987+
return deleteQ(q.log, q.auth, q.db.GetOrganizationByID, q.db.DeleteOrganization)(ctx, id)
988+
}
989+
986990
func (q *querier) DeleteReplicasUpdatedBefore(ctx context.Context, updatedAt time.Time) error {
987991
if err := q.authorizeContext(ctx, policy.ActionDelete, rbac.ResourceSystem); err != nil {
988992
return err
@@ -2822,6 +2826,13 @@ func (q *querier) UpdateOAuth2ProviderAppSecretByID(ctx context.Context, arg dat
28222826
return q.db.UpdateOAuth2ProviderAppSecretByID(ctx, arg)
28232827
}
28242828

2829+
func (q *querier) UpdateOrganization(ctx context.Context, arg database.UpdateOrganizationParams) (database.Organization, error) {
2830+
fetch := func(ctx context.Context, arg database.UpdateOrganizationParams) (database.Organization, error) {
2831+
return q.db.GetOrganizationByID(ctx, arg.ID)
2832+
}
2833+
return updateWithReturn(q.log, q.auth, fetch, q.db.UpdateOrganization)(ctx, arg)
2834+
}
2835+
28252836
func (q *querier) UpdateProvisionerDaemonLastSeenAt(ctx context.Context, arg database.UpdateProvisionerDaemonLastSeenAtParams) error {
28262837
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceProvisionerDaemon); err != nil {
28272838
return err

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 24 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,29 @@ 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+
ctx := testutil.Context(s.T(), testutil.WaitShort)
644+
o, err := db.InsertOrganization(ctx, database.InsertOrganizationParams{
645+
ID: uuid.New(),
646+
Name: "something-unique",
647+
})
648+
require.NoError(s.T(), err)
649+
check.Args(database.UpdateOrganizationParams{
650+
ID: o.ID,
651+
Name: "something-different",
652+
}).Asserts(o, policy.ActionUpdate)
653+
}))
654+
s.Run("DeleteOrganization", s.Subtest(func(db database.Store, check *expects) {
655+
ctx := testutil.Context(s.T(), testutil.WaitShort)
656+
o, err := db.InsertOrganization(ctx, database.InsertOrganizationParams{
657+
ID: uuid.New(),
658+
Name: "doomed",
659+
})
660+
require.NoError(s.T(), err)
661+
check.Args(
662+
o.ID,
663+
).Asserts(o, policy.ActionDelete)
664+
}))
642665
s.Run("UpdateMemberRoles", s.Subtest(func(db database.Store, check *expects) {
643666
o := dbgen.Organization(s.T(), db, database.Organization{})
644667
u := dbgen.User(s.T(), db, database.User{})

coderd/database/dbmem/dbmem.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,16 @@ func (q *FakeQuerier) DeleteOldWorkspaceAgentStats(_ context.Context) error {
15921592
return nil
15931593
}
15941594

1595+
func (q *FakeQuerier) DeleteOrganization(_ context.Context, id uuid.UUID) error {
1596+
for i, org := range q.organizations {
1597+
if org.ID == id && !org.IsDefault {
1598+
q.organizations = append(q.organizations[:i], q.organizations[i+1:]...)
1599+
return nil
1600+
}
1601+
}
1602+
return sql.ErrNoRows
1603+
}
1604+
15951605
func (q *FakeQuerier) DeleteReplicasUpdatedBefore(_ context.Context, before time.Time) error {
15961606
q.mutex.Lock()
15971607
defer q.mutex.Unlock()
@@ -7232,6 +7242,22 @@ func (q *FakeQuerier) UpdateOAuth2ProviderAppSecretByID(_ context.Context, arg d
72327242
return database.OAuth2ProviderAppSecret{}, sql.ErrNoRows
72337243
}
72347244

7245+
func (q *FakeQuerier) UpdateOrganization(_ context.Context, arg database.UpdateOrganizationParams) (database.Organization, error) {
7246+
err := validateDatabaseType(arg)
7247+
if err != nil {
7248+
return database.Organization{}, err
7249+
}
7250+
7251+
for i, org := range q.organizations {
7252+
if org.ID == arg.ID {
7253+
org.Name = arg.Name
7254+
q.organizations[i] = org
7255+
return org, nil
7256+
}
7257+
}
7258+
return database.Organization{}, sql.ErrNoRows
7259+
}
7260+
72357261
func (q *FakeQuerier) UpdateProvisionerDaemonLastSeenAt(_ context.Context, arg database.UpdateProvisionerDaemonLastSeenAtParams) error {
72367262
err := validateDatabaseType(arg)
72377263
if err != nil {

coderd/database/dbmetrics/dbmetrics.go

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

coderd/database/dbmock/dbmock.go

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

coderd/database/querier.go

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

0 commit comments

Comments
 (0)