refactor: Forbid access to workflows when enterprise features is unavailable (#4635) (no-changelog)

* refactor: Forbid access to workflows when enterprise features is unavailable
This commit is contained in:
Omar Ajoue
2022-11-18 13:07:39 +01:00
committed by GitHub
parent bb5ebdf6c9
commit e1a491edce
11 changed files with 74 additions and 73 deletions

View File

@@ -43,13 +43,14 @@ import {
} from 'n8n-workflow';
import * as Db from '@/Db';
import { ICredentialsDb, WhereClause } from '@/Interfaces';
import { ICredentialsDb } from '@/Interfaces';
import * as WorkflowExecuteAdditionalData from '@/WorkflowExecuteAdditionalData';
import { User } from '@db/entities/User';
import { CredentialsEntity } from '@db/entities/CredentialsEntity';
import { NodeTypes } from '@/NodeTypes';
import { CredentialsOverwrites } from '@/CredentialsOverwrites';
import { CredentialTypes } from '@/CredentialTypes';
import { whereClause } from './UserManagement/UserManagementHelper';
const mockNodeTypes: INodeTypes = {
nodeTypes: {} as INodeTypeData,
@@ -738,28 +739,6 @@ export class CredentialsHelper extends ICredentialsHelper {
}
}
/**
* Build a `where` clause for a `find()` or `findOne()` operation
* in the `shared_workflow` or `shared_credentials` tables.
*/
export function whereClause({
user,
entityType,
entityId = '',
}: {
user: User;
entityType: 'workflow' | 'credentials';
entityId?: string;
}): WhereClause {
const where: WhereClause = entityId ? { [entityType]: { id: entityId } } : {};
if (user.globalRole.name !== 'owner') {
where.user = { id: user.id };
}
return where;
}
/**
* Get a credential if it has been shared with a user.
*/