Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always regenerate id when bot creation #2716

Merged
merged 4 commits into from
Apr 21, 2020
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
1 change: 1 addition & 0 deletions Composer/packages/server/src/controllers/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async function createProject(req: Request, res: Response) {
log('Attempting to create project at %s', path);

try {
await BotProjectService.cleanProject(locationRef);
const newProjRef = await AssectService.manager.copyProjectTemplateTo(templateId, locationRef, user);
const id = await BotProjectService.openProject(newProjRef, user);
const currentProject = await BotProjectService.getProjectById(id, user);
Expand Down
10 changes: 10 additions & 0 deletions Composer/packages/server/src/services/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ export class BotProjectService {
return projectId.toString();
};

// clean project registry based on path to avoid reuseing the same id
public static cleanProject = async (location: LocationRef): Promise<void> => {
for (const key in BotProjectService.projectLocationMap) {
if (BotProjectService.projectLocationMap[key] === location.path) {
delete BotProjectService.projectLocationMap[key];
}
}
a-b-r-o-w-n marked this conversation as resolved.
Show resolved Hide resolved
Store.set('projectLocationMap', BotProjectService.projectLocationMap);
};

public static generateProjectId = async (path: string): Promise<string> => {
const projectId = (Math.random() * 100000).toString();
BotProjectService.projectLocationMap[projectId] = path;
Expand Down