refactor(core): Remove roleId indirection (no-changelog) (#8413)
This commit is contained in:
committed by
GitHub
parent
1affebd85e
commit
d6deceacde
@@ -8,13 +8,11 @@ import type { EntityManager } from 'typeorm';
|
||||
import * as Db from '@/Db';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { SharedCredentials } from '@db/entities/SharedCredentials';
|
||||
import type { Role } from '@db/entities/Role';
|
||||
import { CredentialsEntity } from '@db/entities/CredentialsEntity';
|
||||
import { disableAutoGeneratedIds } from '@db/utils/commandHelpers';
|
||||
import { BaseCommand } from '../BaseCommand';
|
||||
import type { ICredentialsEncrypted } from 'n8n-workflow';
|
||||
import { ApplicationError, jsonParse } from 'n8n-workflow';
|
||||
import { RoleService } from '@/services/role.service';
|
||||
import { UM_FIX_INSTRUCTION } from '@/constants';
|
||||
import { UserRepository } from '@db/repositories/user.repository';
|
||||
|
||||
@@ -42,8 +40,6 @@ export class ImportCredentialsCommand extends BaseCommand {
|
||||
}),
|
||||
};
|
||||
|
||||
private ownerCredentialRole: Role;
|
||||
|
||||
private transactionManager: EntityManager;
|
||||
|
||||
async init() {
|
||||
@@ -71,7 +67,6 @@ export class ImportCredentialsCommand extends BaseCommand {
|
||||
let totalImported = 0;
|
||||
|
||||
const cipher = Container.get(Cipher);
|
||||
await this.initOwnerCredentialRole();
|
||||
const user = flags.userId ? await this.getAssignee(flags.userId) : await this.getOwner();
|
||||
|
||||
if (flags.separate) {
|
||||
@@ -145,16 +140,6 @@ export class ImportCredentialsCommand extends BaseCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private async initOwnerCredentialRole() {
|
||||
const ownerCredentialRole = await Container.get(RoleService).findCredentialOwnerRole();
|
||||
|
||||
if (!ownerCredentialRole) {
|
||||
throw new ApplicationError(`Failed to find owner credential role. ${UM_FIX_INSTRUCTION}`);
|
||||
}
|
||||
|
||||
this.ownerCredentialRole = ownerCredentialRole;
|
||||
}
|
||||
|
||||
private async storeCredential(credential: Partial<CredentialsEntity>, user: User) {
|
||||
if (!credential.nodesAccess) {
|
||||
credential.nodesAccess = [];
|
||||
@@ -165,19 +150,14 @@ export class ImportCredentialsCommand extends BaseCommand {
|
||||
{
|
||||
credentialsId: result.identifiers[0].id as string,
|
||||
userId: user.id,
|
||||
roleId: this.ownerCredentialRole.id,
|
||||
role: 'credential:owner',
|
||||
},
|
||||
['credentialsId', 'userId'],
|
||||
);
|
||||
}
|
||||
|
||||
private async getOwner() {
|
||||
const ownerGlobalRole = await Container.get(RoleService).findGlobalOwnerRole();
|
||||
|
||||
const owner =
|
||||
ownerGlobalRole &&
|
||||
(await Container.get(UserRepository).findOneBy({ globalRoleId: ownerGlobalRole.id }));
|
||||
|
||||
const owner = await Container.get(UserRepository).findOneBy({ role: 'global:owner' });
|
||||
if (!owner) {
|
||||
throw new ApplicationError(`Failed to find owner. ${UM_FIX_INSTRUCTION}`);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import { generateNanoId } from '@db/utils/generators';
|
||||
import { UserRepository } from '@db/repositories/user.repository';
|
||||
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
||||
import type { IWorkflowToImport } from '@/Interfaces';
|
||||
import { RoleService } from '@/services/role.service';
|
||||
import { ImportService } from '@/services/import.service';
|
||||
import { BaseCommand } from '../BaseCommand';
|
||||
|
||||
@@ -138,12 +137,7 @@ export class ImportWorkflowsCommand extends BaseCommand {
|
||||
}
|
||||
|
||||
private async getOwner() {
|
||||
const ownerGlobalRole = await Container.get(RoleService).findGlobalOwnerRole();
|
||||
|
||||
const owner =
|
||||
ownerGlobalRole &&
|
||||
(await Container.get(UserRepository).findOneBy({ globalRoleId: ownerGlobalRole?.id }));
|
||||
|
||||
const owner = await Container.get(UserRepository).findOneBy({ role: 'global:owner' });
|
||||
if (!owner) {
|
||||
throw new ApplicationError(`Failed to find owner. ${UM_FIX_INSTRUCTION}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user