diff --git a/front/lib/api/poke/plugins/workspaces/disable_sso_enforcement.ts b/front/lib/api/poke/plugins/workspaces/disable_sso_enforcement.ts new file mode 100644 index 000000000000..c4ecc6121d61 --- /dev/null +++ b/front/lib/api/poke/plugins/workspaces/disable_sso_enforcement.ts @@ -0,0 +1,44 @@ +import { Err, Ok } from "@dust-tt/types"; + +import { createPlugin } from "@app/lib/api/poke/types"; +import { disableSSOEnforcement } from "@app/lib/api/workspace"; + +export const disableSSOPlugin = createPlugin( + { + id: "disable-sso", + name: "Disable SSO Enforcement", + description: "Disable SSO enforcement on a workspace", + resourceTypes: ["workspaces"], + args: { + force: { + type: "boolean", + label: "Force", + description: "Are you sure?", + }, + }, + }, + async (auth, _, args) => { + const workspace = auth.workspace(); + if (!workspace) { + return new Err(new Error("Cannot find workspace.")); + } + + const { force } = args; + if (!force) { + return new Err( + new Error("You must confirm that you want to disable SSO enforcement.") + ); + } + + const res = await disableSSOEnforcement(workspace); + + if (res.isErr()) { + return new Err(res.error); + } + + return new Ok({ + display: "text", + value: "SSO enforcement disabled.", + }); + } +); diff --git a/front/lib/api/poke/plugins/workspaces/index.ts b/front/lib/api/poke/plugins/workspaces/index.ts index 8e788ac76a95..26ff0ced6845 100644 --- a/front/lib/api/poke/plugins/workspaces/index.ts +++ b/front/lib/api/poke/plugins/workspaces/index.ts @@ -1,4 +1,5 @@ export * from "./create_space"; +export * from "./disable_sso_enforcement"; export * from "./extend_trial"; export * from "./invite_user"; export * from "./rename_workspace"; diff --git a/front/lib/api/workspace.ts b/front/lib/api/workspace.ts index 48ab3e393a80..ac53a5eff599 100644 --- a/front/lib/api/workspace.ts +++ b/front/lib/api/workspace.ts @@ -360,3 +360,23 @@ export async function changeWorkspaceName( return new Ok(undefined); } + +export async function disableSSOEnforcement( + owner: LightWorkspaceType +): Promise> { + const [affectedCount] = await Workspace.update( + { ssoEnforced: false }, + { + where: { + id: owner.id, + ssoEnforced: true, + }, + } + ); + + if (affectedCount === 0) { + return new Err(new Error("SSO enforcement is already disabled.")); + } + + return new Ok(undefined); +}