mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: autostop workspaces owned by suspended users (#13790)
This commit is contained in:
@ -5844,6 +5844,15 @@ func (q *FakeQuerier) GetWorkspacesEligibleForTransition(ctx context.Context, no
|
||||
workspaces = append(workspaces, workspace)
|
||||
continue
|
||||
}
|
||||
|
||||
user, err := q.getUserByIDNoLock(workspace.OwnerID)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("get user by ID: %w", err)
|
||||
}
|
||||
if user.Status == database.UserStatusSuspended && build.Transition == database.WorkspaceTransitionStart {
|
||||
workspaces = append(workspaces, workspace)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return workspaces, nil
|
||||
|
@ -13426,6 +13426,8 @@ INNER JOIN
|
||||
provisioner_jobs ON workspace_builds.job_id = provisioner_jobs.id
|
||||
INNER JOIN
|
||||
templates ON workspaces.template_id = templates.id
|
||||
INNER JOIN
|
||||
users ON workspaces.owner_id = users.id
|
||||
WHERE
|
||||
workspace_builds.build_number = (
|
||||
SELECT
|
||||
@ -13477,6 +13479,12 @@ WHERE
|
||||
(
|
||||
templates.time_til_dormant_autodelete > 0 AND
|
||||
workspaces.dormant_at IS NOT NULL
|
||||
) OR
|
||||
|
||||
-- If the user account is suspended, and the workspace is running.
|
||||
(
|
||||
users.status = 'suspended'::user_status AND
|
||||
workspace_builds.transition = 'start'::workspace_transition
|
||||
)
|
||||
) AND workspaces.deleted = 'false'
|
||||
`
|
||||
|
@ -557,6 +557,8 @@ INNER JOIN
|
||||
provisioner_jobs ON workspace_builds.job_id = provisioner_jobs.id
|
||||
INNER JOIN
|
||||
templates ON workspaces.template_id = templates.id
|
||||
INNER JOIN
|
||||
users ON workspaces.owner_id = users.id
|
||||
WHERE
|
||||
workspace_builds.build_number = (
|
||||
SELECT
|
||||
@ -608,6 +610,12 @@ WHERE
|
||||
(
|
||||
templates.time_til_dormant_autodelete > 0 AND
|
||||
workspaces.dormant_at IS NOT NULL
|
||||
) OR
|
||||
|
||||
-- If the user account is suspended, and the workspace is running.
|
||||
(
|
||||
users.status = 'suspended'::user_status AND
|
||||
workspace_builds.transition = 'start'::workspace_transition
|
||||
)
|
||||
) AND workspaces.deleted = 'false';
|
||||
|
||||
|
Reference in New Issue
Block a user