Skip to content

Commit

Permalink
fix(core): Remove subworkflow license check (n8n-io#10893)
Browse files Browse the repository at this point in the history
  • Loading branch information
despairblue authored Sep 23, 2024
1 parent 4effb66 commit 0290e38
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
SUBWORKFLOW_DENIAL_BASE_DESCRIPTION,
SubworkflowPolicyDenialError,
} from '@/errors/subworkflow-policy-denial.error';
import type { License } from '@/license';
import type { AccessService } from '@/services/access.service';
import { OwnershipService } from '@/services/ownership.service';
import type { UrlService } from '@/services/url.service';
Expand All @@ -20,7 +19,6 @@ import { SubworkflowPolicyChecker } from '../subworkflow-policy-checker.service'

describe('SubworkflowPolicyChecker', () => {
const ownershipService = mockInstance(OwnershipService);
const license = mock<License>();
const globalConfig = mock<GlobalConfig>({
workflows: { callerPolicyDefaultOption: 'workflowsFromSameOwner' },
});
Expand All @@ -29,17 +27,12 @@ describe('SubworkflowPolicyChecker', () => {

const checker = new SubworkflowPolicyChecker(
mock(),
license,
ownershipService,
globalConfig,
accessService,
urlService,
);

beforeEach(() => {
license.isSharingEnabled.mockReturnValue(true);
});

afterEach(() => {
jest.restoreAllMocks();
});
Expand Down Expand Up @@ -107,24 +100,6 @@ describe('SubworkflowPolicyChecker', () => {
});

describe('`any` caller policy', () => {
it('if no sharing, should be overriden to `workflows-from-same-owner`', async () => {
license.isSharingEnabled.mockReturnValueOnce(false);

const parentWorkflow = mock<WorkflowEntity>();
const subworkflowId = 'subworkflow-id';
const subworkflow = mock<Workflow>({ id: subworkflowId, settings: { callerPolicy: 'any' } }); // should be overridden

const parentWorkflowProject = mock<Project>({ id: uuid() });
const subworkflowProject = mock<Project>({ id: uuid(), type: 'team' });

ownershipService.getWorkflowProjectCached.mockResolvedValueOnce(parentWorkflowProject);
ownershipService.getWorkflowProjectCached.mockResolvedValueOnce(subworkflowProject);

const check = checker.check(subworkflow, parentWorkflow.id);

await expect(check).rejects.toThrowError(SubworkflowPolicyDenialError);
});

it('should not throw on a regular subworkflow call', async () => {
const parentWorkflow = mock<WorkflowEntity>({ id: uuid() });
const subworkflow = mock<Workflow>({ settings: { callerPolicy: 'any' } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Service } from 'typedi';

import type { Project } from '@/databases/entities/project';
import { SubworkflowPolicyDenialError } from '@/errors/subworkflow-policy-denial.error';
import { License } from '@/license';
import { Logger } from '@/logger';
import { AccessService } from '@/services/access.service';
import { OwnershipService } from '@/services/ownership.service';
Expand All @@ -18,7 +17,6 @@ type DenialPolicy = Exclude<Policy, 'any'>;
export class SubworkflowPolicyChecker {
constructor(
private readonly logger: Logger,
private readonly license: License,
private readonly ownershipService: OwnershipService,
private readonly globalConfig: GlobalConfig,
private readonly accessService: AccessService,
Expand Down Expand Up @@ -82,10 +80,8 @@ export class SubworkflowPolicyChecker {
* Find the subworkflow's caller policy.
*/
private findPolicy(subworkflow: Workflow): WorkflowSettings.CallerPolicy {
if (!this.license.isSharingEnabled()) return 'workflowsFromSameOwner';

return (
subworkflow.settings?.callerPolicy ?? this.globalConfig.workflows.callerPolicyDefaultOption
subworkflow.settings.callerPolicy ?? this.globalConfig.workflows.callerPolicyDefaultOption
);
}

Expand Down Expand Up @@ -139,7 +135,6 @@ export class SubworkflowPolicyChecker {
reason: this.denialReasons[policy],
parentWorkflowId,
subworkflowId,
isSharingEnabled: this.license.isSharingEnabled(),
});
}
}

0 comments on commit 0290e38

Please sign in to comment.