Skip to content

Commit

Permalink
[Poke] Plugin to downgrade a list of workspaces to NO_PLAN (#9271)
Browse files Browse the repository at this point in the history
* [Poke] Plugin to downgrade a list of workspaces to NO_PLAN

Description
---
Fraudulent workspaces are often found by batches. Manually swiching
each of them to NO_PLAN can be a pain.

This plugin allows deleting a list of workspaces

Risk
---
User error to downgrade wrong workspaces. Mitigated by warning message

Deploy
---
front

* add warning

* cleanc

* change message

* remove empty strings if any
  • Loading branch information
philipperolet authored Dec 11, 2024
1 parent 45527dc commit 4030eb6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
6 changes: 6 additions & 0 deletions front/components/poke/plugins/RunPluginDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ export function RunPluginDialog({
manifest={manifest}
onSubmit={onSubmit}
/>
{manifest.warning && (
<PokeAlert variant="destructive">
<PokeAlertTitle>Warning</PokeAlertTitle>
<PokeAlertDescription>{manifest.warning}</PokeAlertDescription>
</PokeAlert>
)}
</>
)}
</PokeDialogContent>
Expand Down
68 changes: 68 additions & 0 deletions front/lib/api/poke/plugins/global/batch_downgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Err, Ok } from "@dust-tt/types";
import { Op } from "sequelize";

import { createPlugin } from "@app/lib/api/poke/types";
import { Workspace } from "@app/lib/models/workspace";
import { internalSubscribeWorkspaceToFreeNoPlan } from "@app/lib/plans/subscription";
import { launchScheduleWorkspaceScrubWorkflow } from "@app/temporal/scrub_workspace/client";

export const batchDowngradePlugin = createPlugin(
{
id: "batch-downgrade",
name: "Batch Downgrade Workspaces",
warning:
"Downgrading workspaces will block access, make sure all workspaces from your list should really be downgraded.",
description: "NO_PLAN for fraudsters",
resourceTypes: ["global"],
args: {
sIds: {
type: "string",
label: "Workspace sIds",
description:
"Comma-separated list of sIds of the workspaces to downgrade",
},
},
},
async (_1, _2, args) => {
const { sIds } = args;

const sIdsArray = sIds
.split(",")
.map((sId) => sId.trim())
.filter((sId) => sId.length > 0);

const workspaces = await Workspace.findAll({
where: {
sId: {
[Op.in]: sIdsArray,
},
},
});

const missingWorkspaces = sIdsArray.filter(
(sId) => !workspaces.some((w) => w.sId === sId)
);

if (missingWorkspaces.length > 0) {
return new Err(
new Error(`Workspaces not found: ${missingWorkspaces.join(", ")}`)
);
}

for (const workspace of workspaces) {
await internalSubscribeWorkspaceToFreeNoPlan({
workspaceId: workspace.sId,
});

// On downgrade, start a worklflow to pause all connectors + scrub the data after a specified retention period.
await launchScheduleWorkspaceScrubWorkflow({
workspaceId: workspace.sId,
});
}

return new Ok({
display: "text",
value: `Workspaces downgraded.`,
});
}
);
1 change: 1 addition & 0 deletions front/lib/api/poke/plugins/global/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./batch_downgrade";
export * from "./create_workspace";
1 change: 1 addition & 0 deletions types/src/front/lib/poke/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface PluginManifest<T extends PluginArgs> {
id: string;
name: string;
resourceTypes: string[];
warning?: string;
}

export interface PluginWorkspaceResource {
Expand Down

0 comments on commit 4030eb6

Please sign in to comment.