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(core): Ensure executions list is properly filtered for all users #4765

Merged
merged 9 commits into from
Nov 30, 2022
2 changes: 1 addition & 1 deletion packages/cli/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ import type {
import { userManagementRouter } from '@/UserManagement';
import { resolveJwt } from '@/UserManagement/auth/jwt';

import { executionsController } from '@/api/executions.api';
import { executionsController } from '@/executions/executions.controller';
import { nodeTypesController } from '@/api/nodeTypes.api';
import { tagsController } from '@/api/tags.api';
import { loadPublicApiVersions } from '@/PublicApi';
Expand Down
70 changes: 70 additions & 0 deletions packages/cli/src/executions/executions.controller.ee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import express from 'express';
import config from '@/config';
import {
IExecutionFlattedResponse,
IExecutionResponse,
IExecutionsListResponse,
} from '@/Interfaces';
import type { ExecutionRequest } from '@/requests';
import * as ResponseHelper from '@/ResponseHelper';
import { isSharingEnabled } from '@/UserManagement/UserManagementHelper';
import { EEExecutionsService } from './executions.service.ee';

// eslint-disable-next-line @typescript-eslint/naming-convention
export const EEExecutionsController = express.Router();

EEExecutionsController.use((req, res, next) => {
if (!isSharingEnabled() || !config.getEnv('enterprise.workflowSharingEnabled')) {
// skip ee router and use free one
next('router');
return;
}
// use ee router
next();
});

/**
* GET /executions
*/
EEExecutionsController.get(
'/',
ResponseHelper.send(async (req: ExecutionRequest.GetAll): Promise<IExecutionsListResponse> => {
return EEExecutionsService.getExecutionsList(req);
}),
);

/**
* GET /executions/:id
*/
EEExecutionsController.get(
'/:id',
ResponseHelper.send(
async (
req: ExecutionRequest.Get,
): Promise<IExecutionResponse | IExecutionFlattedResponse | undefined> => {
return EEExecutionsService.getExecution(req);
},
),
);

/**
* POST /executions/:id/retry
*/
EEExecutionsController.post(
'/:id/retry',
ResponseHelper.send(async (req: ExecutionRequest.Retry): Promise<boolean> => {
return EEExecutionsService.retryExecution(req);
}),
);

/**
* POST /executions/delete
* INFORMATION: We use POST instead of DELETE to not run into any issues with the query data
* getting too long
*/
EEExecutionsController.post(
'/delete',
ResponseHelper.send(async (req: ExecutionRequest.Delete): Promise<void> => {
await EEExecutionsService.deleteExecutions(req);
}),
);
74 changes: 74 additions & 0 deletions packages/cli/src/executions/executions.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import express from 'express';
import { LoggerProxy } from 'n8n-workflow';
import {
IExecutionFlattedResponse,
IExecutionResponse,
IExecutionsListResponse,
} from '@/Interfaces';
import * as ResponseHelper from '@/ResponseHelper';
import { getLogger } from '@/Logger';
import type { ExecutionRequest } from '@/requests';
import { EEExecutionsController } from './executions.controller.ee';
import { ExecutionsService } from './executions.service';

export const executionsController = express.Router();

/**
* Initialise Logger if needed
*/
executionsController.use((req, res, next) => {
try {
LoggerProxy.getInstance();
} catch (error) {
LoggerProxy.init(getLogger());
}
next();
});

executionsController.use('/', EEExecutionsController);

/**
* GET /executions
*/
executionsController.get(
'/',
ResponseHelper.send(async (req: ExecutionRequest.GetAll): Promise<IExecutionsListResponse> => {
return ExecutionsService.getExecutionsList(req);
}),
);

/**
* GET /executions/:id
*/
executionsController.get(
'/:id',
ResponseHelper.send(
async (
req: ExecutionRequest.Get,
): Promise<IExecutionResponse | IExecutionFlattedResponse | undefined> => {
return ExecutionsService.getExecution(req);
},
),
);

/**
* POST /executions/:id/retry
*/
executionsController.post(
'/:id/retry',
ResponseHelper.send(async (req: ExecutionRequest.Retry): Promise<boolean> => {
return ExecutionsService.retryExecution(req);
}),
);

/**
* POST /executions/delete
* INFORMATION: We use POST instead of DELETE to not run into any issues with the query data
* getting too long
*/
executionsController.post(
'/delete',
ResponseHelper.send(async (req: ExecutionRequest.Delete): Promise<void> => {
await ExecutionsService.deleteExecutions(req);
}),
);
13 changes: 13 additions & 0 deletions packages/cli/src/executions/executions.service.ee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { User } from '@/databases/entities/User';
import { getSharedWorkflowIds } from '@/WorkflowHelpers';
import { ExecutionsService } from './executions.service';

export class EEExecutionsService extends ExecutionsService {
/**
* Function to get the workflow Ids for a User regardless of role
*/
static async getWorkflowIdsForUser(user: User): Promise<number[]> {
// Get all workflows
return getSharedWorkflowIds(user);
}
}
Loading