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): Remove subworkflow license check #10893

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
});
}
}
Loading