Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added public url variable for emails #2967

Merged
merged 7 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/cli/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export interface IN8nUISettings {
};
timezone: string;
urlBaseWebhook: string;
urlBaseEditor: string;
versionCli: string;
n8nMetadata?: {
[key: string]: string | number | undefined;
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -296,6 +296,7 @@ class App {
maxExecutionTimeout: this.maxExecutionTimeout,
timezone: this.timezone,
urlBaseWebhook,
urlBaseEditor: getInstanceBaseUrl(),
versionCli: '',
oauthCallbackUrls: {
oauth1: `${urlBaseWebhook}${this.restEndpoint}/oauth1-credential/callback`,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/UserManagement/UserManagementHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export async function getInstanceOwner(): Promise<User> {
* Return the n8n instance base URL without trailing slash.
*/
export function getInstanceBaseUrl(): string {
const baseUrl = GenericHelpers.getBaseUrl();
return baseUrl.endsWith('/') ? baseUrl.slice(0, baseUrl.length - 1) : baseUrl;
const editorBaseUrl = config.get('editorBaseUrl');
return editorBaseUrl ? editorBaseUrl + config.get('path') : GenericHelpers.getBaseUrl();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to me getting a string with a trailing slash feels weird

}

export async function isInstanceOwnerSetup(): Promise<boolean> {
Expand Down
7 changes: 3 additions & 4 deletions packages/cli/src/UserManagement/routes/passwordReset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from my gut feeling i would have written the route with a slash prefix ${baseUrl}/change-password

feels weird to omit it

url.searchParams.append('userId', id);
url.searchParams.append('token', resetPasswordToken);

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/UserManagement/routes/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function usersNamespace(this: N8nApp): void {
const emailingResults = await Promise.all(
usersPendingSetup.map(async ([email, id]) => {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
const inviteAcceptUrl = `${baseUrl}/signup?inviterId=${req.user.id}&inviteeId=${id}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref decision on trailing slash

const inviteAcceptUrl = `${baseUrl}signup?inviterId=${req.user.id}&inviteeId=${id}`;
const result = await mailer?.invite({
email,
inviteAcceptUrl,
Expand Down Expand Up @@ -512,7 +512,7 @@ export function usersNamespace(this: N8nApp): void {
}

const baseUrl = getInstanceBaseUrl();
const inviteAcceptUrl = `${baseUrl}/signup?inviterId=${req.user.id}&inviteeId=${reinvitee.id}`;
const inviteAcceptUrl = `${baseUrl}signup?inviterId=${req.user.id}&inviteeId=${reinvitee.id}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref decision on trailing slash


let mailer: UserManagementMailer.UserManagementMailer | undefined;
try {
Expand Down