mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add owner groups to workspace data (#12841)
This commit is contained in:
@@ -467,6 +467,17 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
|
||||
if err != nil {
|
||||
return nil, failJob(fmt.Sprintf("get owner: %s", err))
|
||||
}
|
||||
ownerGroups, err := s.Database.GetGroupsByOrganizationAndUserID(ctx, database.GetGroupsByOrganizationAndUserIDParams{
|
||||
UserID: owner.ID,
|
||||
OrganizationID: s.OrganizationID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, failJob(fmt.Sprintf("get owner group names: %s", err))
|
||||
}
|
||||
ownerGroupNames := []string{}
|
||||
for _, group := range ownerGroups {
|
||||
ownerGroupNames = append(ownerGroupNames, group.Name)
|
||||
}
|
||||
err = s.Pubsub.Publish(codersdk.WorkspaceNotifyChannel(workspace.ID), []byte{})
|
||||
if err != nil {
|
||||
return nil, failJob(fmt.Sprintf("publish workspace update: %s", err))
|
||||
@@ -567,6 +578,7 @@ func (s *server) acquireProtoJob(ctx context.Context, job database.ProvisionerJo
|
||||
WorkspaceOwner: owner.Username,
|
||||
WorkspaceOwnerEmail: owner.Email,
|
||||
WorkspaceOwnerName: owner.Name,
|
||||
WorkspaceOwnerGroups: ownerGroupNames,
|
||||
WorkspaceOwnerOidcAccessToken: workspaceOwnerOIDCAccessToken,
|
||||
WorkspaceId: workspace.ID.String(),
|
||||
WorkspaceOwnerId: owner.ID.String(),
|
||||
|
||||
@@ -182,6 +182,15 @@ func TestAcquireJob(t *testing.T) {
|
||||
defer cancel()
|
||||
|
||||
user := dbgen.User(t, db, database.User{})
|
||||
group1 := dbgen.Group(t, db, database.Group{
|
||||
Name: "group1",
|
||||
OrganizationID: pd.OrganizationID,
|
||||
})
|
||||
err := db.InsertGroupMember(ctx, database.InsertGroupMemberParams{
|
||||
UserID: user.ID,
|
||||
GroupID: group1.ID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
link := dbgen.UserLink(t, db, database.UserLink{
|
||||
LoginType: database.LoginTypeOIDC,
|
||||
UserID: user.ID,
|
||||
@@ -340,6 +349,7 @@ func TestAcquireJob(t *testing.T) {
|
||||
WorkspaceOwnerEmail: user.Email,
|
||||
WorkspaceOwnerName: user.Name,
|
||||
WorkspaceOwnerOidcAccessToken: link.OAuthAccessToken,
|
||||
WorkspaceOwnerGroups: []string{group1.Name},
|
||||
WorkspaceId: workspace.ID.String(),
|
||||
WorkspaceOwnerId: user.ID.String(),
|
||||
TemplateId: template.ID.String(),
|
||||
|
||||
Reference in New Issue
Block a user