mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-13 16:14:07 -08:00
⚡ Remove non-null assertions for Db
collections (#3111)
* 📘 Remove unions to `null` * ⚡ Track `Db` initialization state * 🔥 Remove non-null assertions * 👕 Remove lint exceptions * 🔥 Remove leftover assertion
This commit is contained in:
parent
e45ac7eb6a
commit
3e5d981f3f
|
@ -108,8 +108,7 @@ export class Execute extends Command {
|
||||||
if (flags.id) {
|
if (flags.id) {
|
||||||
// Id of workflow is given
|
// Id of workflow is given
|
||||||
workflowId = flags.id;
|
workflowId = flags.id;
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
workflowData = await Db.collections.Workflow.findOne(workflowId);
|
||||||
workflowData = await Db.collections.Workflow!.findOne(workflowId);
|
|
||||||
if (workflowData === undefined) {
|
if (workflowData === undefined) {
|
||||||
console.info(`The workflow with the id "${workflowId}" does not exist.`);
|
console.info(`The workflow with the id "${workflowId}" does not exist.`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
|
@ -297,7 +297,7 @@ export class ExecuteBatch extends Command {
|
||||||
|
|
||||||
let allWorkflows;
|
let allWorkflows;
|
||||||
|
|
||||||
const query = Db.collections.Workflow!.createQueryBuilder('workflows');
|
const query = Db.collections.Workflow.createQueryBuilder('workflows');
|
||||||
|
|
||||||
if (ids.length > 0) {
|
if (ids.length > 0) {
|
||||||
query.andWhere(`workflows.id in (:...ids)`, { ids });
|
query.andWhere(`workflows.id in (:...ids)`, { ids });
|
||||||
|
|
|
@ -119,7 +119,7 @@ export class ExportCredentialsCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
const credentials = await Db.collections.Credentials!.find(findQuery);
|
const credentials = await Db.collections.Credentials.find(findQuery);
|
||||||
|
|
||||||
if (flags.decrypted) {
|
if (flags.decrypted) {
|
||||||
const encryptionKey = await UserSettings.getEncryptionKey();
|
const encryptionKey = await UserSettings.getEncryptionKey();
|
||||||
|
|
|
@ -111,7 +111,7 @@ export class ExportWorkflowsCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
const workflows = await Db.collections.Workflow!.find(findQuery);
|
const workflows = await Db.collections.Workflow.find(findQuery);
|
||||||
|
|
||||||
if (workflows.length === 0) {
|
if (workflows.length === 0) {
|
||||||
throw new Error('No workflows found with specified filters.');
|
throw new Error('No workflows found with specified filters.');
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
/* eslint-disable @typescript-eslint/no-shadow */
|
/* eslint-disable @typescript-eslint/no-shadow */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
|
@ -150,7 +149,7 @@ export class ImportCredentialsCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initOwnerCredentialRole() {
|
private async initOwnerCredentialRole() {
|
||||||
const ownerCredentialRole = await Db.collections.Role!.findOne({
|
const ownerCredentialRole = await Db.collections.Role.findOne({
|
||||||
where: { name: 'owner', scope: 'credential' },
|
where: { name: 'owner', scope: 'credential' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -180,11 +179,11 @@ export class ImportCredentialsCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getOwner() {
|
private async getOwner() {
|
||||||
const ownerGlobalRole = await Db.collections.Role!.findOne({
|
const ownerGlobalRole = await Db.collections.Role.findOne({
|
||||||
where: { name: 'owner', scope: 'global' },
|
where: { name: 'owner', scope: 'global' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const owner = await Db.collections.User!.findOne({ globalRole: ownerGlobalRole });
|
const owner = await Db.collections.User.findOne({ globalRole: ownerGlobalRole });
|
||||||
|
|
||||||
if (!owner) {
|
if (!owner) {
|
||||||
throw new Error(`Failed to find owner. ${FIX_INSTRUCTION}`);
|
throw new Error(`Failed to find owner. ${FIX_INSTRUCTION}`);
|
||||||
|
@ -194,7 +193,7 @@ export class ImportCredentialsCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getAssignee(userId: string) {
|
private async getAssignee(userId: string) {
|
||||||
const user = await Db.collections.User!.findOne(userId);
|
const user = await Db.collections.User.findOne(userId);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error(`Failed to find user with ID ${userId}`);
|
throw new Error(`Failed to find user with ID ${userId}`);
|
||||||
|
|
|
@ -157,7 +157,7 @@ export class ImportWorkflowsCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initOwnerWorkflowRole() {
|
private async initOwnerWorkflowRole() {
|
||||||
const ownerWorkflowRole = await Db.collections.Role!.findOne({
|
const ownerWorkflowRole = await Db.collections.Role.findOne({
|
||||||
where: { name: 'owner', scope: 'workflow' },
|
where: { name: 'owner', scope: 'workflow' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -187,11 +187,11 @@ export class ImportWorkflowsCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getOwner() {
|
private async getOwner() {
|
||||||
const ownerGlobalRole = await Db.collections.Role!.findOne({
|
const ownerGlobalRole = await Db.collections.Role.findOne({
|
||||||
where: { name: 'owner', scope: 'global' },
|
where: { name: 'owner', scope: 'global' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const owner = await Db.collections.User!.findOne({ globalRole: ownerGlobalRole });
|
const owner = await Db.collections.User.findOne({ globalRole: ownerGlobalRole });
|
||||||
|
|
||||||
if (!owner) {
|
if (!owner) {
|
||||||
throw new Error(`Failed to find owner. ${FIX_INSTRUCTION}`);
|
throw new Error(`Failed to find owner. ${FIX_INSTRUCTION}`);
|
||||||
|
@ -201,7 +201,7 @@ export class ImportWorkflowsCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getAssignee(userId: string) {
|
private async getAssignee(userId: string) {
|
||||||
const user = await Db.collections.User!.findOne(userId);
|
const user = await Db.collections.User.findOne(userId);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error(`Failed to find user with ID ${userId}`);
|
throw new Error(`Failed to find user with ID ${userId}`);
|
||||||
|
|
|
@ -42,8 +42,7 @@ export class ListWorkflowCommand extends Command {
|
||||||
findQuery.active = flags.active === 'true';
|
findQuery.active = flags.active === 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
const workflows = await Db.collections.Workflow.find(findQuery);
|
||||||
const workflows = await Db.collections.Workflow!.find(findQuery);
|
|
||||||
if (flags.onlyId) {
|
if (flags.onlyId) {
|
||||||
workflows.forEach((workflow) => console.log(workflow.id));
|
workflows.forEach((workflow) => console.log(workflow.id));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -217,7 +217,7 @@ export class Start extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load settings from database and set them to config.
|
// Load settings from database and set them to config.
|
||||||
const databaseSettings = await Db.collections.Settings!.find({ loadOnStartup: true });
|
const databaseSettings = await Db.collections.Settings.find({ loadOnStartup: true });
|
||||||
databaseSettings.forEach((setting) => {
|
databaseSettings.forEach((setting) => {
|
||||||
config.set(setting.key, JSON.parse(setting.value));
|
config.set(setting.key, JSON.parse(setting.value));
|
||||||
});
|
});
|
||||||
|
@ -287,8 +287,8 @@ export class Start extends Command {
|
||||||
if (dbType === 'sqlite') {
|
if (dbType === 'sqlite') {
|
||||||
const shouldRunVacuum = config.getEnv('database.sqlite.executeVacuumOnStartup');
|
const shouldRunVacuum = config.getEnv('database.sqlite.executeVacuumOnStartup');
|
||||||
if (shouldRunVacuum) {
|
if (shouldRunVacuum) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises, @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
await Db.collections.Execution!.query('VACUUM;');
|
await Db.collections.Execution.query('VACUUM;');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,7 @@ export class UpdateWorkflowCommand extends Command {
|
||||||
findQuery.active = true;
|
findQuery.active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
await Db.collections.Workflow.update(findQuery, updateQuery);
|
||||||
await Db.collections.Workflow!.update(findQuery, updateQuery);
|
|
||||||
console.info('Done');
|
console.info('Done');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error updating database. See log messages for details.');
|
console.error('Error updating database. See log messages for details.');
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
||||||
|
|
||||||
import Command from '@oclif/command';
|
import Command from '@oclif/command';
|
||||||
import { Not } from 'typeorm';
|
import { Not } from 'typeorm';
|
||||||
|
@ -27,33 +26,33 @@ export class Reset extends Command {
|
||||||
try {
|
try {
|
||||||
const owner = await this.getInstanceOwner();
|
const owner = await this.getInstanceOwner();
|
||||||
|
|
||||||
const ownerWorkflowRole = await Db.collections.Role!.findOneOrFail({
|
const ownerWorkflowRole = await Db.collections.Role.findOneOrFail({
|
||||||
name: 'owner',
|
name: 'owner',
|
||||||
scope: 'workflow',
|
scope: 'workflow',
|
||||||
});
|
});
|
||||||
|
|
||||||
const ownerCredentialRole = await Db.collections.Role!.findOneOrFail({
|
const ownerCredentialRole = await Db.collections.Role.findOneOrFail({
|
||||||
name: 'owner',
|
name: 'owner',
|
||||||
scope: 'credential',
|
scope: 'credential',
|
||||||
});
|
});
|
||||||
|
|
||||||
await Db.collections.SharedWorkflow!.update(
|
await Db.collections.SharedWorkflow.update(
|
||||||
{ user: { id: Not(owner.id) }, role: ownerWorkflowRole },
|
{ user: { id: Not(owner.id) }, role: ownerWorkflowRole },
|
||||||
{ user: owner },
|
{ user: owner },
|
||||||
);
|
);
|
||||||
|
|
||||||
await Db.collections.SharedCredentials!.update(
|
await Db.collections.SharedCredentials.update(
|
||||||
{ user: { id: Not(owner.id) }, role: ownerCredentialRole },
|
{ user: { id: Not(owner.id) }, role: ownerCredentialRole },
|
||||||
{ user: owner },
|
{ user: owner },
|
||||||
);
|
);
|
||||||
await Db.collections.User!.delete({ id: Not(owner.id) });
|
await Db.collections.User.delete({ id: Not(owner.id) });
|
||||||
await Db.collections.User!.save(Object.assign(owner, this.defaultUserProps));
|
await Db.collections.User.save(Object.assign(owner, this.defaultUserProps));
|
||||||
|
|
||||||
await Db.collections.Settings!.update(
|
await Db.collections.Settings.update(
|
||||||
{ key: 'userManagement.isInstanceOwnerSetUp' },
|
{ key: 'userManagement.isInstanceOwnerSetUp' },
|
||||||
{ value: 'false' },
|
{ value: 'false' },
|
||||||
);
|
);
|
||||||
await Db.collections.Settings!.update(
|
await Db.collections.Settings.update(
|
||||||
{ key: 'userManagement.skipInstanceOwnerSetup' },
|
{ key: 'userManagement.skipInstanceOwnerSetup' },
|
||||||
{ value: 'false' },
|
{ value: 'false' },
|
||||||
);
|
);
|
||||||
|
@ -68,19 +67,19 @@ export class Reset extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getInstanceOwner(): Promise<User> {
|
private async getInstanceOwner(): Promise<User> {
|
||||||
const globalRole = await Db.collections.Role!.findOneOrFail({
|
const globalRole = await Db.collections.Role.findOneOrFail({
|
||||||
name: 'owner',
|
name: 'owner',
|
||||||
scope: 'global',
|
scope: 'global',
|
||||||
});
|
});
|
||||||
|
|
||||||
const owner = await Db.collections.User!.findOne({ globalRole });
|
const owner = await Db.collections.User.findOne({ globalRole });
|
||||||
|
|
||||||
if (owner) return owner;
|
if (owner) return owner;
|
||||||
|
|
||||||
const user = new User();
|
const user = new User();
|
||||||
|
|
||||||
await Db.collections.User!.save(Object.assign(user, { ...this.defaultUserProps, globalRole }));
|
await Db.collections.User.save(Object.assign(user, { ...this.defaultUserProps, globalRole }));
|
||||||
|
|
||||||
return Db.collections.User!.findOneOrFail({ globalRole });
|
return Db.collections.User.findOneOrFail({ globalRole });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ export class Worker extends Command {
|
||||||
|
|
||||||
async runJob(job: Bull.Job, nodeTypes: INodeTypes): Promise<IBullJobResponse> {
|
async runJob(job: Bull.Job, nodeTypes: INodeTypes): Promise<IBullJobResponse> {
|
||||||
const jobData = job.data as IBullJobData;
|
const jobData = job.data as IBullJobData;
|
||||||
const executionDb = await Db.collections.Execution!.findOne(jobData.executionId);
|
const executionDb = await Db.collections.Execution.findOne(jobData.executionId);
|
||||||
|
|
||||||
if (!executionDb) {
|
if (!executionDb) {
|
||||||
LoggerProxy.error('Worker failed to find execution data in database. Cannot continue.', {
|
LoggerProxy.error('Worker failed to find execution data in database. Cannot continue.', {
|
||||||
|
@ -139,7 +139,7 @@ export class Worker extends Command {
|
||||||
const findOptions = {
|
const findOptions = {
|
||||||
select: ['id', 'staticData'],
|
select: ['id', 'staticData'],
|
||||||
} as FindOneOptions;
|
} as FindOneOptions;
|
||||||
const workflowData = await Db.collections.Workflow!.findOne(
|
const workflowData = await Db.collections.Workflow.findOne(
|
||||||
currentExecutionDb.workflowData.id,
|
currentExecutionDb.workflowData.id,
|
||||||
findOptions,
|
findOptions,
|
||||||
);
|
);
|
||||||
|
|
|
@ -69,7 +69,7 @@ export class ActiveWorkflowRunner {
|
||||||
// NOTE
|
// NOTE
|
||||||
// Here I guess we can have a flag on the workflow table like hasTrigger
|
// Here I guess we can have a flag on the workflow table like hasTrigger
|
||||||
// so intead of pulling all the active wehhooks just pull the actives that have a trigger
|
// so intead of pulling all the active wehhooks just pull the actives that have a trigger
|
||||||
const workflowsData: IWorkflowDb[] = (await Db.collections.Workflow!.find({
|
const workflowsData: IWorkflowDb[] = (await Db.collections.Workflow.find({
|
||||||
where: { active: true },
|
where: { active: true },
|
||||||
relations: ['shared', 'shared.user', 'shared.user.globalRole'],
|
relations: ['shared', 'shared.user', 'shared.user.globalRole'],
|
||||||
})) as IWorkflowDb[];
|
})) as IWorkflowDb[];
|
||||||
|
@ -256,7 +256,7 @@ export class ActiveWorkflowRunner {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const workflowData = await Db.collections.Workflow!.findOne(webhook.workflowId, {
|
const workflowData = await Db.collections.Workflow.findOne(webhook.workflowId, {
|
||||||
relations: ['shared', 'shared.user', 'shared.user.globalRole'],
|
relations: ['shared', 'shared.user', 'shared.user.globalRole'],
|
||||||
});
|
});
|
||||||
if (workflowData === undefined) {
|
if (workflowData === undefined) {
|
||||||
|
@ -332,7 +332,7 @@ export class ActiveWorkflowRunner {
|
||||||
* @memberof ActiveWorkflowRunner
|
* @memberof ActiveWorkflowRunner
|
||||||
*/
|
*/
|
||||||
async getWebhookMethods(path: string): Promise<string[]> {
|
async getWebhookMethods(path: string): Promise<string[]> {
|
||||||
const webhooks = (await Db.collections.Webhook?.find({ webhookPath: path })) as IWebhookDb[];
|
const webhooks = await Db.collections.Webhook?.find({ webhookPath: path });
|
||||||
|
|
||||||
// Gather all request methods in string array
|
// Gather all request methods in string array
|
||||||
const webhookMethods: string[] = webhooks.map((webhook) => webhook.method);
|
const webhookMethods: string[] = webhooks.map((webhook) => webhook.method);
|
||||||
|
@ -349,12 +349,12 @@ export class ActiveWorkflowRunner {
|
||||||
let activeWorkflows: WorkflowEntity[] = [];
|
let activeWorkflows: WorkflowEntity[] = [];
|
||||||
|
|
||||||
if (!user || user.globalRole.name === 'owner') {
|
if (!user || user.globalRole.name === 'owner') {
|
||||||
activeWorkflows = await Db.collections.Workflow!.find({
|
activeWorkflows = await Db.collections.Workflow.find({
|
||||||
select: ['id'],
|
select: ['id'],
|
||||||
where: { active: true },
|
where: { active: true },
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const shared = await Db.collections.SharedWorkflow!.find({
|
const shared = await Db.collections.SharedWorkflow.find({
|
||||||
relations: ['workflow'],
|
relations: ['workflow'],
|
||||||
where: whereClause({
|
where: whereClause({
|
||||||
user,
|
user,
|
||||||
|
@ -379,7 +379,7 @@ export class ActiveWorkflowRunner {
|
||||||
* @memberof ActiveWorkflowRunner
|
* @memberof ActiveWorkflowRunner
|
||||||
*/
|
*/
|
||||||
async isActive(id: string): Promise<boolean> {
|
async isActive(id: string): Promise<boolean> {
|
||||||
const workflow = await Db.collections.Workflow!.findOne(id);
|
const workflow = await Db.collections.Workflow.findOne(id);
|
||||||
return !!workflow?.active;
|
return !!workflow?.active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,7 +512,7 @@ export class ActiveWorkflowRunner {
|
||||||
* @memberof ActiveWorkflowRunner
|
* @memberof ActiveWorkflowRunner
|
||||||
*/
|
*/
|
||||||
async removeWorkflowWebhooks(workflowId: string): Promise<void> {
|
async removeWorkflowWebhooks(workflowId: string): Promise<void> {
|
||||||
const workflowData = await Db.collections.Workflow!.findOne(workflowId, {
|
const workflowData = await Db.collections.Workflow.findOne(workflowId, {
|
||||||
relations: ['shared', 'shared.user', 'shared.user.globalRole'],
|
relations: ['shared', 'shared.user', 'shared.user.globalRole'],
|
||||||
});
|
});
|
||||||
if (workflowData === undefined) {
|
if (workflowData === undefined) {
|
||||||
|
@ -715,7 +715,7 @@ export class ActiveWorkflowRunner {
|
||||||
let workflowInstance: Workflow;
|
let workflowInstance: Workflow;
|
||||||
try {
|
try {
|
||||||
if (workflowData === undefined) {
|
if (workflowData === undefined) {
|
||||||
workflowData = (await Db.collections.Workflow!.findOne(workflowId, {
|
workflowData = (await Db.collections.Workflow.findOne(workflowId, {
|
||||||
relations: ['shared', 'shared.user', 'shared.user.globalRole'],
|
relations: ['shared', 'shared.user', 'shared.user.globalRole'],
|
||||||
})) as IWorkflowDb;
|
})) as IWorkflowDb;
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,13 +235,11 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
const credential = userId
|
const credential = userId
|
||||||
? await Db.collections
|
? await Db.collections.SharedCredentials.findOneOrFail({
|
||||||
.SharedCredentials!.findOneOrFail({
|
|
||||||
relations: ['credentials'],
|
relations: ['credentials'],
|
||||||
where: { credentials: { id: nodeCredential.id, type }, user: { id: userId } },
|
where: { credentials: { id: nodeCredential.id, type }, user: { id: userId } },
|
||||||
})
|
}).then((shared) => shared.credentials)
|
||||||
.then((shared) => shared.credentials)
|
: await Db.collections.Credentials.findOneOrFail({ id: nodeCredential.id, type });
|
||||||
: await Db.collections.Credentials!.findOneOrFail({ id: nodeCredential.id, type });
|
|
||||||
|
|
||||||
if (!credential) {
|
if (!credential) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
@ -445,7 +443,7 @@ export class CredentialsHelper extends ICredentialsHelper {
|
||||||
type,
|
type,
|
||||||
};
|
};
|
||||||
|
|
||||||
await Db.collections.Credentials!.update(findQuery, newCredentialsData);
|
await Db.collections.Credentials.update(findQuery, newCredentialsData);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCredentialTestFunction(
|
getCredentialTestFunction(
|
||||||
|
@ -721,8 +719,7 @@ export async function getCredentialForUser(
|
||||||
credentialId: string,
|
credentialId: string,
|
||||||
user: User,
|
user: User,
|
||||||
): Promise<ICredentialsDb | null> {
|
): Promise<ICredentialsDb | null> {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
const sharedCredential = await Db.collections.SharedCredentials.findOne({
|
||||||
const sharedCredential = await Db.collections.SharedCredentials!.findOne({
|
|
||||||
relations: ['credentials'],
|
relations: ['credentials'],
|
||||||
where: whereClause({
|
where: whereClause({
|
||||||
user,
|
user,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable import/no-mutable-exports */
|
||||||
/* eslint-disable import/no-cycle */
|
/* eslint-disable import/no-cycle */
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||||
|
@ -28,18 +29,8 @@ import { postgresMigrations } from './databases/postgresdb/migrations';
|
||||||
import { mysqlMigrations } from './databases/mysqldb/migrations';
|
import { mysqlMigrations } from './databases/mysqldb/migrations';
|
||||||
import { sqliteMigrations } from './databases/sqlite/migrations';
|
import { sqliteMigrations } from './databases/sqlite/migrations';
|
||||||
|
|
||||||
export const collections: IDatabaseCollections = {
|
export let isInitialized = false;
|
||||||
Credentials: null,
|
export const collections = {} as IDatabaseCollections;
|
||||||
Execution: null,
|
|
||||||
Workflow: null,
|
|
||||||
Webhook: null,
|
|
||||||
Tag: null,
|
|
||||||
Role: null,
|
|
||||||
User: null,
|
|
||||||
SharedCredentials: null,
|
|
||||||
SharedWorkflow: null,
|
|
||||||
Settings: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
let connection: Connection;
|
let connection: Connection;
|
||||||
|
|
||||||
|
@ -202,5 +193,7 @@ export async function init(
|
||||||
collections.SharedWorkflow = linkRepository(entities.SharedWorkflow);
|
collections.SharedWorkflow = linkRepository(entities.SharedWorkflow);
|
||||||
collections.Settings = linkRepository(entities.Settings);
|
collections.Settings = linkRepository(entities.Settings);
|
||||||
|
|
||||||
|
isInitialized = true;
|
||||||
|
|
||||||
return collections;
|
return collections;
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,8 +165,8 @@ export async function generateUniqueName(
|
||||||
|
|
||||||
const found: Array<WorkflowEntity | ICredentialsDb> =
|
const found: Array<WorkflowEntity | ICredentialsDb> =
|
||||||
entityType === 'workflow'
|
entityType === 'workflow'
|
||||||
? await Db.collections.Workflow!.find(findConditions)
|
? await Db.collections.Workflow.find(findConditions)
|
||||||
: await Db.collections.Credentials!.find(findConditions);
|
: await Db.collections.Credentials.find(findConditions);
|
||||||
|
|
||||||
// name is unique
|
// name is unique
|
||||||
if (found.length === 0) {
|
if (found.length === 0) {
|
||||||
|
|
|
@ -72,16 +72,16 @@ export interface ICredentialsOverwrite {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDatabaseCollections {
|
export interface IDatabaseCollections {
|
||||||
Credentials: Repository<ICredentialsDb> | null;
|
Credentials: Repository<ICredentialsDb>;
|
||||||
Execution: Repository<IExecutionFlattedDb> | null;
|
Execution: Repository<IExecutionFlattedDb>;
|
||||||
Workflow: Repository<WorkflowEntity> | null;
|
Workflow: Repository<WorkflowEntity>;
|
||||||
Webhook: Repository<IWebhookDb> | null;
|
Webhook: Repository<IWebhookDb>;
|
||||||
Tag: Repository<TagEntity> | null;
|
Tag: Repository<TagEntity>;
|
||||||
Role: Repository<Role> | null;
|
Role: Repository<Role>;
|
||||||
User: Repository<User> | null;
|
User: Repository<User>;
|
||||||
SharedCredentials: Repository<SharedCredentials> | null;
|
SharedCredentials: Repository<SharedCredentials>;
|
||||||
SharedWorkflow: Repository<SharedWorkflow> | null;
|
SharedWorkflow: Repository<SharedWorkflow>;
|
||||||
Settings: Repository<Settings> | null;
|
Settings: Repository<Settings>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IWebhookDb {
|
export interface IWebhookDb {
|
||||||
|
|
|
@ -671,7 +671,7 @@ class App {
|
||||||
|
|
||||||
// eslint-disable-next-line consistent-return
|
// eslint-disable-next-line consistent-return
|
||||||
this.app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
|
this.app.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
if (Db.collections.Workflow === null) {
|
if (!Db.isInitialized) {
|
||||||
const error = new ResponseHelper.ResponseError('Database is not ready!', undefined, 503);
|
const error = new ResponseHelper.ResponseError('Database is not ready!', undefined, 503);
|
||||||
return ResponseHelper.sendErrorResponse(res, error);
|
return ResponseHelper.sendErrorResponse(res, error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import * as config from '../../config';
|
||||||
import { getWebhookBaseUrl } from '../WebhookHelpers';
|
import { getWebhookBaseUrl } from '../WebhookHelpers';
|
||||||
|
|
||||||
export async function getWorkflowOwner(workflowId: string | number): Promise<User> {
|
export async function getWorkflowOwner(workflowId: string | number): Promise<User> {
|
||||||
const sharedWorkflow = await Db.collections.SharedWorkflow!.findOneOrFail({
|
const sharedWorkflow = await Db.collections.SharedWorkflow.findOneOrFail({
|
||||||
where: { workflow: { id: workflowId } },
|
where: { workflow: { id: workflowId } },
|
||||||
relations: ['user', 'user.globalRole'],
|
relations: ['user', 'user.globalRole'],
|
||||||
});
|
});
|
||||||
|
@ -33,7 +33,7 @@ export function isEmailSetUp(): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getInstanceOwnerRole(): Promise<Role> {
|
async function getInstanceOwnerRole(): Promise<Role> {
|
||||||
const ownerRole = await Db.collections.Role!.findOneOrFail({
|
const ownerRole = await Db.collections.Role.findOneOrFail({
|
||||||
where: {
|
where: {
|
||||||
name: 'owner',
|
name: 'owner',
|
||||||
scope: 'global',
|
scope: 'global',
|
||||||
|
@ -45,7 +45,7 @@ async function getInstanceOwnerRole(): Promise<Role> {
|
||||||
export async function getInstanceOwner(): Promise<User> {
|
export async function getInstanceOwner(): Promise<User> {
|
||||||
const ownerRole = await getInstanceOwnerRole();
|
const ownerRole = await getInstanceOwnerRole();
|
||||||
|
|
||||||
const owner = await Db.collections.User!.findOneOrFail({
|
const owner = await Db.collections.User.findOneOrFail({
|
||||||
relations: ['globalRole'],
|
relations: ['globalRole'],
|
||||||
where: {
|
where: {
|
||||||
globalRole: ownerRole,
|
globalRole: ownerRole,
|
||||||
|
@ -121,7 +121,7 @@ export function sanitizeUser(user: User, withoutKeys?: string[]): PublicUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUserById(userId: string): Promise<User> {
|
export async function getUserById(userId: string): Promise<User> {
|
||||||
const user = await Db.collections.User!.findOneOrFail(userId, {
|
const user = await Db.collections.User.findOneOrFail(userId, {
|
||||||
relations: ['globalRole'],
|
relations: ['globalRole'],
|
||||||
});
|
});
|
||||||
return user;
|
return user;
|
||||||
|
@ -174,7 +174,7 @@ export async function checkPermissionsForExecution(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for the user's permission to all used credentials
|
// Check for the user's permission to all used credentials
|
||||||
const credentialCount = await Db.collections.SharedCredentials!.count({
|
const credentialCount = await Db.collections.SharedCredentials.count({
|
||||||
where: {
|
where: {
|
||||||
user: { id: userId },
|
user: { id: userId },
|
||||||
credentials: In(ids),
|
credentials: In(ids),
|
||||||
|
|
|
@ -37,7 +37,7 @@ export function issueJWT(user: User): JwtToken {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resolveJwtContent(jwtPayload: JwtPayload): Promise<User> {
|
export async function resolveJwtContent(jwtPayload: JwtPayload): Promise<User> {
|
||||||
const user = await Db.collections.User!.findOne(jwtPayload.id, {
|
const user = await Db.collections.User.findOne(jwtPayload.id, {
|
||||||
relations: ['globalRole'],
|
relations: ['globalRole'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,6 @@ export class UserManagementMailer {
|
||||||
let template = await getTemplate('invite', 'invite.html');
|
let template = await getTemplate('invite', 'invite.html');
|
||||||
template = replaceStrings(template, inviteEmailData);
|
template = replaceStrings(template, inviteEmailData);
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
const result = await this.mailer?.sendMail({
|
const result = await this.mailer?.sendMail({
|
||||||
emailRecipients: inviteEmailData.email,
|
emailRecipients: inviteEmailData.email,
|
||||||
subject: 'You have been invited to n8n',
|
subject: 'You have been invited to n8n',
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
/* eslint-disable import/no-cycle */
|
/* eslint-disable import/no-cycle */
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
||||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { IDataObject } from 'n8n-workflow';
|
import { IDataObject } from 'n8n-workflow';
|
||||||
|
@ -32,7 +31,7 @@ export function authenticationMethods(this: N8nApp): void {
|
||||||
|
|
||||||
let user;
|
let user;
|
||||||
try {
|
try {
|
||||||
user = await Db.collections.User!.findOne(
|
user = await Db.collections.User.findOne(
|
||||||
{
|
{
|
||||||
email: req.body.email,
|
email: req.body.email,
|
||||||
},
|
},
|
||||||
|
@ -91,7 +90,7 @@ export function authenticationMethods(this: N8nApp): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
user = await Db.collections.User!.findOneOrFail({ relations: ['globalRole'] });
|
user = await Db.collections.User.findOneOrFail({ relations: ['globalRole'] });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'No users found in database - did you wipe the users table? Create at least one user.',
|
'No users found in database - did you wipe the users table? Create at least one user.',
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
||||||
/* eslint-disable import/no-cycle */
|
/* eslint-disable import/no-cycle */
|
||||||
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
|
@ -53,7 +52,7 @@ export function meNamespace(this: N8nApp): void {
|
||||||
|
|
||||||
await validateEntity(newUser);
|
await validateEntity(newUser);
|
||||||
|
|
||||||
const user = await Db.collections.User!.save(newUser);
|
const user = await Db.collections.User.save(newUser);
|
||||||
|
|
||||||
Logger.info('User updated successfully', { userId: user.id });
|
Logger.info('User updated successfully', { userId: user.id });
|
||||||
|
|
||||||
|
@ -99,7 +98,7 @@ export function meNamespace(this: N8nApp): void {
|
||||||
|
|
||||||
req.user.password = await hashPassword(validPassword);
|
req.user.password = await hashPassword(validPassword);
|
||||||
|
|
||||||
const user = await Db.collections.User!.save(req.user);
|
const user = await Db.collections.User.save(req.user);
|
||||||
Logger.info('Password updated successfully', { userId: user.id });
|
Logger.info('Password updated successfully', { userId: user.id });
|
||||||
|
|
||||||
await issueCookie(res, user);
|
await issueCookie(res, user);
|
||||||
|
@ -135,7 +134,7 @@ export function meNamespace(this: N8nApp): void {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Db.collections.User!.save({
|
await Db.collections.User.save({
|
||||||
id: req.user.id,
|
id: req.user.id,
|
||||||
personalizationAnswers,
|
personalizationAnswers,
|
||||||
});
|
});
|
||||||
|
|
|
@ -55,7 +55,7 @@ export function ownerNamespace(this: N8nApp): void {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let owner = await Db.collections.User!.findOne(userId, {
|
let owner = await Db.collections.User.findOne(userId, {
|
||||||
relations: ['globalRole'],
|
relations: ['globalRole'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -78,11 +78,11 @@ export function ownerNamespace(this: N8nApp): void {
|
||||||
|
|
||||||
await validateEntity(owner);
|
await validateEntity(owner);
|
||||||
|
|
||||||
owner = await Db.collections.User!.save(owner);
|
owner = await Db.collections.User.save(owner);
|
||||||
|
|
||||||
Logger.info('Owner was set up successfully', { userId: req.user.id });
|
Logger.info('Owner was set up successfully', { userId: req.user.id });
|
||||||
|
|
||||||
await Db.collections.Settings!.update(
|
await Db.collections.Settings.update(
|
||||||
{ key: 'userManagement.isInstanceOwnerSetUp' },
|
{ key: 'userManagement.isInstanceOwnerSetUp' },
|
||||||
{ value: JSON.stringify(true) },
|
{ value: JSON.stringify(true) },
|
||||||
);
|
);
|
||||||
|
@ -108,7 +108,7 @@ export function ownerNamespace(this: N8nApp): void {
|
||||||
`/${this.restEndpoint}/owner/skip-setup`,
|
`/${this.restEndpoint}/owner/skip-setup`,
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
ResponseHelper.send(async (_req: AuthenticatedRequest, _res: express.Response) => {
|
ResponseHelper.send(async (_req: AuthenticatedRequest, _res: express.Response) => {
|
||||||
await Db.collections.Settings!.update(
|
await Db.collections.Settings.update(
|
||||||
{ key: 'userManagement.skipInstanceOwnerSetup' },
|
{ key: 'userManagement.skipInstanceOwnerSetup' },
|
||||||
{ value: JSON.stringify(true) },
|
{ value: JSON.stringify(true) },
|
||||||
);
|
);
|
||||||
|
|
|
@ -53,7 +53,7 @@ export function passwordResetNamespace(this: N8nApp): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// User should just be able to reset password if one is already present
|
// User should just be able to reset password if one is already present
|
||||||
const user = await Db.collections.User!.findOne({ email, password: Not(IsNull()) });
|
const user = await Db.collections.User.findOne({ email, password: Not(IsNull()) });
|
||||||
|
|
||||||
if (!user || !user.password) {
|
if (!user || !user.password) {
|
||||||
Logger.debug(
|
Logger.debug(
|
||||||
|
@ -69,7 +69,7 @@ export function passwordResetNamespace(this: N8nApp): void {
|
||||||
|
|
||||||
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) + 7200;
|
const resetPasswordTokenExpiration = Math.floor(Date.now() / 1000) + 7200;
|
||||||
|
|
||||||
await Db.collections.User!.update(id, { resetPasswordToken, resetPasswordTokenExpiration });
|
await Db.collections.User.update(id, { resetPasswordToken, resetPasswordTokenExpiration });
|
||||||
|
|
||||||
const baseUrl = getInstanceBaseUrl();
|
const baseUrl = getInstanceBaseUrl();
|
||||||
const url = new URL(`${baseUrl}/change-password`);
|
const url = new URL(`${baseUrl}/change-password`);
|
||||||
|
@ -134,7 +134,7 @@ export function passwordResetNamespace(this: N8nApp): void {
|
||||||
// Timestamp is saved in seconds
|
// Timestamp is saved in seconds
|
||||||
const currentTimestamp = Math.floor(Date.now() / 1000);
|
const currentTimestamp = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
const user = await Db.collections.User!.findOne({
|
const user = await Db.collections.User.findOne({
|
||||||
id,
|
id,
|
||||||
resetPasswordToken,
|
resetPasswordToken,
|
||||||
resetPasswordTokenExpiration: MoreThanOrEqual(currentTimestamp),
|
resetPasswordTokenExpiration: MoreThanOrEqual(currentTimestamp),
|
||||||
|
@ -187,7 +187,7 @@ export function passwordResetNamespace(this: N8nApp): void {
|
||||||
// Timestamp is saved in seconds
|
// Timestamp is saved in seconds
|
||||||
const currentTimestamp = Math.floor(Date.now() / 1000);
|
const currentTimestamp = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
const user = await Db.collections.User!.findOne({
|
const user = await Db.collections.User.findOne({
|
||||||
id: userId,
|
id: userId,
|
||||||
resetPasswordToken,
|
resetPasswordToken,
|
||||||
resetPasswordTokenExpiration: MoreThanOrEqual(currentTimestamp),
|
resetPasswordTokenExpiration: MoreThanOrEqual(currentTimestamp),
|
||||||
|
@ -204,7 +204,7 @@ export function passwordResetNamespace(this: N8nApp): void {
|
||||||
throw new ResponseHelper.ResponseError('', undefined, 404);
|
throw new ResponseHelper.ResponseError('', undefined, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Db.collections.User!.update(userId, {
|
await Db.collections.User.update(userId, {
|
||||||
password: await hashPassword(validPassword),
|
password: await hashPassword(validPassword),
|
||||||
resetPasswordToken: null,
|
resetPasswordToken: null,
|
||||||
resetPasswordTokenExpiration: null,
|
resetPasswordTokenExpiration: null,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
/* eslint-disable no-restricted-syntax */
|
/* eslint-disable no-restricted-syntax */
|
||||||
/* eslint-disable import/no-cycle */
|
/* eslint-disable import/no-cycle */
|
||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { In } from 'typeorm';
|
import { In } from 'typeorm';
|
||||||
import validator from 'validator';
|
import validator from 'validator';
|
||||||
|
@ -108,7 +107,7 @@ export function usersNamespace(this: N8nApp): void {
|
||||||
createUsers[invite.email] = null;
|
createUsers[invite.email] = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
const role = await Db.collections.Role!.findOne({ scope: 'global', name: 'member' });
|
const role = await Db.collections.Role.findOne({ scope: 'global', name: 'member' });
|
||||||
|
|
||||||
if (!role) {
|
if (!role) {
|
||||||
Logger.error(
|
Logger.error(
|
||||||
|
@ -122,7 +121,7 @@ export function usersNamespace(this: N8nApp): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove/exclude existing users from creation
|
// remove/exclude existing users from creation
|
||||||
const existingUsers = await Db.collections.User!.find({
|
const existingUsers = await Db.collections.User.find({
|
||||||
where: { email: In(Object.keys(createUsers)) },
|
where: { email: In(Object.keys(createUsers)) },
|
||||||
});
|
});
|
||||||
existingUsers.forEach((user) => {
|
existingUsers.forEach((user) => {
|
||||||
|
@ -190,6 +189,7 @@ export function usersNamespace(this: N8nApp): void {
|
||||||
};
|
};
|
||||||
if (result?.success) {
|
if (result?.success) {
|
||||||
void InternalHooksManager.getInstance().onUserTransactionalEmail({
|
void InternalHooksManager.getInstance().onUserTransactionalEmail({
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
user_id: id!,
|
user_id: id!,
|
||||||
message_type: 'New user invite',
|
message_type: 'New user invite',
|
||||||
});
|
});
|
||||||
|
@ -249,7 +249,7 @@ export function usersNamespace(this: N8nApp): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const users = await Db.collections.User!.find({ where: { id: In([inviterId, inviteeId]) } });
|
const users = await Db.collections.User.find({ where: { id: In([inviterId, inviteeId]) } });
|
||||||
|
|
||||||
if (users.length !== 2) {
|
if (users.length !== 2) {
|
||||||
Logger.debug(
|
Logger.debug(
|
||||||
|
@ -317,7 +317,7 @@ export function usersNamespace(this: N8nApp): void {
|
||||||
|
|
||||||
const validPassword = validatePassword(password);
|
const validPassword = validatePassword(password);
|
||||||
|
|
||||||
const users = await Db.collections.User!.find({
|
const users = await Db.collections.User.find({
|
||||||
where: { id: In([inviterId, inviteeId]) },
|
where: { id: In([inviterId, inviteeId]) },
|
||||||
relations: ['globalRole'],
|
relations: ['globalRole'],
|
||||||
});
|
});
|
||||||
|
@ -351,7 +351,7 @@ export function usersNamespace(this: N8nApp): void {
|
||||||
invitee.lastName = lastName;
|
invitee.lastName = lastName;
|
||||||
invitee.password = await hashPassword(validPassword);
|
invitee.password = await hashPassword(validPassword);
|
||||||
|
|
||||||
const updatedUser = await Db.collections.User!.save(invitee);
|
const updatedUser = await Db.collections.User.save(invitee);
|
||||||
|
|
||||||
await issueCookie(res, updatedUser);
|
await issueCookie(res, updatedUser);
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ export function usersNamespace(this: N8nApp): void {
|
||||||
this.app.get(
|
this.app.get(
|
||||||
`/${this.restEndpoint}/users`,
|
`/${this.restEndpoint}/users`,
|
||||||
ResponseHelper.send(async () => {
|
ResponseHelper.send(async () => {
|
||||||
const users = await Db.collections.User!.find({ relations: ['globalRole'] });
|
const users = await Db.collections.User.find({ relations: ['globalRole'] });
|
||||||
|
|
||||||
return users.map((user): PublicUser => sanitizeUser(user, ['personalizationAnswers']));
|
return users.map((user): PublicUser => sanitizeUser(user, ['personalizationAnswers']));
|
||||||
}),
|
}),
|
||||||
|
@ -398,7 +398,7 @@ export function usersNamespace(this: N8nApp): void {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const users = await Db.collections.User!.find({
|
const users = await Db.collections.User.find({
|
||||||
where: { id: In([transferId, idToDelete]) },
|
where: { id: In([transferId, idToDelete]) },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -432,11 +432,11 @@ export function usersNamespace(this: N8nApp): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
const [ownedSharedWorkflows, ownedSharedCredentials] = await Promise.all([
|
const [ownedSharedWorkflows, ownedSharedCredentials] = await Promise.all([
|
||||||
Db.collections.SharedWorkflow!.find({
|
Db.collections.SharedWorkflow.find({
|
||||||
relations: ['workflow'],
|
relations: ['workflow'],
|
||||||
where: { user: userToDelete },
|
where: { user: userToDelete },
|
||||||
}),
|
}),
|
||||||
Db.collections.SharedCredentials!.find({
|
Db.collections.SharedCredentials.find({
|
||||||
relations: ['credentials'],
|
relations: ['credentials'],
|
||||||
where: { user: userToDelete },
|
where: { user: userToDelete },
|
||||||
}),
|
}),
|
||||||
|
@ -494,7 +494,7 @@ export function usersNamespace(this: N8nApp): void {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const reinvitee = await Db.collections.User!.findOne({ id: idToReinvite });
|
const reinvitee = await Db.collections.User.findOne({ id: idToReinvite });
|
||||||
|
|
||||||
if (!reinvitee) {
|
if (!reinvitee) {
|
||||||
Logger.debug(
|
Logger.debug(
|
||||||
|
|
|
@ -71,7 +71,7 @@ export class WaitTrackerClass {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const executions = await Db.collections.Execution!.find(findQuery);
|
const executions = await Db.collections.Execution.find(findQuery);
|
||||||
|
|
||||||
if (executions.length === 0) {
|
if (executions.length === 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -107,7 +107,7 @@ export class WaitTrackerClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also check in database
|
// Also check in database
|
||||||
const execution = await Db.collections.Execution!.findOne(executionId);
|
const execution = await Db.collections.Execution.findOne(executionId);
|
||||||
|
|
||||||
if (execution === undefined || !execution.waitTill) {
|
if (execution === undefined || !execution.waitTill) {
|
||||||
throw new Error(`The execution ID "${executionId}" could not be found.`);
|
throw new Error(`The execution ID "${executionId}" could not be found.`);
|
||||||
|
@ -127,7 +127,7 @@ export class WaitTrackerClass {
|
||||||
fullExecutionData.stoppedAt = new Date();
|
fullExecutionData.stoppedAt = new Date();
|
||||||
fullExecutionData.waitTill = undefined;
|
fullExecutionData.waitTill = undefined;
|
||||||
|
|
||||||
await Db.collections.Execution!.update(
|
await Db.collections.Execution.update(
|
||||||
executionId,
|
executionId,
|
||||||
ResponseHelper.flattenExecutionData(fullExecutionData),
|
ResponseHelper.flattenExecutionData(fullExecutionData),
|
||||||
);
|
);
|
||||||
|
@ -146,7 +146,7 @@ export class WaitTrackerClass {
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// Get the data to execute
|
// Get the data to execute
|
||||||
const fullExecutionDataFlatted = await Db.collections.Execution!.findOne(executionId);
|
const fullExecutionDataFlatted = await Db.collections.Execution.findOne(executionId);
|
||||||
|
|
||||||
if (fullExecutionDataFlatted === undefined) {
|
if (fullExecutionDataFlatted === undefined) {
|
||||||
throw new Error(`The execution with the id "${executionId}" does not exist.`);
|
throw new Error(`The execution with the id "${executionId}" does not exist.`);
|
||||||
|
|
|
@ -33,8 +33,8 @@ export async function WorkflowCredentials(nodes: INode[]): Promise<IWorkflowCred
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!returnCredentials[type][nodeCredentials.id]) {
|
if (!returnCredentials[type][nodeCredentials.id]) {
|
||||||
// eslint-disable-next-line no-await-in-loop, @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line no-await-in-loop
|
||||||
foundCredentials = await Db.collections.Credentials!.findOne({
|
foundCredentials = await Db.collections.Credentials.findOne({
|
||||||
id: nodeCredentials.id,
|
id: nodeCredentials.id,
|
||||||
type,
|
type,
|
||||||
});
|
});
|
||||||
|
|
|
@ -181,9 +181,7 @@ function pruneExecutionData(this: WorkflowHooks): void {
|
||||||
const utcDate = DateUtils.mixedDateToUtcDatetimeString(date);
|
const utcDate = DateUtils.mixedDateToUtcDatetimeString(date);
|
||||||
|
|
||||||
// throttle just on success to allow for self healing on failure
|
// throttle just on success to allow for self healing on failure
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
Db.collections.Execution.delete({ stoppedAt: LessThanOrEqual(utcDate) })
|
||||||
Db.collections
|
|
||||||
.Execution!.delete({ stoppedAt: LessThanOrEqual(utcDate) })
|
|
||||||
.then((data) =>
|
.then((data) =>
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
throttling = false;
|
throttling = false;
|
||||||
|
@ -371,8 +369,7 @@ export function hookFunctionsPreExecute(parentProcessMode?: string): IWorkflowEx
|
||||||
{ executionId: this.executionId, nodeName },
|
{ executionId: this.executionId, nodeName },
|
||||||
);
|
);
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
const execution = await Db.collections.Execution.findOne(this.executionId);
|
||||||
const execution = await Db.collections.Execution!.findOne(this.executionId);
|
|
||||||
|
|
||||||
if (execution === undefined) {
|
if (execution === undefined) {
|
||||||
// Something went badly wrong if this happens.
|
// Something went badly wrong if this happens.
|
||||||
|
@ -418,8 +415,7 @@ export function hookFunctionsPreExecute(parentProcessMode?: string): IWorkflowEx
|
||||||
|
|
||||||
const flattenedExecutionData = ResponseHelper.flattenExecutionData(fullExecutionData);
|
const flattenedExecutionData = ResponseHelper.flattenExecutionData(fullExecutionData);
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
await Db.collections.Execution.update(
|
||||||
await Db.collections.Execution!.update(
|
|
||||||
this.executionId,
|
this.executionId,
|
||||||
flattenedExecutionData as IExecutionFlattedDb,
|
flattenedExecutionData as IExecutionFlattedDb,
|
||||||
);
|
);
|
||||||
|
@ -503,7 +499,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||||
|
|
||||||
if (isManualMode && !saveManualExecutions && !fullRunData.waitTill) {
|
if (isManualMode && !saveManualExecutions && !fullRunData.waitTill) {
|
||||||
// Data is always saved, so we remove from database
|
// Data is always saved, so we remove from database
|
||||||
await Db.collections.Execution!.delete(this.executionId);
|
await Db.collections.Execution.delete(this.executionId);
|
||||||
await BinaryDataManager.getInstance().markDataForDeletionByExecutionId(
|
await BinaryDataManager.getInstance().markDataForDeletionByExecutionId(
|
||||||
this.executionId,
|
this.executionId,
|
||||||
);
|
);
|
||||||
|
@ -539,7 +535,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// Data is always saved, so we remove from database
|
// Data is always saved, so we remove from database
|
||||||
await Db.collections.Execution!.delete(this.executionId);
|
await Db.collections.Execution.delete(this.executionId);
|
||||||
await BinaryDataManager.getInstance().markDataForDeletionByExecutionId(
|
await BinaryDataManager.getInstance().markDataForDeletionByExecutionId(
|
||||||
this.executionId,
|
this.executionId,
|
||||||
);
|
);
|
||||||
|
@ -580,7 +576,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||||
const executionData = ResponseHelper.flattenExecutionData(fullExecutionData);
|
const executionData = ResponseHelper.flattenExecutionData(fullExecutionData);
|
||||||
|
|
||||||
// Save the Execution in DB
|
// Save the Execution in DB
|
||||||
await Db.collections.Execution!.update(
|
await Db.collections.Execution.update(
|
||||||
this.executionId,
|
this.executionId,
|
||||||
executionData as IExecutionFlattedDb,
|
executionData as IExecutionFlattedDb,
|
||||||
);
|
);
|
||||||
|
@ -588,7 +584,7 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
||||||
if (fullRunData.finished === true && this.retryOf !== undefined) {
|
if (fullRunData.finished === true && this.retryOf !== undefined) {
|
||||||
// If the retry was successful save the reference it on the original execution
|
// If the retry was successful save the reference it on the original execution
|
||||||
// await Db.collections.Execution!.save(executionData as IExecutionFlattedDb);
|
// await Db.collections.Execution!.save(executionData as IExecutionFlattedDb);
|
||||||
await Db.collections.Execution!.update(this.retryOf, {
|
await Db.collections.Execution.update(this.retryOf, {
|
||||||
retrySuccessId: this.executionId,
|
retrySuccessId: this.executionId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -693,14 +689,14 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
|
||||||
const executionData = ResponseHelper.flattenExecutionData(fullExecutionData);
|
const executionData = ResponseHelper.flattenExecutionData(fullExecutionData);
|
||||||
|
|
||||||
// Save the Execution in DB
|
// Save the Execution in DB
|
||||||
await Db.collections.Execution!.update(
|
await Db.collections.Execution.update(
|
||||||
this.executionId,
|
this.executionId,
|
||||||
executionData as IExecutionFlattedDb,
|
executionData as IExecutionFlattedDb,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (fullRunData.finished === true && this.retryOf !== undefined) {
|
if (fullRunData.finished === true && this.retryOf !== undefined) {
|
||||||
// If the retry was successful save the reference it on the original execution
|
// If the retry was successful save the reference it on the original execution
|
||||||
await Db.collections.Execution!.update(this.retryOf, {
|
await Db.collections.Execution.update(this.retryOf, {
|
||||||
retrySuccessId: this.executionId,
|
retrySuccessId: this.executionId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -804,7 +800,7 @@ export async function getWorkflowData(
|
||||||
relations = relations.filter((relation) => relation !== 'workflow.tags');
|
relations = relations.filter((relation) => relation !== 'workflow.tags');
|
||||||
}
|
}
|
||||||
|
|
||||||
const shared = await Db.collections.SharedWorkflow!.findOne({
|
const shared = await Db.collections.SharedWorkflow.findOne({
|
||||||
relations,
|
relations,
|
||||||
where: whereClause({
|
where: whereClause({
|
||||||
user,
|
user,
|
||||||
|
@ -959,7 +955,7 @@ export async function executeWorkflow(
|
||||||
|
|
||||||
const executionData = ResponseHelper.flattenExecutionData(fullExecutionData);
|
const executionData = ResponseHelper.flattenExecutionData(fullExecutionData);
|
||||||
|
|
||||||
await Db.collections.Execution!.update(executionId, executionData as IExecutionFlattedDb);
|
await Db.collections.Execution.update(executionId, executionData as IExecutionFlattedDb);
|
||||||
throw {
|
throw {
|
||||||
...error,
|
...error,
|
||||||
stack: error.stack,
|
stack: error.stack,
|
||||||
|
|
|
@ -107,9 +107,9 @@ export async function executeErrorWorkflow(
|
||||||
const user = await getWorkflowOwner(workflowErrorData.workflow.id!);
|
const user = await getWorkflowOwner(workflowErrorData.workflow.id!);
|
||||||
|
|
||||||
if (user.globalRole.name === 'owner') {
|
if (user.globalRole.name === 'owner') {
|
||||||
workflowData = await Db.collections.Workflow!.findOne({ id: Number(workflowId) });
|
workflowData = await Db.collections.Workflow.findOne({ id: Number(workflowId) });
|
||||||
} else {
|
} else {
|
||||||
const sharedWorkflowData = await Db.collections.SharedWorkflow!.findOne({
|
const sharedWorkflowData = await Db.collections.SharedWorkflow.findOne({
|
||||||
where: {
|
where: {
|
||||||
workflow: { id: workflowId },
|
workflow: { id: workflowId },
|
||||||
user,
|
user,
|
||||||
|
@ -121,7 +121,7 @@ export async function executeErrorWorkflow(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
workflowData = await Db.collections.Workflow!.findOne({ id: Number(workflowId) });
|
workflowData = await Db.collections.Workflow.findOne({ id: Number(workflowId) });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (workflowData === undefined) {
|
if (workflowData === undefined) {
|
||||||
|
@ -426,7 +426,7 @@ export async function saveStaticDataById(
|
||||||
workflowId: string | number,
|
workflowId: string | number,
|
||||||
newStaticData: IDataObject,
|
newStaticData: IDataObject,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await Db.collections.Workflow!.update(workflowId, {
|
await Db.collections.Workflow.update(workflowId, {
|
||||||
staticData: newStaticData,
|
staticData: newStaticData,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -440,7 +440,7 @@ export async function saveStaticDataById(
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||||
export async function getStaticDataById(workflowId: string | number) {
|
export async function getStaticDataById(workflowId: string | number) {
|
||||||
const workflowData = await Db.collections.Workflow!.findOne(workflowId, {
|
const workflowData = await Db.collections.Workflow.findOne(workflowId, {
|
||||||
select: ['staticData'],
|
select: ['staticData'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -586,7 +586,7 @@ export function whereClause({
|
||||||
* Get the IDs of the workflows that have been shared with the user.
|
* Get the IDs of the workflows that have been shared with the user.
|
||||||
*/
|
*/
|
||||||
export async function getSharedWorkflowIds(user: User): Promise<number[]> {
|
export async function getSharedWorkflowIds(user: User): Promise<number[]> {
|
||||||
const sharedWorkflows = await Db.collections.SharedWorkflow!.find({
|
const sharedWorkflows = await Db.collections.SharedWorkflow.find({
|
||||||
relations: ['workflow'],
|
relations: ['workflow'],
|
||||||
where: whereClause({
|
where: whereClause({
|
||||||
user,
|
user,
|
||||||
|
|
|
@ -513,7 +513,7 @@ export class WorkflowRunner {
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const executionDb = (await Db.collections.Execution!.findOne(
|
const executionDb = (await Db.collections.Execution.findOne(
|
||||||
executionId,
|
executionId,
|
||||||
)) as IExecutionFlattedDb;
|
)) as IExecutionFlattedDb;
|
||||||
const fullExecutionData = ResponseHelper.unflattenExecutionData(executionDb);
|
const fullExecutionData = ResponseHelper.unflattenExecutionData(executionDb);
|
||||||
|
@ -548,7 +548,7 @@ export class WorkflowRunner {
|
||||||
(workflowDidSucceed && saveDataSuccessExecution === 'none') ||
|
(workflowDidSucceed && saveDataSuccessExecution === 'none') ||
|
||||||
(!workflowDidSucceed && saveDataErrorExecution === 'none')
|
(!workflowDidSucceed && saveDataErrorExecution === 'none')
|
||||||
) {
|
) {
|
||||||
await Db.collections.Execution!.delete(executionId);
|
await Db.collections.Execution.delete(executionId);
|
||||||
await BinaryDataManager.getInstance().markDataForDeletionByExecutionId(executionId);
|
await BinaryDataManager.getInstance().markDataForDeletionByExecutionId(executionId);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line id-denylist
|
// eslint-disable-next-line id-denylist
|
||||||
|
|
|
@ -53,12 +53,12 @@ credentialsController.get(
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (req.user.globalRole.name === 'owner') {
|
if (req.user.globalRole.name === 'owner') {
|
||||||
credentials = await Db.collections.Credentials!.find({
|
credentials = await Db.collections.Credentials.find({
|
||||||
select: ['id', 'name', 'type', 'nodesAccess', 'createdAt', 'updatedAt'],
|
select: ['id', 'name', 'type', 'nodesAccess', 'createdAt', 'updatedAt'],
|
||||||
where: filter,
|
where: filter,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const shared = await Db.collections.SharedCredentials!.find({
|
const shared = await Db.collections.SharedCredentials.find({
|
||||||
where: whereClause({
|
where: whereClause({
|
||||||
user: req.user,
|
user: req.user,
|
||||||
entityType: 'credentials',
|
entityType: 'credentials',
|
||||||
|
@ -67,7 +67,7 @@ credentialsController.get(
|
||||||
|
|
||||||
if (!shared.length) return [];
|
if (!shared.length) return [];
|
||||||
|
|
||||||
credentials = await Db.collections.Credentials!.find({
|
credentials = await Db.collections.Credentials.find({
|
||||||
select: ['id', 'name', 'type', 'nodesAccess', 'createdAt', 'updatedAt'],
|
select: ['id', 'name', 'type', 'nodesAccess', 'createdAt', 'updatedAt'],
|
||||||
where: {
|
where: {
|
||||||
id: In(shared.map(({ credentialId }) => credentialId)),
|
id: In(shared.map(({ credentialId }) => credentialId)),
|
||||||
|
@ -175,7 +175,7 @@ credentialsController.post(
|
||||||
|
|
||||||
await externalHooks.run('credentials.create', [encryptedData]);
|
await externalHooks.run('credentials.create', [encryptedData]);
|
||||||
|
|
||||||
const role = await Db.collections.Role!.findOneOrFail({
|
const role = await Db.collections.Role.findOneOrFail({
|
||||||
name: 'owner',
|
name: 'owner',
|
||||||
scope: 'credential',
|
scope: 'credential',
|
||||||
});
|
});
|
||||||
|
@ -213,7 +213,7 @@ credentialsController.delete(
|
||||||
ResponseHelper.send(async (req: CredentialRequest.Delete) => {
|
ResponseHelper.send(async (req: CredentialRequest.Delete) => {
|
||||||
const { id: credentialId } = req.params;
|
const { id: credentialId } = req.params;
|
||||||
|
|
||||||
const shared = await Db.collections.SharedCredentials!.findOne({
|
const shared = await Db.collections.SharedCredentials.findOne({
|
||||||
relations: ['credentials'],
|
relations: ['credentials'],
|
||||||
where: whereClause({
|
where: whereClause({
|
||||||
user: req.user,
|
user: req.user,
|
||||||
|
@ -236,7 +236,7 @@ credentialsController.delete(
|
||||||
|
|
||||||
await externalHooks.run('credentials.delete', [credentialId]);
|
await externalHooks.run('credentials.delete', [credentialId]);
|
||||||
|
|
||||||
await Db.collections.Credentials!.remove(shared.credentials);
|
await Db.collections.Credentials.remove(shared.credentials);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}),
|
}),
|
||||||
|
@ -255,7 +255,7 @@ credentialsController.patch(
|
||||||
|
|
||||||
await validateEntity(updateData);
|
await validateEntity(updateData);
|
||||||
|
|
||||||
const shared = await Db.collections.SharedCredentials!.findOne({
|
const shared = await Db.collections.SharedCredentials.findOne({
|
||||||
relations: ['credentials'],
|
relations: ['credentials'],
|
||||||
where: whereClause({
|
where: whereClause({
|
||||||
user: req.user,
|
user: req.user,
|
||||||
|
@ -329,11 +329,11 @@ credentialsController.patch(
|
||||||
await externalHooks.run('credentials.update', [newCredentialData]);
|
await externalHooks.run('credentials.update', [newCredentialData]);
|
||||||
|
|
||||||
// Update the credentials in DB
|
// Update the credentials in DB
|
||||||
await Db.collections.Credentials!.update(credentialId, newCredentialData);
|
await Db.collections.Credentials.update(credentialId, newCredentialData);
|
||||||
|
|
||||||
// We sadly get nothing back from "update". Neither if it updated a record
|
// We sadly get nothing back from "update". Neither if it updated a record
|
||||||
// nor the new value. So query now the updated entry.
|
// nor the new value. So query now the updated entry.
|
||||||
const responseData = await Db.collections.Credentials!.findOne(credentialId);
|
const responseData = await Db.collections.Credentials.findOne(credentialId);
|
||||||
|
|
||||||
if (responseData === undefined) {
|
if (responseData === undefined) {
|
||||||
throw new ResponseHelper.ResponseError(
|
throw new ResponseHelper.ResponseError(
|
||||||
|
@ -363,7 +363,7 @@ credentialsController.get(
|
||||||
ResponseHelper.send(async (req: CredentialRequest.Get) => {
|
ResponseHelper.send(async (req: CredentialRequest.Get) => {
|
||||||
const { id: credentialId } = req.params;
|
const { id: credentialId } = req.params;
|
||||||
|
|
||||||
const shared = await Db.collections.SharedCredentials!.findOne({
|
const shared = await Db.collections.SharedCredentials.findOne({
|
||||||
relations: ['credentials'],
|
relations: ['credentials'],
|
||||||
where: whereClause({
|
where: whereClause({
|
||||||
user: req.user,
|
user: req.user,
|
||||||
|
|
Loading…
Reference in a new issue