Skip to content
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

Add Poke plugin to disable SSO enforcement #9129

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading