refactor(core): Finish removing UserManagementHelper (no-changelog) (#8418)

This commit is contained in:
Iván Ovejero
2024-01-23 13:58:31 +01:00
committed by GitHub
parent 2257ec63b3
commit c0bc94c78f
12 changed files with 36 additions and 36 deletions

View File

@@ -3,7 +3,7 @@ import type { INode, Workflow } from 'n8n-workflow';
import { NodeOperationError, WorkflowOperationError } from 'n8n-workflow';
import config from '@/config';
import { isSharingEnabled } from './UserManagementHelper';
import { License } from '@/License';
import { OwnershipService } from '@/services/ownership.service';
import { RoleService } from '@/services/role.service';
import { UserRepository } from '@db/repositories/user.repository';
@@ -18,6 +18,7 @@ export class PermissionChecker {
private readonly sharedWorkflowRepository: SharedWorkflowRepository,
private readonly roleService: RoleService,
private readonly ownershipService: OwnershipService,
private readonly license: License,
) {}
/**
@@ -46,7 +47,7 @@ export class PermissionChecker {
let workflowUserIds = [userId];
if (workflow.id && isSharingEnabled()) {
if (workflow.id && this.license.isSharingEnabled()) {
const workflowSharings = await this.sharedWorkflowRepository.find({
relations: ['workflow'],
where: { workflowId: workflow.id },
@@ -98,7 +99,7 @@ export class PermissionChecker {
let policy =
subworkflow.settings?.callerPolicy ?? config.getEnv('workflows.callerPolicyDefaultOption');
if (!isSharingEnabled()) {
if (!this.license.isSharingEnabled()) {
// Community version allows only same owner workflows
policy = 'workflowsFromSameOwner';
}

View File

@@ -1,6 +0,0 @@
import { Container } from 'typedi';
import { License } from '@/License';
export function isSharingEnabled(): boolean {
return Container.get(License).isSharingEnabled();
}

View File

@@ -5,7 +5,7 @@ import * as Db from '@/Db';
import * as ResponseHelper from '@/ResponseHelper';
import type { CredentialRequest } from '@/requests';
import { isSharingEnabled } from '@/UserManagement/UserManagementHelper';
import { License } from '@/License';
import { EECredentialsService as EECredentials } from './credentials.service.ee';
import { OwnershipService } from '@/services/ownership.service';
import { Container } from 'typedi';
@@ -24,7 +24,7 @@ import { InternalServerError } from '@/errors/response-errors/internal-server.er
export const EECredentialsController = express.Router();
EECredentialsController.use((req, res, next) => {
if (!isSharingEnabled()) {
if (!Container.get(License).isSharingEnabled()) {
// skip ee router and use free one
next('router');
return;

View File

@@ -3,7 +3,7 @@ import { ExecutionRequest } from './execution.types';
import { ExecutionService } from './execution.service';
import { Authorized, Get, Post, RestController } from '@/decorators';
import { EnterpriseExecutionsService } from './execution.service.ee';
import { isSharingEnabled } from '@/UserManagement/UserManagementHelper';
import { License } from '@/License';
import { WorkflowSharingService } from '@/workflows/workflowSharing.service';
import type { User } from '@/databases/entities/User';
import config from '@/config';
@@ -21,10 +21,11 @@ export class ExecutionsController {
private readonly enterpriseExecutionService: EnterpriseExecutionsService,
private readonly workflowSharingService: WorkflowSharingService,
private readonly activeExecutionService: ActiveExecutionService,
private readonly license: License,
) {}
private async getAccessibleWorkflowIds(user: User) {
return isSharingEnabled()
return this.license.isSharingEnabled()
? await this.workflowSharingService.getSharedWorkflowIds(user)
: await this.workflowSharingService.getSharedWorkflowIds(user, ['owner']);
}
@@ -68,7 +69,7 @@ export class ExecutionsController {
if (workflowIds.length === 0) throw new NotFoundError('Execution not found');
return isSharingEnabled()
return this.license.isSharingEnabled()
? await this.enterpriseExecutionService.findOne(req, workflowIds)
: await this.executionService.findOne(req, workflowIds);
}

View File

@@ -4,7 +4,7 @@ import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.reposi
import { CacheService } from '@/services/cache/cache.service';
import type { RoleNames, RoleScopes } from '@db/entities/Role';
import { InvalidRoleError } from '@/errors/invalid-role.error';
import { isSharingEnabled } from '@/UserManagement/UserManagementHelper';
import { License } from '@/License';
@Service()
export class RoleService {
@@ -12,6 +12,7 @@ export class RoleService {
private roleRepository: RoleRepository,
private sharedWorkflowRepository: SharedWorkflowRepository,
private cacheService: CacheService,
private readonly license: License,
) {
void this.populateCache();
}
@@ -103,6 +104,6 @@ export class RoleService {
}
async findCredentialOwnerRoleId() {
return isSharingEnabled() ? undefined : (await this.findCredentialOwnerRole()).id;
return this.license.isSharingEnabled() ? undefined : (await this.findCredentialOwnerRole()).id;
}
}

View File

@@ -21,7 +21,7 @@ import { validateEntity } from '@/GenericHelpers';
import { ExternalHooks } from '@/ExternalHooks';
import { ListQuery } from '@/requests';
import { WorkflowService } from './workflow.service';
import { isSharingEnabled } from '@/UserManagement/UserManagementHelper';
import { License } from '@/License';
import { InternalHooks } from '@/InternalHooks';
import { RoleService } from '@/services/role.service';
import * as utils from '@/utils';
@@ -64,6 +64,7 @@ export class WorkflowsController {
private readonly workflowSharingService: WorkflowSharingService,
private readonly sharedWorkflowRepository: SharedWorkflowRepository,
private readonly userRepository: UserRepository,
private readonly license: License,
private readonly mailer: UserManagementMailer,
private readonly urlService: UrlService,
) {}
@@ -92,7 +93,7 @@ export class WorkflowsController {
WorkflowHelpers.addNodeIds(newWorkflow);
if (isSharingEnabled()) {
if (this.license.isSharingEnabled()) {
// This is a new workflow, so we simply check if the user has access to
// all used workflows
@@ -150,7 +151,7 @@ export class WorkflowsController {
@Get('/', { middlewares: listQueryMiddleware })
async getAll(req: ListQuery.Request, res: express.Response) {
try {
const roles: RoleNames[] = isSharingEnabled() ? [] : ['owner'];
const roles: RoleNames[] = this.license.isSharingEnabled() ? [] : ['owner'];
const sharedWorkflowIds = await this.workflowSharingService.getSharedWorkflowIds(
req.user,
roles,
@@ -221,7 +222,7 @@ export class WorkflowsController {
async getWorkflow(req: WorkflowRequest.Get) {
const { id: workflowId } = req.params;
if (isSharingEnabled()) {
if (this.license.isSharingEnabled()) {
const relations = ['shared', 'shared.user', 'shared.role'];
if (!config.getEnv('workflowTagsDisabled')) {
relations.push('tags');
@@ -280,7 +281,7 @@ export class WorkflowsController {
const { tags, ...rest } = req.body;
Object.assign(updateData, rest);
if (isSharingEnabled()) {
if (this.license.isSharingEnabled()) {
updateData = await this.enterpriseWorkflowService.preventTampering(
updateData,
workflowId,
@@ -293,8 +294,8 @@ export class WorkflowsController {
updateData,
workflowId,
tags,
isSharingEnabled() ? forceSave : true,
isSharingEnabled() ? undefined : ['owner'],
this.license.isSharingEnabled() ? forceSave : true,
this.license.isSharingEnabled() ? undefined : ['owner'],
);
return updatedWorkflow;
@@ -320,7 +321,7 @@ export class WorkflowsController {
@Post('/run')
async runManually(req: WorkflowRequest.ManualRun) {
if (isSharingEnabled()) {
if (this.license.isSharingEnabled()) {
const workflow = this.workflowRepository.create(req.body.workflowData);
if (req.body.workflowData.id !== undefined) {
@@ -342,7 +343,7 @@ export class WorkflowsController {
@Put('/:workflowId/share')
async share(req: WorkflowRequest.Share) {
if (!isSharingEnabled()) throw new NotFoundError('Route not found');
if (!this.license.isSharingEnabled()) throw new NotFoundError('Route not found');
const { workflowId } = req.params;
const { shareWithIds } = req.body;