Skip to content

Commit

Permalink
Delete groups when we scrub or delete a workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph committed Jul 25, 2024
1 parent 6d2ab76 commit 8bc8c8c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion front/lib/resources/group_resource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ModelId, Result } from "@dust-tt/types";
import type { LightWorkspaceType, ModelId, Result } from "@dust-tt/types";
import { Err, Ok } from "@dust-tt/types";
import type {
Attributes,
Expand Down Expand Up @@ -69,6 +69,18 @@ export class GroupResource extends BaseResource<GroupModel> {
}
}

static async deleteAllForWorkspace(
workspace: LightWorkspaceType,
transaction?: Transaction
) {
return this.model.destroy({
where: {
workspaceId: workspace.id,
},
transaction,
});
}

static async fetchById(
auth: Authenticator,
sId: string
Expand Down
2 changes: 2 additions & 0 deletions front/poke/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { UserMetadata } from "@app/lib/models/user";
import { MembershipInvitation, Workspace } from "@app/lib/models/workspace";
import { ContentFragmentResource } from "@app/lib/resources/content_fragment_resource";
import { FileResource } from "@app/lib/resources/file_resource";
import { GroupResource } from "@app/lib/resources/group_resource";
import { KeyResource } from "@app/lib/resources/key_resource";
import { MembershipResource } from "@app/lib/resources/membership_resource";
import { RunResource } from "@app/lib/resources/run_resource";
Expand Down Expand Up @@ -565,6 +566,7 @@ export async function deleteWorkspaceActivity({
transaction: t,
});
await FileResource.deleteAllForWorkspace(workspace, t);
await GroupResource.deleteAllForWorkspace(workspace, t);
logger.info(`[Workspace delete] Deleting Worskpace ${workspace.sId}`);
await Workspace.destroy({
where: {
Expand Down
11 changes: 11 additions & 0 deletions front/temporal/scrub_workspace/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
FREE_NO_PLAN_CODE,
FREE_TEST_PLAN_CODE,
} from "@app/lib/plans/plan_codes";
import { GroupResource } from "@app/lib/resources/group_resource";
import { MembershipResource } from "@app/lib/resources/membership_resource";
import { UserResource } from "@app/lib/resources/user_resource";
import { CustomerioServerSideTracking } from "@app/lib/tracking/customerio/server";
Expand Down Expand Up @@ -84,6 +85,7 @@ export async function scrubWorkspaceData({
await deleteAllConversations(auth);
await archiveAssistants(auth);
await deleteDatasources(auth);
await deleteGroups(auth);
await cleanupCustomerio(auth);
}

Expand Down Expand Up @@ -154,6 +156,15 @@ async function deleteDatasources(auth: Authenticator) {
}
}

async function deleteGroups(auth: Authenticator) {
const workspace = auth.workspace();
if (!workspace) {
throw new Error("No workspace found");
}
const w = renderLightWorkspaceType({ workspace });
await GroupResource.deleteAllForWorkspace(w);
}

async function cleanupCustomerio(auth: Authenticator) {
const w = auth.workspace();

Expand Down

0 comments on commit 8bc8c8c

Please sign in to comment.