From 94edba213ebbfc5462417ccad1e4afb8c8dc6c9b Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Fri, 11 Mar 2022 15:05:53 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A7=20Added=20public=20url=20variable?= =?UTF-8?q?=20for=20emails=20(#2967)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added public url variable for emails * Fixed base url for reset password - the current implementation overrides possibly existing path * Change variable name to editorUrl * Using correct name editorUrl for emails * Changed variable description * Improved base url naming and appending path so it remains consistent * Removed trailing slash from editor base url --- packages/cli/config/index.ts | 6 ++++++ packages/cli/src/Interfaces.ts | 1 + packages/cli/src/Server.ts | 3 ++- packages/cli/src/UserManagement/UserManagementHelper.ts | 3 ++- packages/cli/src/UserManagement/routes/passwordReset.ts | 7 +++---- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/cli/config/index.ts b/packages/cli/config/index.ts index ca0a978d3937e..b6810bf9f6591 100644 --- a/packages/cli/config/index.ts +++ b/packages/cli/config/index.ts @@ -411,6 +411,12 @@ const config = convict({ env: 'N8N_SSL_CERT', doc: 'SSL Cert for HTTPS Protocol', }, + editorBaseUrl: { + format: String, + default: '', + env: 'N8N_EDITOR_BASE_URL', + doc: 'Public URL where the editor is accessible; path will be concatenated to this base. Also used for emails sent from n8n.', + }, security: { excludeEndpoints: { diff --git a/packages/cli/src/Interfaces.ts b/packages/cli/src/Interfaces.ts index 7d151093fac0d..ac8290140c7ef 100644 --- a/packages/cli/src/Interfaces.ts +++ b/packages/cli/src/Interfaces.ts @@ -446,6 +446,7 @@ export interface IN8nUISettings { }; timezone: string; urlBaseWebhook: string; + urlBaseEditor: string; versionCli: string; n8nMetadata?: { [key: string]: string | number | undefined; diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index b393505a66b70..4aed4be015389 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -171,7 +171,7 @@ import { ExecutionEntity } from './databases/entities/ExecutionEntity'; import { SharedWorkflow } from './databases/entities/SharedWorkflow'; import { AUTH_COOKIE_NAME, RESPONSE_ERROR_MESSAGES } from './constants'; import { credentialsController } from './api/credentials.api'; -import { isEmailSetUp } from './UserManagement/UserManagementHelper'; +import { getInstanceBaseUrl, isEmailSetUp } from './UserManagement/UserManagementHelper'; require('body-parser-xml')(bodyParser); @@ -296,6 +296,7 @@ class App { maxExecutionTimeout: this.maxExecutionTimeout, timezone: this.timezone, urlBaseWebhook, + urlBaseEditor: getInstanceBaseUrl(), versionCli: '', oauthCallbackUrls: { oauth1: `${urlBaseWebhook}${this.restEndpoint}/oauth1-credential/callback`, diff --git a/packages/cli/src/UserManagement/UserManagementHelper.ts b/packages/cli/src/UserManagement/UserManagementHelper.ts index b2a1cae9e9923..e46278f63dd05 100644 --- a/packages/cli/src/UserManagement/UserManagementHelper.ts +++ b/packages/cli/src/UserManagement/UserManagementHelper.ts @@ -55,7 +55,8 @@ export async function getInstanceOwner(): Promise { * Return the n8n instance base URL without trailing slash. */ export function getInstanceBaseUrl(): string { - const baseUrl = GenericHelpers.getBaseUrl(); + const editorBaseUrl = config.get('editorBaseUrl'); + const baseUrl = editorBaseUrl ? editorBaseUrl + config.get('path') : GenericHelpers.getBaseUrl(); return baseUrl.endsWith('/') ? baseUrl.slice(0, baseUrl.length - 1) : baseUrl; } diff --git a/packages/cli/src/UserManagement/routes/passwordReset.ts b/packages/cli/src/UserManagement/routes/passwordReset.ts index 4ac00e2cc234e..574551e142194 100644 --- a/packages/cli/src/UserManagement/routes/passwordReset.ts +++ b/packages/cli/src/UserManagement/routes/passwordReset.ts @@ -11,11 +11,10 @@ import { LoggerProxy as Logger } from 'n8n-workflow'; import { Db, InternalHooksManager, ResponseHelper } from '../..'; import { N8nApp } from '../Interfaces'; -import { validatePassword } from '../UserManagementHelper'; +import { getInstanceBaseUrl, validatePassword } from '../UserManagementHelper'; import * as UserManagementMailer from '../email'; import type { PasswordResetRequest } from '../../requests'; import { issueCookie } from '../auth/jwt'; -import { getBaseUrl } from '../../GenericHelpers'; import config = require('../../../config'); export function passwordResetNamespace(this: N8nApp): void { @@ -73,8 +72,8 @@ export function passwordResetNamespace(this: N8nApp): void { await Db.collections.User!.update(id, { resetPasswordToken, resetPasswordTokenExpiration }); - const baseUrl = getBaseUrl(); - const url = new URL('/change-password', baseUrl); + const baseUrl = getInstanceBaseUrl(); + const url = new URL(`${baseUrl}/change-password`); url.searchParams.append('userId', id); url.searchParams.append('token', resetPasswordToken);