mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
fix: respect automatic_updates policy when building workspace action list (#26362)
This commit is contained in:
@@ -86,6 +86,11 @@ export const abilitiesByWorkspaceStatus = (
|
||||
|
||||
if (workspace.template_require_active_version && workspace.outdated) {
|
||||
actions.push("updateAndRestartRequireActiveVersion");
|
||||
} else if (
|
||||
workspace.automatic_updates === "always" &&
|
||||
workspace.outdated
|
||||
) {
|
||||
actions.unshift("updateAndRestart");
|
||||
} else {
|
||||
if (workspace.outdated) {
|
||||
actions.unshift("updateAndRestart");
|
||||
@@ -111,6 +116,11 @@ export const abilitiesByWorkspaceStatus = (
|
||||
|
||||
if (workspace.template_require_active_version && workspace.outdated) {
|
||||
actions.push("updateAndStartRequireActiveVersion");
|
||||
} else if (
|
||||
workspace.automatic_updates === "always" &&
|
||||
workspace.outdated
|
||||
) {
|
||||
actions.push("updateAndStart");
|
||||
} else {
|
||||
if (workspace.outdated) {
|
||||
actions.unshift("updateAndStart");
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
} from "#/modules/workspaces/actions";
|
||||
import type { WorkspacePermissions } from "#/modules/workspaces/permissions";
|
||||
import { WorkspaceMoreActions } from "#/modules/workspaces/WorkspaceMoreActions/WorkspaceMoreActions";
|
||||
import { mustUpdateWorkspace } from "#/utils/workspace";
|
||||
import {
|
||||
ActivateButton,
|
||||
CancelButton,
|
||||
@@ -71,13 +70,8 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
|
||||
},
|
||||
);
|
||||
|
||||
const mustUpdate = mustUpdateWorkspace(
|
||||
workspace,
|
||||
permissions.updateWorkspaceVersion,
|
||||
);
|
||||
const tooltipText = getTooltipText(
|
||||
workspace,
|
||||
mustUpdate,
|
||||
permissions.updateWorkspaceVersion,
|
||||
);
|
||||
|
||||
@@ -116,7 +110,6 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
|
||||
<StartButton
|
||||
workspace={workspace}
|
||||
handleAction={handleStart}
|
||||
disabled={mustUpdate}
|
||||
tooltipText={tooltipText}
|
||||
/>
|
||||
),
|
||||
@@ -125,17 +118,16 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
|
||||
loading
|
||||
workspace={workspace}
|
||||
handleAction={handleStart}
|
||||
disabled={mustUpdate}
|
||||
tooltipText={tooltipText}
|
||||
/>
|
||||
),
|
||||
|
||||
stop: <StopButton handleAction={handleStop} />,
|
||||
stopping: <StopButton loading handleAction={handleStop} />,
|
||||
restart: (
|
||||
<RestartButton
|
||||
workspace={workspace}
|
||||
handleAction={handleRestart}
|
||||
disabled={mustUpdate}
|
||||
tooltipText={tooltipText}
|
||||
/>
|
||||
),
|
||||
@@ -144,10 +136,10 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
|
||||
loading
|
||||
workspace={workspace}
|
||||
handleAction={handleRestart}
|
||||
disabled={mustUpdate}
|
||||
tooltipText={tooltipText}
|
||||
/>
|
||||
),
|
||||
|
||||
deleting: <DisabledButton label="Deleting" />,
|
||||
canceling: <DisabledButton label="Canceling..." />,
|
||||
deleted: <DisabledButton label="Deleted" />,
|
||||
@@ -203,18 +195,9 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
|
||||
|
||||
function getTooltipText(
|
||||
workspace: Workspace,
|
||||
mustUpdate: boolean,
|
||||
canChangeVersions: boolean,
|
||||
): string {
|
||||
if (!mustUpdate && !canChangeVersions) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (
|
||||
!mustUpdate &&
|
||||
canChangeVersions &&
|
||||
workspace.template_require_active_version
|
||||
) {
|
||||
if (canChangeVersions && workspace.template_require_active_version) {
|
||||
return "This template requires automatic updates on workspace startup, but template administrators can ignore this policy.";
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import type {
|
||||
import {
|
||||
MockDormantOutdatedWorkspace,
|
||||
MockDormantWorkspace,
|
||||
MockOutdatedStoppedWorkspaceAlwaysUpdate,
|
||||
MockOutdatedWorkspace,
|
||||
MockRunningOutdatedWorkspace,
|
||||
MockStoppedWorkspace,
|
||||
@@ -394,4 +395,21 @@ describe("WorkspaceApps filtering", () => {
|
||||
}),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("does not show start button for stopped outdated workspace with automatic_updates always", async () => {
|
||||
vi.spyOn(API, "getWorkspaces").mockResolvedValue({
|
||||
workspaces: [MockOutdatedStoppedWorkspaceAlwaysUpdate],
|
||||
count: 1,
|
||||
});
|
||||
|
||||
renderWithAuth(<WorkspacesPage />);
|
||||
await waitForLoaderToBeRemoved();
|
||||
|
||||
expect(
|
||||
screen.queryByRole("button", { name: "Start workspace" }),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Update and start workspace" }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1804,7 +1804,7 @@ export const MockOutdatedStoppedWorkspaceRequireActiveVersion: TypesGen.Workspac
|
||||
},
|
||||
};
|
||||
|
||||
const _MockOutdatedStoppedWorkspaceAlwaysUpdate: TypesGen.Workspace = {
|
||||
export const MockOutdatedStoppedWorkspaceAlwaysUpdate: TypesGen.Workspace = {
|
||||
...MockOutdatedRunningWorkspaceAlwaysUpdate,
|
||||
latest_build: {
|
||||
...MockWorkspaceBuild,
|
||||
|
||||
Reference in New Issue
Block a user