Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
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
19 changes: 19 additions & 0 deletions Composer/packages/server/src/controllers/formDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,27 @@ const generate = async (req: Request, res: Response) => {
}
};

const deleteDialog = async (req: Request, res: Response) => {
const projectId = req.params.projectId;
const dialogId = req.params.dialogId;

const user = await ExtensionContext.getUserFromRequest(req);

const currentProject = await BotProjectService.getProjectById(projectId, user);
if (currentProject !== undefined) {
await currentProject.deleteFormDialog(dialogId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want a try catch here with 500 response?

const updatedProject = await BotProjectService.getProjectById(projectId, user);
res.status(200).json({ id: projectId, ...updatedProject.getProject() });
} else {
res.status(404).json({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the error for when the caller doesn't provide project id should be different

message: `Could not delete form dialog. Project ${projectId} not found.`,
});
}
};

export const FormDialogController = {
getTemplateSchemas,
generate,
expandJsonSchemaProperty,
deleteDialog,
};
11 changes: 11 additions & 0 deletions Composer/packages/server/src/models/bot/botProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,17 @@ export class BotProject implements IBotProject {
);
}

public async deleteFormDialog(dialogId: string) {
const defaultLocale = this.settings?.defaultLanguage || defaultLanguage;
const dialogPath = defaultFilePath(this.name, defaultLocale, `${dialogId}${FileExtensions.Dialog}`);
const dirToDelete = Path.dirname(Path.resolve(this.dir, dialogPath));

// I check that the path is longer 3 to avoid deleting a drive and all its contents.
if (dirToDelete.length > 3 && this.fileStorage.exists(dirToDelete)) {
this.fileStorage.rmrfDir(dirToDelete);
}
}

private async removeLocalRuntimeData(projectId) {
const method = 'localpublish';
if (ExtensionContext.extensions.publish[method]?.methods?.stopBot) {
Expand Down
1 change: 1 addition & 0 deletions Composer/packages/server/src/router/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ router.get('/projects/:projectId/export', ProjectController.exportProject);
router.post('/formDialogs/expandJsonSchemaProperty', FormDialogController.expandJsonSchemaProperty);
router.get('/formDialogs/templateSchemas', FormDialogController.getTemplateSchemas);
router.post('/formDialogs/:projectId/generate', FormDialogController.generate);
router.delete('/formDialogs/:projectId/:dialogId', FormDialogController.deleteDialog);

// update the boilerplate content
router.get('/projects/:projectId/boilerplateVersion', ProjectController.checkBoilerplateVersion);
Expand Down