fix: show a notice when workspace sharing is disabled globally in organization settings (#22580)

This commit is contained in:
Kayla はな
2026-03-04 11:14:52 -07:00
committed by GitHub
parent fda181bb26
commit e35717bc19
12 changed files with 142 additions and 52 deletions
+1 -1
View File
@@ -828,7 +828,7 @@ class ApiMethods {
*/
patchWorkspaceSharingSettings = async (
organization: string,
data: TypesGen.WorkspaceSharingSettings,
data: TypesGen.UpdateWorkspaceSharingSettingsRequest,
): Promise<TypesGen.WorkspaceSharingSettings> => {
const response = await this.axios.patch<TypesGen.WorkspaceSharingSettings>(
`/api/v2/organizations/${organization}/settings/workspace-sharing`,
+16 -1
View File
@@ -6523,6 +6523,15 @@ export interface UpdateWorkspaceRequest {
readonly name?: string;
}
// From codersdk/workspacesharing.go
/**
* UpdateWorkspaceSharingSettingsRequest represents workspace sharing settings
* that can be updated for an organization.
*/
export interface UpdateWorkspaceSharingSettingsRequest {
readonly sharing_disabled: boolean;
}
// From codersdk/workspaces.go
/**
* UpdateWorkspaceTTLRequest is a request to update a workspace's TTL.
@@ -7556,9 +7565,15 @@ export const WorkspaceRoles: WorkspaceRole[] = ["admin", "", "use"];
// From codersdk/workspacesharing.go
/**
* WorkspaceSharingSettings represents workspace sharing settings for an organization.
* WorkspaceSharingSettings represents workspace sharing settings affecting an
* organization.
*/
export interface WorkspaceSharingSettings {
/**
* SharingGloballyDisabled is true if sharing has been disabled for this
* organization because of a deployment-wide setting.
*/
readonly sharing_globally_disabled: boolean;
readonly sharing_disabled: boolean;
}
@@ -29,7 +29,7 @@ const OrganizationSettingsPage: FC = () => {
const sharingSettingsQuery = useQuery({
...workspaceSharingSettings(organization?.id ?? ""),
enabled: !!organization,
enabled: Boolean(organization),
});
const patchSharingSettingsMutation = useMutation(
@@ -112,6 +112,9 @@ const OrganizationSettingsPage: FC = () => {
);
}
}}
workspaceSharingGloballyDisabled={
sharingSettingsQuery.data?.sharing_globally_disabled
}
workspaceSharingEnabled={
!(sharingSettingsQuery.data?.sharing_disabled ?? false)
}
@@ -4,6 +4,7 @@ import type {
Organization,
UpdateOrganizationRequest,
} from "api/typesGenerated";
import { Alert, AlertTitle } from "components/Alert/Alert";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { Button } from "components/Button/Button";
import { Checkbox } from "components/Checkbox/Checkbox";
@@ -50,9 +51,10 @@ interface OrganizationSettingsPageViewProps {
error: unknown;
onSubmit: (values: UpdateOrganizationRequest) => Promise<void>;
onDeleteOrganization: () => void;
workspaceSharingEnabled?: boolean;
onToggleWorkspaceSharing?: (enabled: boolean) => void;
isTogglingWorkspaceSharing?: boolean;
workspaceSharingGloballyDisabled?: boolean;
workspaceSharingEnabled: boolean;
onToggleWorkspaceSharing: (enabled: boolean) => void;
isTogglingWorkspaceSharing: boolean;
}
export const OrganizationSettingsPageView: FC<
@@ -62,7 +64,8 @@ export const OrganizationSettingsPageView: FC<
error,
onSubmit,
onDeleteOrganization,
workspaceSharingEnabled = true,
workspaceSharingGloballyDisabled,
workspaceSharingEnabled,
onToggleWorkspaceSharing,
isTogglingWorkspaceSharing,
}) => {
@@ -156,29 +159,44 @@ export const OrganizationSettingsPageView: FC<
}
description="Control whether workspace owners can share their workspaces."
>
<div className="flex items-start gap-3">
<Checkbox
id="workspace-sharing"
checked={workspaceSharingEnabled}
disabled={isTogglingWorkspaceSharing}
onCheckedChange={(checked) => {
if (checked) {
onToggleWorkspaceSharing(true);
} else {
setIsDisableSharingDialogOpen(true);
<div className="flex flex-col gap-2">
{workspaceSharingGloballyDisabled && (
<Alert severity="warning" className="mb-4">
<AlertTitle>Disabled by deployment settings</AlertTitle>
Workspace sharing has been disallowed by an administrator.
Sharing must be allowed by an administrator before sharing can
be used in this organization.
</Alert>
)}
<div className="flex items-start gap-3">
<Checkbox
id="workspace-sharing"
checked={
!workspaceSharingGloballyDisabled && workspaceSharingEnabled
}
}}
/>
<div className="flex flex-col">
<label
htmlFor="workspace-sharing"
className="text-sm cursor-pointer"
>
Allow workspace sharing
</label>
<div className="text-sm text-content-secondary">
When enabled, workspace owners can share their workspaces with
other users in this organization.
disabled={
workspaceSharingGloballyDisabled ||
isTogglingWorkspaceSharing
}
onCheckedChange={(checked) => {
if (checked) {
onToggleWorkspaceSharing(true);
} else {
setIsDisableSharingDialogOpen(true);
}
}}
/>
<div className="flex flex-col">
<label
htmlFor="workspace-sharing"
className="text-sm cursor-pointer"
>
Allow workspace sharing
</label>
<div className="text-sm text-content-secondary">
When enabled, workspace owners can share their workspaces
with other users in this organization.
</div>
</div>
</div>
</div>