refactor(core): Move typeorm operators from various sources into repositories (no-changelog) (#8174)

Follow-up to: #8165
This commit is contained in:
Iván Ovejero
2023-12-28 13:14:10 +01:00
committed by GitHub
parent 405e26757e
commit e418d42450
17 changed files with 185 additions and 209 deletions

View File

@@ -1,9 +1,4 @@
import { In } from 'typeorm';
import { Container } from 'typedi';
import type { Scope } from '@n8n/permissions';
import type { WhereClause } from '@/Interfaces';
import type { User } from '@db/entities/User';
import { License } from '@/License';
export function isSharingEnabled(): boolean {
@@ -29,32 +24,3 @@ export function rightDiff<T1, T2>(
return acc;
}, []);
}
/**
* Build a `where` clause for a TypeORM entity search,
* checking for member access if the user is not an owner.
*/
export function whereClause({
user,
entityType,
globalScope,
entityId = '',
roles = [],
}: {
user: User;
entityType: 'workflow' | 'credentials';
globalScope: Scope;
entityId?: string;
roles?: string[];
}): WhereClause {
const where: WhereClause = entityId ? { [entityType]: { id: entityId } } : {};
if (!user.hasGlobalScope(globalScope)) {
where.user = { id: user.id };
if (roles?.length) {
where.role = { name: In(roles) };
}
}
return where;
}