feat(core): Update POST /workflows to link folder (no-changelog) (#13449)

This commit is contained in:
Ricardo Espinoza
2025-02-25 15:29:35 -05:00
committed by GitHub
parent 2f395fe89a
commit 461e39a74e
6 changed files with 148 additions and 12 deletions

View File

@@ -46,6 +46,7 @@ import { License } from '@/license';
import { listQueryMiddleware } from '@/middlewares';
import { AuthenticatedRequest } from '@/requests';
import * as ResponseHelper from '@/response-helper';
import { FolderService } from '@/services/folder.service';
import { NamingService } from '@/services/naming.service';
import { ProjectService } from '@/services/project.service.ee';
import { TagService } from '@/services/tag.service';
@@ -82,6 +83,7 @@ export class WorkflowsController {
private readonly projectRelationRepository: ProjectRelationRepository,
private readonly eventService: EventService,
private readonly globalConfig: GlobalConfig,
private readonly folderService: FolderService,
) {}
@Post('/')
@@ -133,7 +135,7 @@ export class WorkflowsController {
const savedWorkflow = await Db.transaction(async (transactionManager) => {
const workflow = await transactionManager.save<WorkflowEntity>(newWorkflow);
const { projectId } = req.body;
const { projectId, parentFolderId } = req.body;
project =
projectId === undefined
? await this.projectRepository.getPersonalProjectForUser(req.user.id, transactionManager)
@@ -155,6 +157,17 @@ export class WorkflowsController {
throw new ApplicationError('No personal project found');
}
if (parentFolderId) {
try {
const parentFolder = await this.folderService.getFolderInProject(
parentFolderId,
project.id,
transactionManager,
);
await transactionManager.update(WorkflowEntity, { id: workflow.id }, { parentFolder });
} catch {}
}
const newSharedWorkflow = this.sharedWorkflowRepository.create({
role: 'workflow:owner',
projectId: project.id,
@@ -167,7 +180,7 @@ export class WorkflowsController {
workflow.id,
req.user,
['workflow:read'],
{ em: transactionManager, includeTags: true },
{ em: transactionManager, includeTags: true, includeParentFolder: true },
);
});