Skip to content

Commit f3b7b9a

Browse files
committed
use query over route logic
1 parent f1d3279 commit f3b7b9a

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3704,6 +3704,9 @@ func (q *FakeQuerier) GetWorkspaceAgentAndOwnerByAuthToken(_ context.Context, au
37043704
if build.WorkspaceID != ws.ID {
37053705
continue
37063706
}
3707+
if ws.Deleted {
3708+
continue
3709+
}
37073710
var row database.GetWorkspaceAgentAndOwnerByAuthTokenRow
37083711
row.WorkspaceID = ws.ID
37093712
usr, err := q.getUserByIDNoLock(ws.OwnerID)

coderd/database/queries.sql.go

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

coderd/database/queries/workspaceagents.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,10 @@ FROM users
252252
WHERE
253253
-- TODO: we can add more conditions here, such as:
254254
-- 1) The user must be active
255-
-- 2) The user must not be deleted
256-
-- 3) The workspace must be running
255+
-- 2) The workspace must be running
257256
workspace_agents.auth_token = @auth_token
257+
AND
258+
workspaces.deleted = FALSE
258259
GROUP BY
259260
workspace_agents.id,
260261
workspaces.id,

coderd/workspaceagents.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,13 +1653,6 @@ func (api *API) workspaceAgentReportStats(rw http.ResponseWriter, r *http.Reques
16531653
return
16541654
}
16551655

1656-
if workspace.Deleted {
1657-
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
1658-
Message: "Workspace has been deleted.",
1659-
})
1660-
return
1661-
}
1662-
16631656
var req agentsdk.Stats
16641657
if !httpapi.Read(ctx, rw, r, &req) {
16651658
return

coderd/workspaceagents_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ func TestWorkspaceAgentReportStats(t *testing.T) {
929929
SessionCountSSH: 0,
930930
ConnectionMedianLatencyMS: 10,
931931
})
932-
require.ErrorContains(t, err, "Workspace has been deleted.")
932+
require.ErrorContains(t, err, "agent is invalid")
933933
})
934934
}
935935

0 commit comments

Comments
 (0)