Skip to content

Commit

Permalink
[dashbaord, server] Remove api.maySetTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
geropl committed Sep 21, 2023
1 parent d7ba4db commit 267805a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 85 deletions.

This file was deleted.

89 changes: 45 additions & 44 deletions components/dashboard/src/user-settings/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,23 @@ import { getGitpodService } from "../service/service";
import { UserContext } from "../user-context";
import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu";
import { ThemeSelector } from "../components/ThemeSelector";
import Alert from "../components/Alert";
import { Link } from "react-router-dom";
import { Heading2, Heading3, Subheading } from "../components/typography/headings";
import { useUserMaySetTimeout } from "../data/current-user/may-set-timeout-query";
import { Button } from "../components/Button";
import SelectIDE from "./SelectIDE";
import { InputField } from "../components/forms/InputField";
import { TextInput } from "../components/forms/TextInputField";
import { useToast } from "../components/toasts/Toasts";
import { useUpdateCurrentUserDotfileRepoMutation } from "../data/current-user/update-mutation";
import { AdditionalUserData } from "@gitpod/gitpod-protocol";
import { useOrgBillingMode } from "../data/billing-mode/org-billing-mode-query";

export type IDEChangedTrackLocation = "workspace_list" | "workspace_start" | "preferences";

export default function Preferences() {
const { toast } = useToast();
const { user, setUser } = useContext(UserContext);
const maySetTimeout = useUserMaySetTimeout();
const billingMode = useOrgBillingMode();
const updateDotfileRepo = useUpdateCurrentUserDotfileRepoMutation();

const [dotfileRepo, setDotfileRepo] = useState<string>(user?.additionalData?.dotfileRepo || "");
Expand Down Expand Up @@ -57,15 +56,29 @@ export default function Preferences() {
const updatedUser = await getGitpodService().server.getLoggedInUser();
setUser(updatedUser);

toast("Your default workspace timeout was updated.");
let toastMessage = <>"Your default workspace timeout was updated."</>;
if (billingMode.data?.mode === "usage-based") {
if (!billingMode.data.paid) {
toastMessage = (
<>
{toastMessage} Note that this will only affect workspaces in paid organizations. Go to{" "}
<Link to="/billing" className="gp-link">
billing
</Link>{" "}
to upgrade your organization.
</>
);
}
}
toast(toastMessage);
} catch (e) {
// TODO: Convert this to an error style toast
alert("Cannot set custom workspace timeout: " + e.message);
} finally {
setTimeoutUpdating(false);
}
},
[toast, setUser, workspaceTimeout],
[toast, setUser, workspaceTimeout, billingMode],
);

const clearAutostartWorkspaceOptions = useCallback(async () => {
Expand Down Expand Up @@ -136,46 +149,34 @@ export default function Preferences() {
<Subheading>Workspaces will stop after a period of inactivity without any user input.</Subheading>

<div className="mt-4 max-w-xl">
{!maySetTimeout.isLoading && maySetTimeout.data === false && (
<Alert type="message">
Upgrade organization{" "}
<Link to="/billing" className="gp-link">
billing
</Link>{" "}
plan to use a custom inactivity timeout.
</Alert>
)}

{maySetTimeout.data === true && (
<form onSubmit={saveWorkspaceTimeout}>
<InputField
label="Default Workspace Timeout"
hint={
<span>
Use minutes or hours, like <span className="font-semibold">30m</span> or{" "}
<span className="font-semibold">2h</span>
</span>
}
>
<div className="flex space-x-2">
<div className="flex-grow">
<TextInput
value={workspaceTimeout}
placeholder="e.g. 30m"
onChange={setWorkspaceTimeout}
/>
</div>
<Button
htmlType="submit"
loading={timeoutUpdating}
disabled={workspaceTimeout === user?.additionalData?.workspaceTimeout ?? ""}
>
Save
</Button>
<form onSubmit={saveWorkspaceTimeout}>
<InputField
label="Default Workspace Timeout"
hint={
<span>
Use minutes or hours, like <span className="font-semibold">30m</span> or{" "}
<span className="font-semibold">2h</span>
</span>
}
>
<div className="flex space-x-2">
<div className="flex-grow">
<TextInput
value={workspaceTimeout}
placeholder="e.g. 30m"
onChange={setWorkspaceTimeout}
/>
</div>
</InputField>
</form>
)}
<Button
htmlType="submit"
loading={timeoutUpdating}
disabled={workspaceTimeout === user?.additionalData?.workspaceTimeout ?? ""}
>
Save
</Button>
</div>
</InputField>
</form>
</div>
</PageWithSettingsSubMenu>
</div>
Expand Down
3 changes: 1 addition & 2 deletions components/gitpod-protocol/src/billing-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export namespace BillingMode {
}

export function canSetCostCenter(billingMode: BillingMode): boolean {
// if has any Stripe Subscription, either directly or per team
return billingMode.mode === "usage-based";
}
}
Expand All @@ -36,6 +35,6 @@ interface None {
interface UsageBased {
mode: "usage-based";

/** True iff this is a team, and is based on a paid plan. Currently only set for teams! */
/** True if the org has a paid plan. */
paid?: boolean;
}
1 change: 0 additions & 1 deletion components/gitpod-protocol/src/gitpod-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
reportErrorBoundary(url: string, message: string): Promise<void>;

getSupportedWorkspaceClasses(): Promise<SupportedWorkspaceClass[]>;
maySetTimeout(): Promise<boolean>;
updateWorkspaceTimeoutSetting(setting: Partial<WorkspaceTimeoutSetting>): Promise<void>;

/**
Expand Down
1 change: 0 additions & 1 deletion components/server/src/auth/rate-limiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ const defaultFunctions: FunctionsConfig = {
getCostCenter: { group: "default", points: 1 },
setUsageLimit: { group: "default", points: 1 },
getSupportedWorkspaceClasses: { group: "default", points: 1 },
maySetTimeout: { group: "default", points: 1 },
updateWorkspaceTimeoutSetting: { group: "default", points: 1 },
getIDToken: { group: "default", points: 1 },
reportErrorBoundary: { group: "default", points: 1 },
Expand Down
10 changes: 0 additions & 10 deletions components/server/src/workspace/gitpod-server-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ import {
import { ListUsageRequest, ListUsageResponse } from "@gitpod/gitpod-protocol/lib/usage";
import { VerificationService } from "../auth/verification-service";
import { BillingMode } from "@gitpod/gitpod-protocol/lib/billing-mode";
import { EntitlementService } from "../billing/entitlement-service";
import { formatPhoneNumber } from "../user/phone-numbers";
import { IDEService } from "../ide-service";
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution";
Expand Down Expand Up @@ -240,7 +239,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
@inject(IDEService) private readonly ideService: IDEService,

@inject(VerificationService) private readonly verificationService: VerificationService,
@inject(EntitlementService) private readonly entitlementService: EntitlementService,

@inject(Authorizer) private readonly auth: Authorizer,

Expand Down Expand Up @@ -669,14 +667,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
return updatedUser;
}

public async maySetTimeout(ctx: TraceContext): Promise<boolean> {
const user = await this.checkUser("maySetTimeout");
await this.guardAccess({ kind: "user", subject: user }, "get");
await this.auth.checkPermissionOnUser(user.id, "read_info", user.id);

return await this.entitlementService.maySetTimeout(user.id);
}

public async updateWorkspaceTimeoutSetting(
ctx: TraceContext,
setting: Partial<WorkspaceTimeoutSetting>,
Expand Down

0 comments on commit 267805a

Please sign in to comment.