-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
3500423
commit 6332852
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Err, Ok } from "@dust-tt/types"; | ||
|
||
import { createPlugin } from "@app/lib/api/poke/types"; | ||
import { Workspace } from "@app/lib/models/workspace"; | ||
import { Op } from "sequelize"; | ||
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", | ||
description: | ||
"Downgrade a list of workspaces to NO_PLAN, used to block access to fraudulent users", | ||
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()); | ||
|
||
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.`, | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./create_workspace"; | ||
export * from "./batch_downgrade"; |