feat: Return scopes on executions (no-changelog) (#10310)
This commit is contained in:
@@ -31,6 +31,7 @@ describe('ExecutionService', () => {
|
||||
mock(),
|
||||
concurrencyControl,
|
||||
mock(),
|
||||
mock(),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -74,6 +74,8 @@ describe('ExecutionsController', () => {
|
||||
},
|
||||
];
|
||||
|
||||
executionService.findRangeWithCount.mockResolvedValue(NO_EXECUTIONS);
|
||||
|
||||
describe('if either status or range provided', () => {
|
||||
test.each(QUERIES_WITH_EITHER_STATUS_OR_RANGE)(
|
||||
'should fetch executions per query',
|
||||
|
||||
@@ -40,6 +40,8 @@ import { QueuedExecutionRetryError } from '@/errors/queued-execution-retry.error
|
||||
import { ConcurrencyControlService } from '@/concurrency/concurrency-control.service';
|
||||
import { AbortedExecutionRetryError } from '@/errors/aborted-execution-retry.error';
|
||||
import { License } from '@/License';
|
||||
import type { User } from '@/databases/entities/User';
|
||||
import { WorkflowSharingService } from '@/workflows/workflowSharing.service';
|
||||
|
||||
export const schemaGetExecutionsQueryFilter = {
|
||||
$id: '/IGetExecutionsQueryFilter',
|
||||
@@ -92,6 +94,7 @@ export class ExecutionService {
|
||||
private readonly workflowRunner: WorkflowRunner,
|
||||
private readonly concurrencyControl: ConcurrencyControlService,
|
||||
private readonly license: License,
|
||||
private readonly workflowSharingService: WorkflowSharingService,
|
||||
) {}
|
||||
|
||||
async findOne(
|
||||
@@ -478,4 +481,16 @@ export class ExecutionService {
|
||||
|
||||
return await this.executionRepository.stopDuringRun(execution);
|
||||
}
|
||||
|
||||
async addScopes(user: User, summaries: ExecutionSummaries.ExecutionSummaryWithScopes[]) {
|
||||
const workflowIds = [...new Set(summaries.map((s) => s.workflowId))];
|
||||
|
||||
const scopes = Object.fromEntries(
|
||||
await this.workflowSharingService.getSharedWorkflowScopes(workflowIds, user),
|
||||
);
|
||||
|
||||
for (const s of summaries) {
|
||||
s.scopes = scopes[s.workflowId] ?? [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import type { ExecutionEntity } from '@/databases/entities/ExecutionEntity';
|
||||
import type { AuthenticatedRequest } from '@/requests';
|
||||
import type { ExecutionStatus, IDataObject, WorkflowExecuteMode } from 'n8n-workflow';
|
||||
import type { Scope } from '@n8n/permissions';
|
||||
import type {
|
||||
ExecutionStatus,
|
||||
ExecutionSummary,
|
||||
IDataObject,
|
||||
WorkflowExecuteMode,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export declare namespace ExecutionRequest {
|
||||
namespace QueryParams {
|
||||
@@ -83,6 +89,8 @@ export namespace ExecutionSummaries {
|
||||
stoppedAt?: 'DESC';
|
||||
};
|
||||
};
|
||||
|
||||
export type ExecutionSummaryWithScopes = ExecutionSummary & { scopes: Scope[] };
|
||||
}
|
||||
|
||||
export type QueueRecoverySettings = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ExecutionRequest } from './execution.types';
|
||||
import { ExecutionRequest, type ExecutionSummaries } from './execution.types';
|
||||
import { ExecutionService } from './execution.service';
|
||||
import { Get, Post, RestController } from '@/decorators';
|
||||
import { EnterpriseExecutionsService } from './execution.service.ee';
|
||||
@@ -53,10 +53,20 @@ export class ExecutionsController {
|
||||
const noRange = !query.range.lastId || !query.range.firstId;
|
||||
|
||||
if (noStatus && noRange) {
|
||||
return await this.executionService.findLatestCurrentAndCompleted(query);
|
||||
const executions = await this.executionService.findLatestCurrentAndCompleted(query);
|
||||
await this.executionService.addScopes(
|
||||
req.user,
|
||||
executions.results as ExecutionSummaries.ExecutionSummaryWithScopes[],
|
||||
);
|
||||
return executions;
|
||||
}
|
||||
|
||||
return await this.executionService.findRangeWithCount(query);
|
||||
const executions = await this.executionService.findRangeWithCount(query);
|
||||
await this.executionService.addScopes(
|
||||
req.user,
|
||||
executions.results as ExecutionSummaries.ExecutionSummaryWithScopes[],
|
||||
);
|
||||
return executions;
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
|
||||
Reference in New Issue
Block a user