Skip to content

Commit e788b3b

Browse files
committed
remove new query
1 parent a8277a0 commit e788b3b

File tree

9 files changed

+31
-94
lines changed

9 files changed

+31
-94
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,6 @@ func (q *querier) GetGroupsByOrganizationID(ctx context.Context, organizationID
11451145
return fetchWithPostFilter(q.auth, q.db.GetGroupsByOrganizationID)(ctx, organizationID)
11461146
}
11471147

1148-
func (q *querier) GetGroupsByUserID(ctx context.Context, userID uuid.UUID) ([]database.Group, error) {
1149-
panic("not implemented")
1150-
}
1151-
11521148
func (q *querier) GetHealthSettings(ctx context.Context) (string, error) {
11531149
// No authz checks
11541150
return q.db.GetHealthSettings(ctx)

coderd/database/dbmem/dbmem.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,10 +2264,6 @@ func (q *FakeQuerier) GetGroupsByOrganizationID(_ context.Context, id uuid.UUID)
22642264
return groups, nil
22652265
}
22662266

2267-
func (q *FakeQuerier) GetGroupsByUserID(ctx context.Context, userID uuid.UUID) ([]database.Group, error) {
2268-
panic("not implemented")
2269-
}
2270-
22712267
func (q *FakeQuerier) GetHealthSettings(_ context.Context) (string, error) {
22722268
q.mutex.RLock()
22732269
defer q.mutex.RUnlock()

coderd/database/dbmetrics/dbmetrics.go

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

coderd/database/queries/groupmembers.sql

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@ WHERE
2323
AND
2424
users.deleted = 'false';
2525

26-
-- name: GetGroupsByUserID :many
27-
SELECT
28-
groups.*
29-
FROM
30-
groups
31-
LEFT JOIN
32-
group_members
33-
ON
34-
group_members.group_id = groups.id
35-
WHERE
36-
group_members.user_id = @user_id;
37-
3826
-- InsertUserGroupsByName adds a user to all provided groups, if they exist.
3927
-- name: InsertUserGroupsByName :exec
4028
WITH groups AS (

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,14 +467,23 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
467467
if err != nil {
468468
return nil, failJob(fmt.Sprintf("get owner: %s", err))
469469
}
470-
ownerGroups, err := s.Database.GetGroupsByUserID(ctx, owner.ID)
471-
ownerGroupNames := make([]string, 0, len(ownerGroups))
472-
for _, group := range ownerGroups {
473-
ownerGroupNames = append(ownerGroupNames, group.Name)
474-
}
470+
orgGroups, err := s.Database.GetGroupsByOrganizationID(ctx, workspace.OrganizationID)
475471
if err != nil {
476472
return nil, failJob(fmt.Sprintf("get owner groups: %s", err))
477473
}
474+
ownerGroupNames := []string{}
475+
for _, group := range orgGroups {
476+
members, err := s.Database.GetGroupMembers(ctx, group.ID)
477+
if err != nil {
478+
return nil, failJob(fmt.Sprintf("get group members: %s", err))
479+
}
480+
for _, member := range members {
481+
if member.ID == owner.ID {
482+
ownerGroupNames = append(ownerGroupNames, group.Name)
483+
break
484+
}
485+
}
486+
}
478487
err = s.Pubsub.Publish(codersdk.WorkspaceNotifyChannel(workspace.ID), []byte{})
479488
if err != nil {
480489
return nil, failJob(fmt.Sprintf("publish workspace update: %s", err))

provisioner/terraform/provision.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package terraform
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"os"
78
"strings"
89
"time"
910

1011
"github.com/spf13/afero"
12+
"golang.org/x/xerrors"
1113

1214
"cdr.dev/slog"
1315
"github.com/coder/terraform-provider-coder/provider"
@@ -186,6 +188,11 @@ func provisionEnv(
186188
richParams []*proto.RichParameterValue, externalAuth []*proto.ExternalAuthProvider,
187189
) ([]string, error) {
188190
env := safeEnviron()
191+
ownerGroups, err := json.Marshal(metadata.WorkspaceOwnerGroups)
192+
if err != nil {
193+
return nil, xerrors.Errorf("marshal owner groups: %w", err)
194+
}
195+
189196
env = append(env,
190197
"CODER_AGENT_URL="+metadata.GetCoderUrl(),
191198
"CODER_WORKSPACE_TRANSITION="+strings.ToLower(metadata.GetWorkspaceTransition().String()),
@@ -194,6 +201,7 @@ func provisionEnv(
194201
"CODER_WORKSPACE_OWNER_EMAIL="+metadata.GetWorkspaceOwnerEmail(),
195202
"CODER_WORKSPACE_OWNER_NAME="+metadata.GetWorkspaceOwnerName(),
196203
"CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN="+metadata.GetWorkspaceOwnerOidcAccessToken(),
204+
"CODER_WORKSPACE_OWNER_GROUPS="+string(ownerGroups),
197205
"CODER_WORKSPACE_ID="+metadata.GetWorkspaceId(),
198206
"CODER_WORKSPACE_OWNER_ID="+metadata.GetWorkspaceOwnerId(),
199207
"CODER_WORKSPACE_OWNER_SESSION_TOKEN="+metadata.GetWorkspaceOwnerSessionToken(),

0 commit comments

Comments
 (0)