Skip to content

Commit 06378e4

Browse files
committed
dbauthz and dbmem impls
1 parent f16e0f6 commit 06378e4

File tree

10 files changed

+71
-7
lines changed

10 files changed

+71
-7
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,10 @@ func (q *querier) DeleteOldWorkspaceAgentStats(ctx context.Context) error {
914914
return q.db.DeleteOldWorkspaceAgentStats(ctx)
915915
}
916916

917+
func (q *querier) DeleteOrganization(ctx context.Context, id uuid.UUID) error {
918+
return deleteQ[database.Organization](q.log, q.auth, q.db.GetOrganizationByID, q.db.DeleteOrganization)(ctx, id)
919+
}
920+
917921
func (q *querier) DeleteReplicasUpdatedBefore(ctx context.Context, updatedAt time.Time) error {
918922
if err := q.authorizeContext(ctx, policy.ActionDelete, rbac.ResourceSystem); err != nil {
919923
return err
@@ -2754,7 +2758,10 @@ func (q *querier) UpdateOAuth2ProviderAppSecretByID(ctx context.Context, arg dat
27542758
}
27552759

27562760
func (q *querier) UpdateOrganization(ctx context.Context, arg database.UpdateOrganizationParams) (database.Organization, error) {
2757-
panic("not implemented")
2761+
fetch := func(ctx context.Context, arg database.UpdateOrganizationParams) (database.Organization, error) {
2762+
return q.db.GetOrganizationByID(ctx, arg.ID)
2763+
}
2764+
return updateWithReturn(q.log, q.auth, fetch, q.db.UpdateOrganization)(ctx, arg)
27582765
}
27592766

27602767
func (q *querier) UpdateProvisionerDaemonLastSeenAt(ctx context.Context, arg database.UpdateProvisionerDaemonLastSeenAtParams) error {

coderd/database/dbmem/dbmem.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,16 @@ func (q *FakeQuerier) DeleteOldWorkspaceAgentStats(_ context.Context) error {
15731573
return nil
15741574
}
15751575

1576+
func (q *FakeQuerier) DeleteOrganization(ctx context.Context, id uuid.UUID) error {
1577+
for i, org := range q.organizations {
1578+
if org.ID == id {
1579+
q.organizations = append(q.organizations[:i], q.organizations[i+1:]...)
1580+
return nil
1581+
}
1582+
}
1583+
return sql.ErrNoRows
1584+
}
1585+
15761586
func (q *FakeQuerier) DeleteReplicasUpdatedBefore(_ context.Context, before time.Time) error {
15771587
q.mutex.Lock()
15781588
defer q.mutex.Unlock()
@@ -7149,7 +7159,14 @@ func (q *FakeQuerier) UpdateOrganization(ctx context.Context, arg database.Updat
71497159
return database.Organization{}, err
71507160
}
71517161

7152-
panic("not implemented")
7162+
for i, org := range q.organizations {
7163+
if org.ID == arg.ID {
7164+
org.Name = arg.Name
7165+
q.organizations[i] = org
7166+
return org, nil
7167+
}
7168+
}
7169+
return database.Organization{}, sql.ErrNoRows
71537170
}
71547171

71557172
func (q *FakeQuerier) UpdateProvisionerDaemonLastSeenAt(_ context.Context, arg database.UpdateProvisionerDaemonLastSeenAtParams) error {

coderd/database/dbmetrics/dbmetrics.go

Lines changed: 7 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: 14 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: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

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

coderd/database/queries/organizations.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ VALUES
5454
-- If no organizations exist, and this is the first, make it the default.
5555
($1, $2, $3, $4, $5, (SELECT TRUE FROM organizations LIMIT 1) IS NULL) RETURNING *;
5656

57-
5857
-- name: UpdateOrganization :one
5958
UPDATE
6059
organizations
@@ -64,3 +63,10 @@ SET
6463
WHERE
6564
id = $1
6665
RETURNING *;
66+
67+
-- name: DeleteOrganization :exec
68+
DELETE FROM
69+
organizations
70+
WHERE
71+
id = $1 AND
72+
is_default = false;

coderd/organizations.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ func (api *API) postOrganizations(rw http.ResponseWriter, r *http.Request) {
129129
// @Router /organizations/{organization} [patch]
130130
func (api *API) patchOrganization(rw http.ResponseWriter, r *http.Request) {
131131
ctx := r.Context()
132-
apiKey := httpmw.APIKey(r)
133132

134133
var req codersdk.PatchOrganizationRequest
135134
if !httpapi.Read(ctx, rw, r, &req) {

coderd/rbac/object.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ type Object struct {
3636
func (z Object) ValidAction(action policy.Action) error {
3737
perms, ok := policy.RBACPermissions[z.Type]
3838
if !ok {
39-
return fmt.Errorf("invalid type %q", z.Type)
39+
return xerrors.Errorf("invalid type %q", z.Type)
4040
}
4141
if _, ok := perms.Actions[action]; !ok {
42-
return fmt.Errorf("invalid action %q for type %q", action, z.Type)
42+
return xerrors.Errorf("invalid action %q for type %q", action, z.Type)
4343
}
4444

4545
return nil

coderd/rbac/roles_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func TestRolePermissions(t *testing.T) {
359359
},
360360
// Some admin style resources
361361
{
362-
Name: "Licences",
362+
Name: "Licenses",
363363
Actions: []policy.Action{policy.ActionCreate, policy.ActionRead, policy.ActionDelete},
364364
Resource: rbac.ResourceLicense,
365365
AuthorizeMap: map[bool][]authSubject{

0 commit comments

Comments
 (0)