Skip to content

Commit

Permalink
Add Poke plugin to disable SSO enforcement (#9129)
Browse files Browse the repository at this point in the history
  • Loading branch information
flvndvd authored Dec 5, 2024
1 parent aab1514 commit 20894c4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
44 changes: 44 additions & 0 deletions front/lib/api/poke/plugins/workspaces/disable_sso_enforcement.ts
Original file line number Diff line number Diff line change
@@ -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.",
});
}
);
1 change: 1 addition & 0 deletions front/lib/api/poke/plugins/workspaces/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
20 changes: 20 additions & 0 deletions front/lib/api/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,23 @@ export async function changeWorkspaceName(

return new Ok(undefined);
}

export async function disableSSOEnforcement(
owner: LightWorkspaceType
): Promise<Result<void, Error>> {
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);
}

0 comments on commit 20894c4

Please sign in to comment.