refactor(core): Move typeorm operators from various sources into repositories (no-changelog) (#8174)
Follow-up to: #8165
This commit is contained in:
@@ -18,6 +18,7 @@ import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.reposi
|
||||
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
||||
import { NotFoundError } from '@/errors/response-errors/not-found.error';
|
||||
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
|
||||
import { CredentialsRepository } from '@/databases/repositories/credentials.repository';
|
||||
|
||||
@Service()
|
||||
export class EnterpriseWorkflowService {
|
||||
@@ -27,6 +28,7 @@ export class EnterpriseWorkflowService {
|
||||
private readonly roleService: RoleService,
|
||||
private readonly sharedWorkflowRepository: SharedWorkflowRepository,
|
||||
private readonly workflowRepository: WorkflowRepository,
|
||||
private readonly credentialsRepository: CredentialsRepository,
|
||||
) {}
|
||||
|
||||
async isOwned(
|
||||
@@ -111,7 +113,7 @@ export class EnterpriseWorkflowService {
|
||||
credentialIdsUsedByWorkflow.add(credential.id);
|
||||
});
|
||||
});
|
||||
const workflowCredentials = await CredentialsService.getManyByIds(
|
||||
const workflowCredentials = await this.credentialsRepository.getManyByIds(
|
||||
Array.from(credentialIdsUsedByWorkflow),
|
||||
{ withSharings: true },
|
||||
);
|
||||
|
||||
@@ -20,7 +20,6 @@ import { NodeTypes } from '@/NodeTypes';
|
||||
import { WorkflowRunner } from '@/WorkflowRunner';
|
||||
import * as WorkflowExecuteAdditionalData from '@/WorkflowExecuteAdditionalData';
|
||||
import { TestWebhooks } from '@/TestWebhooks';
|
||||
import { whereClause } from '@/UserManagement/UserManagementHelper';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
||||
import { OwnershipService } from '@/services/ownership.service';
|
||||
@@ -137,16 +136,12 @@ export class WorkflowService {
|
||||
forceSave?: boolean,
|
||||
roles?: string[],
|
||||
): Promise<WorkflowEntity> {
|
||||
const shared = await this.sharedWorkflowRepository.findOne({
|
||||
relations: ['workflow', 'role'],
|
||||
where: whereClause({
|
||||
user,
|
||||
globalScope: 'workflow:update',
|
||||
entityType: 'workflow',
|
||||
entityId: workflowId,
|
||||
roles,
|
||||
}),
|
||||
});
|
||||
const shared = await this.sharedWorkflowRepository.findSharing(
|
||||
workflowId,
|
||||
user,
|
||||
'workflow:update',
|
||||
{ roles },
|
||||
);
|
||||
|
||||
if (!shared) {
|
||||
this.logger.verbose('User attempted to update a workflow without permissions', {
|
||||
@@ -403,16 +398,12 @@ export class WorkflowService {
|
||||
async delete(user: User, workflowId: string): Promise<WorkflowEntity | undefined> {
|
||||
await this.externalHooks.run('workflow.delete', [workflowId]);
|
||||
|
||||
const sharedWorkflow = await this.sharedWorkflowRepository.findOne({
|
||||
relations: ['workflow', 'role'],
|
||||
where: whereClause({
|
||||
user,
|
||||
globalScope: 'workflow:delete',
|
||||
entityType: 'workflow',
|
||||
entityId: workflowId,
|
||||
roles: ['owner'],
|
||||
}),
|
||||
});
|
||||
const sharedWorkflow = await this.sharedWorkflowRepository.findSharing(
|
||||
workflowId,
|
||||
user,
|
||||
'workflow:delete',
|
||||
{ roles: ['owner'] },
|
||||
);
|
||||
|
||||
if (!sharedWorkflow) {
|
||||
return;
|
||||
|
||||
@@ -16,7 +16,6 @@ import type { ListQuery, WorkflowRequest } from '@/requests';
|
||||
import { isBelowOnboardingThreshold } from '@/WorkflowHelpers';
|
||||
import { EEWorkflowController } from './workflows.controller.ee';
|
||||
import { WorkflowService } from './workflow.service';
|
||||
import { whereClause } from '@/UserManagement/UserManagementHelper';
|
||||
import { Container } from 'typedi';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { RoleService } from '@/services/role.service';
|
||||
@@ -196,22 +195,14 @@ workflowsController.get(
|
||||
ResponseHelper.send(async (req: WorkflowRequest.Get) => {
|
||||
const { id: workflowId } = req.params;
|
||||
|
||||
let relations = ['workflow', 'workflow.tags', 'role'];
|
||||
const extraRelations = config.getEnv('workflowTagsDisabled') ? [] : ['workflow.tags'];
|
||||
|
||||
if (config.getEnv('workflowTagsDisabled')) {
|
||||
relations = relations.filter((relation) => relation !== 'workflow.tags');
|
||||
}
|
||||
|
||||
const shared = await Container.get(SharedWorkflowRepository).findOne({
|
||||
relations,
|
||||
where: whereClause({
|
||||
user: req.user,
|
||||
entityType: 'workflow',
|
||||
globalScope: 'workflow:read',
|
||||
entityId: workflowId,
|
||||
roles: ['owner'],
|
||||
}),
|
||||
});
|
||||
const shared = await Container.get(SharedWorkflowRepository).findSharing(
|
||||
workflowId,
|
||||
req.user,
|
||||
'workflow:read',
|
||||
{ extraRelations },
|
||||
);
|
||||
|
||||
if (!shared) {
|
||||
Container.get(Logger).verbose('User attempted to access a workflow without permissions', {
|
||||
|
||||
Reference in New Issue
Block a user