fix(core): Permission check for subworkflow properly checking for workflow settings (#7576)
The `sharing` related code is legacy that was not removed. Subworkflow execution should check workflow settings alone, and this is now reflected in the code. Github issue / Community forum post (link here to close automatically): https://community.n8n.io/t/bug-when-using-the-execute-workflow-node-when-workflow-is-shared/32207 --------- Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
@@ -1,17 +1,11 @@
|
||||
import type { INode, Workflow } from 'n8n-workflow';
|
||||
import {
|
||||
NodeOperationError,
|
||||
SubworkflowOperationError,
|
||||
WorkflowOperationError,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeOperationError, SubworkflowOperationError } from 'n8n-workflow';
|
||||
import type { FindOptionsWhere } from 'typeorm';
|
||||
import { In } from 'typeorm';
|
||||
import * as Db from '@/Db';
|
||||
import config from '@/config';
|
||||
import type { SharedCredentials } from '@db/entities/SharedCredentials';
|
||||
import { isSharingEnabled } from './UserManagementHelper';
|
||||
import { WorkflowsService } from '@/workflows/workflows.services';
|
||||
import { UserService } from '@/services/user.service';
|
||||
import { OwnershipService } from '@/services/ownership.service';
|
||||
import Container from 'typedi';
|
||||
import { RoleService } from '@/services/role.service';
|
||||
@@ -135,14 +129,7 @@ export class PermissionChecker {
|
||||
}
|
||||
|
||||
if (policy === 'workflowsFromSameOwner') {
|
||||
const user = await Container.get(UserService).findOne({ where: { id: userId } });
|
||||
if (!user) {
|
||||
throw new WorkflowOperationError(
|
||||
'Fatal error: user not found. Please contact the system administrator.',
|
||||
);
|
||||
}
|
||||
const sharing = await WorkflowsService.getSharing(user, subworkflow.id, ['role', 'user']);
|
||||
if (!sharing || sharing.role.name !== 'owner') {
|
||||
if (subworkflowOwner?.id !== userId) {
|
||||
throw errorToThrow;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user