-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[server, dashboard, db] Org-wide "maintenance mode" #20813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8ba9feb
[dashboard] Initial infra rollout page, incl. list running workspaces
geropl ccdca90
[server, db, dashboard] Allow org-owner to stop workspace on all work…
geropl d73be97
[public-api, db, server, dashboard] Introduce MaintenanceNofitication…
geropl f2c77b6
review comments: use mutation instead of callback for state mutation
geropl 4eaaa9d
Fix workspace start prevention
geropl 51fb829
Review comments around banners and rendering
geropl 36a7cc1
[dashboard] Only show Admin entry for dedicated
geropl 81b081d
[server] Fix permissions for setMaintenanceMode to "maintenance"
geropl d7770f6
[dashboard] Adjusted copy incl. default notification message
geropl d156926
Review coments: re-use and fix styles, and naming
geropl 93d01d1
Minor copy improvements
geropl 2192fa6
[server] Fix bogus permission check in stopWorkspace
geropl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Copyright (c) 2025 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useQuery, useQueryClient } from "@tanstack/react-query"; | ||
import { useCurrentOrg } from "./organizations/orgs-query"; | ||
import { organizationClient } from "../service/public-api"; | ||
|
||
export const maintenanceModeQueryKey = (orgId: string) => ["maintenance-mode", orgId]; | ||
|
||
export const useMaintenanceMode = () => { | ||
const { data: org } = useCurrentOrg(); | ||
const queryClient = useQueryClient(); | ||
|
||
const { data: isMaintenanceMode = false, isLoading } = useQuery( | ||
maintenanceModeQueryKey(org?.id || ""), | ||
async () => { | ||
if (!org?.id) return false; | ||
|
||
try { | ||
const response = await organizationClient.getOrganizationMaintenanceMode({ | ||
organizationId: org.id, | ||
}); | ||
return response.enabled; | ||
} catch (error) { | ||
console.error("Failed to fetch maintenance mode status", error); | ||
return false; | ||
} | ||
}, | ||
{ | ||
enabled: !!org?.id, | ||
staleTime: 30 * 1000, // 30 seconds | ||
refetchInterval: 60 * 1000, // 1 minute | ||
}, | ||
); | ||
|
||
const setMaintenanceMode = async (enabled: boolean) => { | ||
if (!org?.id) return false; | ||
|
||
try { | ||
const response = await organizationClient.setOrganizationMaintenanceMode({ | ||
organizationId: org.id, | ||
enabled, | ||
}); | ||
const result = response.enabled; | ||
|
||
// Update the cache | ||
queryClient.setQueryData(maintenanceModeQueryKey(org.id), result); | ||
|
||
return result; | ||
} catch (error) { | ||
console.error("Failed to set maintenance mode", error); | ||
return false; | ||
} | ||
}; | ||
|
||
return { | ||
isMaintenanceMode, | ||
isLoading, | ||
setMaintenanceMode, | ||
}; | ||
}; |
77 changes: 77 additions & 0 deletions
77
components/dashboard/src/data/maintenance-notification-query.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Copyright (c) 2025 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useQuery, useQueryClient } from "@tanstack/react-query"; | ||
import { useCurrentOrg } from "./organizations/orgs-query"; | ||
import { organizationClient } from "../service/public-api"; | ||
import { MaintenanceNotification } from "@gitpod/gitpod-protocol"; | ||
|
||
export const maintenanceNotificationQueryKey = (orgId: string) => ["maintenance-notification", orgId]; | ||
|
||
export const useMaintenanceNotification = () => { | ||
const { data: org } = useCurrentOrg(); | ||
const queryClient = useQueryClient(); | ||
|
||
const { data, isLoading } = useQuery<MaintenanceNotification>( | ||
maintenanceNotificationQueryKey(org?.id || ""), | ||
async () => { | ||
if (!org?.id) return { enabled: false }; | ||
|
||
try { | ||
const response = await organizationClient.getMaintenanceNotification({ | ||
organizationId: org.id, | ||
}); | ||
return { | ||
enabled: response.isEnabled, | ||
message: response.message, | ||
}; | ||
} catch (error) { | ||
console.error("Failed to fetch maintenance notification settings", error); | ||
return { enabled: false }; | ||
} | ||
}, | ||
{ | ||
enabled: !!org?.id, | ||
staleTime: 30 * 1000, // 30 seconds | ||
refetchInterval: 60 * 1000, // 1 minute | ||
}, | ||
); | ||
|
||
const setMaintenanceNotification = async ( | ||
isEnabled: boolean, | ||
customMessage?: string, | ||
): Promise<MaintenanceNotification> => { | ||
if (!org?.id) return { enabled: false, message: "" }; | ||
|
||
try { | ||
const response = await organizationClient.setMaintenanceNotification({ | ||
organizationId: org.id, | ||
isEnabled, | ||
customMessage, | ||
}); | ||
|
||
const result: MaintenanceNotification = { | ||
enabled: response.isEnabled, | ||
message: response.message, | ||
}; | ||
|
||
// Update the cache | ||
queryClient.setQueryData(maintenanceNotificationQueryKey(org.id), result); | ||
|
||
return result; | ||
} catch (error) { | ||
console.error("Failed to set maintenance notification", error); | ||
return { enabled: false }; | ||
} | ||
}; | ||
|
||
return { | ||
isNotificationEnabled: data?.enabled || false, | ||
notificationMessage: data?.message, | ||
isLoading, | ||
setMaintenanceNotification, | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright (c) 2025 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import React, { useEffect } from "react"; | ||
import { useHistory } from "react-router-dom"; | ||
import { useUserLoader } from "../hooks/use-user-loader"; | ||
import { useCurrentOrg } from "../data/organizations/orgs-query"; | ||
import { useIsOwner } from "../data/organizations/members-query"; | ||
import Header from "../components/Header"; | ||
import { SpinnerLoader } from "../components/Loader"; | ||
import { RunningWorkspacesCard } from "./RunningWorkspacesCard"; | ||
import { MaintenanceModeCard } from "./MaintenanceModeCard"; | ||
import { MaintenanceNotificationCard } from "./MaintenanceNotificationCard"; | ||
|
||
const AdminPage: React.FC = () => { | ||
const history = useHistory(); | ||
const { loading: userLoading } = useUserLoader(); | ||
const { data: currentOrg, isLoading: orgLoading } = useCurrentOrg(); | ||
const isOwner = useIsOwner(); | ||
|
||
useEffect(() => { | ||
if (userLoading || orgLoading) { | ||
return; | ||
} | ||
if (!isOwner) { | ||
history.replace("/workspaces"); | ||
} | ||
}, [isOwner, userLoading, orgLoading, history, currentOrg?.id]); | ||
|
||
return ( | ||
<div className="flex flex-col w-full"> | ||
<Header | ||
title="Organization Administration" | ||
subtitle="Manage your organization's infrastructure and settings." | ||
/> | ||
<div className="app-container py-6"> | ||
<h2 className="text-2xl font-semibold text-gray-800 dark:text-gray-100 mb-4">Infrastructure Rollout</h2> | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
{userLoading || | ||
orgLoading || | ||
(!isOwner && ( | ||
<div className="flex items-center justify-center w-full p-8"> | ||
<SpinnerLoader /> | ||
</div> | ||
))} | ||
|
||
{!orgLoading && !currentOrg && ( | ||
<div className="text-red-500 p-4 bg-red-100 dark:bg-red-900 border border-red-500 rounded-md"> | ||
Could not load organization details. Please ensure you are part of an organization. | ||
</div> | ||
)} | ||
|
||
{currentOrg && ( | ||
<> | ||
<MaintenanceNotificationCard /> | ||
<MaintenanceModeCard /> | ||
<RunningWorkspacesCard /> | ||
</> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AdminPage; |
26 changes: 26 additions & 0 deletions
26
components/dashboard/src/org-admin/MaintenanceModeBanner.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (c) 2025 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { FC } from "react"; | ||
import Alert from "../components/Alert"; | ||
import { useMaintenanceMode } from "../data/maintenance-mode-query"; | ||
|
||
export const MaintenanceModeBanner: FC = () => { | ||
const { isMaintenanceMode } = useMaintenanceMode(); | ||
|
||
if (!isMaintenanceMode) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Alert type="warning" className="mb-2"> | ||
<div className="flex items-center"> | ||
<span className="font-semibold">System is in maintenance mode.</span> | ||
<span className="ml-2">Starting new workspaces is currently disabled.</span> | ||
</div> | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Alert> | ||
); | ||
}; |
50 changes: 50 additions & 0 deletions
50
components/dashboard/src/org-admin/MaintenanceModeCard.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) 2025 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { FC } from "react"; | ||
import { useToast } from "../components/toasts/Toasts"; | ||
import { Button } from "@podkit/buttons/Button"; | ||
import { useMaintenanceMode } from "../data/maintenance-mode-query"; | ||
|
||
export const MaintenanceModeCard: FC = () => { | ||
const { isMaintenanceMode, isLoading, setMaintenanceMode } = useMaintenanceMode(); | ||
const toast = useToast(); | ||
|
||
const toggleMaintenanceMode = async () => { | ||
try { | ||
const newState = !isMaintenanceMode; | ||
const result = await setMaintenanceMode(newState); | ||
|
||
toast.toast({ | ||
message: `Maintenance mode ${result ? "enabled" : "disabled"}`, | ||
type: "success", | ||
}); | ||
} catch (error) { | ||
console.error("Failed to toggle maintenance mode", error); | ||
toast.toast({ message: "Failed to toggle maintenance mode", type: "error" }); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="bg-white dark:bg-gray-800 shadow-md rounded-lg p-4 mb-4"> | ||
<div className="flex justify-between items-center"> | ||
<div> | ||
<h3 className="text-lg font-semibold text-gray-700 dark:text-gray-200">Maintenance Mode</h3> | ||
<p className="text-gray-500 dark:text-gray-400"> | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
When enabled, users cannot start new workspaces and a notification is displayed. | ||
</p> | ||
</div> | ||
<Button | ||
variant={isMaintenanceMode ? "secondary" : "default"} | ||
onClick={toggleMaintenanceMode} | ||
disabled={isLoading} | ||
> | ||
{isLoading ? "Loading..." : isMaintenanceMode ? "Disable" : "Enable"} | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.