Skip to content

Commit 0b5542f

Browse files
authored
fix: update task link AppStatus using task_id (coder#20543) (coder#20551)
Fixes coder#20515 Alternative to coder#20519 Adds `task_id` to `workspaces_expanded` view and updates the "View Task" link in `AppStatuses` component. NOTE: this contains a migration (cherry picked from commit 1ebc217) <!-- If you have used AI to produce some or all of this PR, please ensure you have read our [AI Contribution guidelines](https://coder.com/docs/about/contributing/AI_CONTRIBUTING) before submitting. -->
1 parent ba14acf commit 0b5542f

File tree

20 files changed

+213
-22
lines changed

20 files changed

+213
-22
lines changed

cli/testdata/coder_list_--output_json.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"allow_renames": false,
9191
"favorite": false,
9292
"next_start_at": "====[timestamp]=====",
93-
"is_prebuild": false
93+
"is_prebuild": false,
94+
"task_id": null
9495
}
9596
]

coderd/aitasks_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ func TestTasks(t *testing.T) {
259259
// Wait for the workspace to be built.
260260
workspace, err := client.Workspace(ctx, task.WorkspaceID.UUID)
261261
require.NoError(t, err)
262+
if assert.True(t, workspace.TaskID.Valid, "task id should be set on workspace") {
263+
assert.Equal(t, task.ID, workspace.TaskID.UUID, "workspace task id should match")
264+
}
262265
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
263266

264267
// List tasks via experimental API and verify the prompt and status mapping.
@@ -297,6 +300,9 @@ func TestTasks(t *testing.T) {
297300
// Get the workspace and wait for it to be ready.
298301
ws, err := client.Workspace(ctx, task.WorkspaceID.UUID)
299302
require.NoError(t, err)
303+
if assert.True(t, ws.TaskID.Valid, "task id should be set on workspace") {
304+
assert.Equal(t, task.ID, ws.TaskID.UUID, "workspace task id should match")
305+
}
300306
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, ws.LatestBuild.ID)
301307
ws = coderdtest.MustWorkspace(t, client, task.WorkspaceID.UUID)
302308
// Assert invariant: the workspace has exactly one resource with one agent with one app.
@@ -371,6 +377,9 @@ func TestTasks(t *testing.T) {
371377
require.True(t, task.WorkspaceID.Valid, "task should have a workspace ID")
372378
ws, err := client.Workspace(ctx, task.WorkspaceID.UUID)
373379
require.NoError(t, err)
380+
if assert.True(t, ws.TaskID.Valid, "task id should be set on workspace") {
381+
assert.Equal(t, task.ID, ws.TaskID.UUID, "workspace task id should match")
382+
}
374383
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, ws.LatestBuild.ID)
375384

376385
err = exp.DeleteTask(ctx, "me", task.ID)
@@ -417,6 +426,9 @@ func TestTasks(t *testing.T) {
417426
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
418427
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
419428
ws := coderdtest.CreateWorkspace(t, client, template.ID)
429+
if assert.False(t, ws.TaskID.Valid, "task id should not be set on non-task workspace") {
430+
assert.Zero(t, ws.TaskID, "non-task workspace task id should be empty")
431+
}
420432
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, ws.LatestBuild.ID)
421433

422434
exp := codersdk.NewExperimentalClient(client)

coderd/apidoc/docs.go

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

coderd/database/dump.sql

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
DROP VIEW workspaces_expanded;
2+
3+
-- Recreate the view from 000354_workspace_acl.up.sql
4+
CREATE VIEW workspaces_expanded AS
5+
SELECT workspaces.id,
6+
workspaces.created_at,
7+
workspaces.updated_at,
8+
workspaces.owner_id,
9+
workspaces.organization_id,
10+
workspaces.template_id,
11+
workspaces.deleted,
12+
workspaces.name,
13+
workspaces.autostart_schedule,
14+
workspaces.ttl,
15+
workspaces.last_used_at,
16+
workspaces.dormant_at,
17+
workspaces.deleting_at,
18+
workspaces.automatic_updates,
19+
workspaces.favorite,
20+
workspaces.next_start_at,
21+
workspaces.group_acl,
22+
workspaces.user_acl,
23+
visible_users.avatar_url AS owner_avatar_url,
24+
visible_users.username AS owner_username,
25+
visible_users.name AS owner_name,
26+
organizations.name AS organization_name,
27+
organizations.display_name AS organization_display_name,
28+
organizations.icon AS organization_icon,
29+
organizations.description AS organization_description,
30+
templates.name AS template_name,
31+
templates.display_name AS template_display_name,
32+
templates.icon AS template_icon,
33+
templates.description AS template_description
34+
FROM (((workspaces
35+
JOIN visible_users ON ((workspaces.owner_id = visible_users.id)))
36+
JOIN organizations ON ((workspaces.organization_id = organizations.id)))
37+
JOIN templates ON ((workspaces.template_id = templates.id)));
38+
39+
COMMENT ON VIEW workspaces_expanded IS 'Joins in the display name information such as username, avatar, and organization name.';
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
DROP VIEW workspaces_expanded;
2+
3+
-- Add nullable task_id to workspaces_expanded view
4+
CREATE VIEW workspaces_expanded AS
5+
SELECT workspaces.id,
6+
workspaces.created_at,
7+
workspaces.updated_at,
8+
workspaces.owner_id,
9+
workspaces.organization_id,
10+
workspaces.template_id,
11+
workspaces.deleted,
12+
workspaces.name,
13+
workspaces.autostart_schedule,
14+
workspaces.ttl,
15+
workspaces.last_used_at,
16+
workspaces.dormant_at,
17+
workspaces.deleting_at,
18+
workspaces.automatic_updates,
19+
workspaces.favorite,
20+
workspaces.next_start_at,
21+
workspaces.group_acl,
22+
workspaces.user_acl,
23+
visible_users.avatar_url AS owner_avatar_url,
24+
visible_users.username AS owner_username,
25+
visible_users.name AS owner_name,
26+
organizations.name AS organization_name,
27+
organizations.display_name AS organization_display_name,
28+
organizations.icon AS organization_icon,
29+
organizations.description AS organization_description,
30+
templates.name AS template_name,
31+
templates.display_name AS template_display_name,
32+
templates.icon AS template_icon,
33+
templates.description AS template_description,
34+
tasks.id AS task_id
35+
FROM ((((workspaces
36+
JOIN visible_users ON ((workspaces.owner_id = visible_users.id)))
37+
JOIN organizations ON ((workspaces.organization_id = organizations.id)))
38+
JOIN templates ON ((workspaces.template_id = templates.id)))
39+
LEFT JOIN tasks ON ((workspaces.id = tasks.workspace_id)));
40+
41+
COMMENT ON VIEW workspaces_expanded IS 'Joins in the display name information such as username, avatar, and organization name.';
42+

coderd/database/modelqueries.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
321321
&i.TemplateDisplayName,
322322
&i.TemplateIcon,
323323
&i.TemplateDescription,
324+
&i.TaskID,
324325
&i.TemplateVersionID,
325326
&i.TemplateVersionName,
326327
&i.LatestBuildCompletedAt,

coderd/database/models.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.

0 commit comments

Comments
 (0)