-
Notifications
You must be signed in to change notification settings - Fork 122
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 (#9271)
* [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
1 parent
45527dc
commit 4030eb6
Showing
4 changed files
with
76 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
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,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.`, | ||
}); | ||
} | ||
); |
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 "./batch_downgrade"; | ||
export * from "./create_workspace"; |
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