Skip to content

Commit 7924bb2

Browse files
authored
feat!: move workspace renames behind flag, disable by default (#11189)
1 parent e63de9a commit 7924bb2

23 files changed

+173
-21
lines changed

cli/rename_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func TestRename(t *testing.T) {
1616
t.Parallel()
1717

18-
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
18+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true, AllowWorkspaceRenames: true})
1919
owner := coderdtest.CreateFirstUser(t, client)
2020
member, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
2121
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)

cli/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
583583
HostnamePrefix: vals.SSHConfig.DeploymentName.String(),
584584
SSHConfigOptions: configSSHOptions,
585585
},
586+
AllowWorkspaceRenames: vals.AllowWorkspaceRenames.Value(),
586587
}
587588
if httpServers.TLSConfig != nil {
588589
options.TLSCertificates = httpServers.TLSConfig.Certificates

cli/testdata/coder_list_--output_json.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"healthy": true,
6060
"failing_agents": []
6161
},
62-
"automatic_updates": "never"
62+
"automatic_updates": "never",
63+
"allow_renames": false
6364
}
6465
]

cli/testdata/coder_server_--help.golden

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ SUBCOMMANDS:
1414
PostgreSQL deployment.
1515

1616
OPTIONS:
17+
--allow-workspace-renames bool, $CODER_ALLOW_WORKSPACE_RENAMES (default: false)
18+
DEPRECATED: Allow users to rename their workspaces. Use only for
19+
temporary compatibility reasons, this will be removed in a future
20+
release.
21+
1722
--cache-dir string, $CODER_CACHE_DIRECTORY (default: [cache dir])
1823
The directory to cache temporary files. If unspecified and
1924
$CACHE_DIRECTORY is set, it will be used for compatibility with

cli/testdata/server-config.yaml.golden

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,7 @@ userQuietHoursSchedule:
462462
# change their quiet hours schedule and the site default is always used.
463463
# (default: true, type: bool)
464464
allowCustomQuietHours: true
465+
# DEPRECATED: Allow users to rename their workspaces. Use only for temporary
466+
# compatibility reasons, this will be removed in a future release.
467+
# (default: false, type: bool)
468+
allowWorkspaceRenames: false

coderd/apidoc/docs.go

Lines changed: 6 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: 6 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ type Options struct {
179179
// This janky function is used in telemetry to parse fields out of the raw
180180
// JWT. It needs to be passed through like this because license parsing is
181181
// under the enterprise license, and can't be imported into AGPL.
182-
ParseLicenseClaims func(rawJWT string) (email string, trial bool, err error)
182+
ParseLicenseClaims func(rawJWT string) (email string, trial bool, err error)
183+
AllowWorkspaceRenames bool
183184
}
184185

185186
// @title Coder API

coderd/coderdtest/coderdtest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ type Options struct {
144144
StatsBatcher *batchstats.Batcher
145145

146146
WorkspaceAppsStatsCollectorOptions workspaceapps.StatsCollectorOptions
147+
AllowWorkspaceRenames bool
147148
}
148149

149150
// New constructs a codersdk client connected to an in-memory API instance.
@@ -449,6 +450,7 @@ func NewOptions(t testing.TB, options *Options) (func(http.Handler), context.Can
449450
HealthcheckRefresh: options.HealthcheckRefresh,
450451
StatsBatcher: options.StatsBatcher,
451452
WorkspaceAppsStatsCollectorOptions: options.WorkspaceAppsStatsCollectorOptions,
453+
AllowWorkspaceRenames: options.AllowWorkspaceRenames,
452454
}
453455
}
454456

coderd/workspaces.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func (api *API) workspace(rw http.ResponseWriter, r *http.Request) {
106106
data.builds[0],
107107
data.templates[0],
108108
ownerName,
109+
api.Options.AllowWorkspaceRenames,
109110
))
110111
}
111112

@@ -277,6 +278,7 @@ func (api *API) workspaceByOwnerAndName(rw http.ResponseWriter, r *http.Request)
277278
data.builds[0],
278279
data.templates[0],
279280
ownerName,
281+
api.Options.AllowWorkspaceRenames,
280282
))
281283
}
282284

@@ -585,6 +587,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
585587
apiBuild,
586588
template,
587589
member.Username,
590+
api.Options.AllowWorkspaceRenames,
588591
))
589592
}
590593

@@ -628,6 +631,12 @@ func (api *API) patchWorkspace(rw http.ResponseWriter, r *http.Request) {
628631
// patched in the future, it's enough if one changes.
629632
name := workspace.Name
630633
if req.Name != "" || req.Name != workspace.Name {
634+
if !api.Options.AllowWorkspaceRenames {
635+
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
636+
Message: "Workspace renames are not allowed.",
637+
})
638+
return
639+
}
631640
name = req.Name
632641
}
633642

@@ -917,6 +926,7 @@ func (api *API) putWorkspaceDormant(rw http.ResponseWriter, r *http.Request) {
917926
data.builds[0],
918927
data.templates[0],
919928
ownerName,
929+
api.Options.AllowWorkspaceRenames,
920930
))
921931
}
922932

@@ -1242,6 +1252,7 @@ func (api *API) watchWorkspace(rw http.ResponseWriter, r *http.Request) {
12421252
data.builds[0],
12431253
data.templates[0],
12441254
ownerName,
1255+
api.Options.AllowWorkspaceRenames,
12451256
),
12461257
})
12471258
}
@@ -1293,9 +1304,10 @@ func (api *API) watchWorkspace(rw http.ResponseWriter, r *http.Request) {
12931304
}
12941305

12951306
type workspaceData struct {
1296-
templates []database.Template
1297-
builds []codersdk.WorkspaceBuild
1298-
users []database.User
1307+
templates []database.Template
1308+
builds []codersdk.WorkspaceBuild
1309+
users []database.User
1310+
allowRenames bool
12991311
}
13001312

13011313
// workspacesData only returns the data the caller can access. If the caller
@@ -1347,9 +1359,10 @@ func (api *API) workspaceData(ctx context.Context, workspaces []database.Workspa
13471359
}
13481360

13491361
return workspaceData{
1350-
templates: templates,
1351-
builds: apiBuilds,
1352-
users: data.users,
1362+
templates: templates,
1363+
builds: apiBuilds,
1364+
users: data.users,
1365+
allowRenames: api.Options.AllowWorkspaceRenames,
13531366
}, nil
13541367
}
13551368

@@ -1392,6 +1405,7 @@ func convertWorkspaces(workspaces []database.Workspace, data workspaceData) ([]c
13921405
build,
13931406
template,
13941407
owner.Username,
1408+
data.allowRenames,
13951409
))
13961410
}
13971411
return apiWorkspaces, nil
@@ -1402,6 +1416,7 @@ func convertWorkspace(
14021416
workspaceBuild codersdk.WorkspaceBuild,
14031417
template database.Template,
14041418
ownerName string,
1419+
allowRenames bool,
14051420
) codersdk.Workspace {
14061421
var autostartSchedule *string
14071422
if workspace.AutostartSchedule.Valid {
@@ -1456,6 +1471,7 @@ func convertWorkspace(
14561471
FailingAgents: failingAgents,
14571472
},
14581473
AutomaticUpdates: codersdk.AutomaticUpdates(workspace.AutomaticUpdates),
1474+
AllowRenames: allowRenames,
14591475
}
14601476
}
14611477

0 commit comments

Comments
 (0)