refactor(core): Post-release refactorings of Public API (#3495)

*  Post-release refactorings

* 🧪 Add `--forceExit`

* 🛠 typing refactor (#3486)

* 🐛 Fix middleware arguments

* 👕 Fix lint

*  Restore commented out block

Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
This commit is contained in:
Iván Ovejero
2022-06-14 18:32:19 +02:00
committed by GitHub
parent 2ebcf4bb91
commit b8e3bcc052
19 changed files with 307 additions and 343 deletions

View File

@@ -1,16 +1,15 @@
import express = require('express');
import express from 'express';
import { BinaryDataManager } from 'n8n-core';
import {
getExecutions,
getExecutionInWorkflows,
deleteExecution,
getExecutionsCount,
} from './executions.service';
import { ActiveExecutions } from '../../../..';
import { authorize, validCursor } from '../../shared/middlewares/global.middleware';
import { ExecutionRequest } from '../../../types';
import { getSharedWorkflowIds } from '../workflows/workflows.service';
import { encodeNextCursor } from '../../shared/services/pagination.service';
@@ -20,31 +19,24 @@ export = {
deleteExecution: [
authorize(['owner', 'member']),
async (req: ExecutionRequest.Delete, res: express.Response): Promise<express.Response> => {
const { id } = req.params;
const sharedWorkflowsIds = await getSharedWorkflowIds(req.user);
// user does not have workflows hence no executions
// or the execution he is trying to access belongs to a workflow he does not own
if (!sharedWorkflowsIds.length) {
return res.status(404).json({
message: 'Not Found',
});
return res.status(404).json({ message: 'Not Found' });
}
const { id } = req.params;
// look for the execution on the workflow the user owns
const execution = await getExecutionInWorkflows(id, sharedWorkflowsIds, false);
// execution was not found
if (!execution) {
return res.status(404).json({
message: 'Not Found',
});
return res.status(404).json({ message: 'Not Found' });
}
const binaryDataManager = BinaryDataManager.getInstance();
await binaryDataManager.deleteBinaryDataByExecutionId(execution.id.toString());
await BinaryDataManager.getInstance().deleteBinaryDataByExecutionId(execution.id.toString());
await deleteExecution(execution);
@@ -56,35 +48,28 @@ export = {
getExecution: [
authorize(['owner', 'member']),
async (req: ExecutionRequest.Get, res: express.Response): Promise<express.Response> => {
const { id } = req.params;
const { includeData = false } = req.query;
const sharedWorkflowsIds = await getSharedWorkflowIds(req.user);
// user does not have workflows hence no executions
// or the execution he is trying to access belongs to a workflow he does not own
if (!sharedWorkflowsIds.length) {
return res.status(404).json({
message: 'Not Found',
});
return res.status(404).json({ message: 'Not Found' });
}
const { id } = req.params;
const { includeData = false } = req.query;
// look for the execution on the workflow the user owns
const execution = await getExecutionInWorkflows(id, sharedWorkflowsIds, includeData);
// execution was not found
if (!execution) {
return res.status(404).json({
message: 'Not Found',
});
return res.status(404).json({ message: 'Not Found' });
}
const telemetryData = {
void InternalHooksManager.getInstance().onUserRetrievedExecution({
user_id: req.user.id,
public_api: true,
};
void InternalHooksManager.getInstance().onUserRetrievedExecution(telemetryData);
});
return res.json(execution);
},
@@ -106,10 +91,7 @@ export = {
// user does not have workflows hence no executions
// or the execution he is trying to access belongs to a workflow he does not own
if (!sharedWorkflowsIds.length) {
return res.status(200).json({
data: [],
nextCursor: null,
});
return res.status(200).json({ data: [], nextCursor: null });
}
// get running workflows so we exclude them from the result
@@ -134,12 +116,10 @@ export = {
const count = await getExecutionsCount(filters);
const telemetryData = {
void InternalHooksManager.getInstance().onUserRetrievedAllExecutions({
user_id: req.user.id,
public_api: true,
};
void InternalHooksManager.getInstance().onUserRetrievedAllExecutions(telemetryData);
});
return res.json({
data: executions,