Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

fix(backend:notifications): use configured public URL for email links

johaven5526218bbf40
diff --git a/backend/src/applications/comments/services/comments-manager.service.spec.ts b/backend/src/applications/comments/services/comments-manager.service.spec.ts
index 2c25d854..34959798 100644
--- a/backend/src/applications/comments/services/comments-manager.service.spec.ts
+++ b/backend/src/applications/comments/services/comments-manager.service.spec.ts
@@ -1,8 +1,8 @@
import { HttpException, HttpStatus } from '@nestjs/common'
import { Test, TestingModule } from '@nestjs/testing'
import { Cache } from '../../../infrastructure/cache/cache.service'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import { DB_TOKEN_PROVIDER } from '../../../infrastructure/database/constants'
+import type { FileProps } from '../../files/interfaces/file-props.interface'
import { FilesQueries } from '../../files/services/files-queries.service'
import { dirName, fileName, getProps, isPathExists } from '../../files/utils/files'
import { NotificationsManager } from '../../notifications/services/notifications-manager.service'
@@ -22,7 +22,6 @@ vi.mock('../../files/utils/files', () => ({
describe(CommentsManager.name, () => {
let commentsManager: CommentsManager
- let contextManager: { headerOriginUrl: Mock }
let commentQueries: {
getComments: Mock
createComment: Mock
@@ -68,10 +67,6 @@ describe(CommentsManager.name, () => {
notificationsManager = {
create: vi.fn().mockResolvedValue(undefined)
}
- contextManager = {
- headerOriginUrl: vi.fn().mockReturnValue('https://app.local/path')
- }
-
const module: TestingModule = await Test.createTestingModule({
providers: [
{
@@ -80,7 +75,6 @@ describe(CommentsManager.name, () => {
},
{ provide: Cache, useValue: {} },
{ provide: NotificationsManager, useValue: notificationsManager },
- { provide: ContextManager, useValue: contextManager },
{ provide: CommentsManager, useClass: CommentsManager },
{ provide: CommentsQueries, useValue: commentQueries },
{ provide: FilesQueries, useValue: filesQueries },
@@ -95,7 +89,7 @@ describe(CommentsManager.name, () => {
beforeEach(() => {
vi.clearAllMocks()
vi.mocked(isPathExists).mockResolvedValue(true)
- vi.mocked(getProps).mockResolvedValue({ name: 'file.txt', path: 'folder' })
+ vi.mocked(getProps).mockResolvedValue({ name: 'file.txt', path: 'folder' } as FileProps)
vi.mocked(dirName).mockReturnValue('/space/folder')
vi.mocked(fileName).mockReturnValue('file.txt')
})
@@ -237,7 +231,6 @@ describe(CommentsManager.name, () => {
expect(dirName).toHaveBeenCalledWith(space.url)
expect(data).toMatchObject({
author: user,
- currentUrl: 'https://app.local/path',
content: 'c'
})
})
diff --git a/backend/src/applications/comments/services/comments-manager.service.ts b/backend/src/applications/comments/services/comments-manager.service.ts
index 5520ad07..a715ddfc 100644
--- a/backend/src/applications/comments/services/comments-manager.service.ts
+++ b/backend/src/applications/comments/services/comments-manager.service.ts
@@ -1,5 +1,4 @@
import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import type { FileProps } from '../../files/interfaces/file-props.interface'
import { FilesQueries } from '../../files/services/files-queries.service'
import { dirName, fileName, getProps, isPathExists } from '../../files/utils/files'
@@ -19,7 +18,6 @@ export class CommentsManager {
private readonly logger = new Logger(CommentsManager.name)
constructor(
- private readonly contextManager: ContextManager,
private readonly commentQueries: CommentsQueries,
private readonly filesQueries: FilesQueries,
private readonly notificationsManager: NotificationsManager
@@ -115,7 +113,6 @@ export class CommentsManager {
this.notificationsManager
.create(members, notification, {
author: fromUser,
- currentUrl: this.contextManager.headerOriginUrl(),
content: comment
})
.catch((e: Error) => this.logger.error({ tag: this.notify.name, msg: `${e}` }))
diff --git a/backend/src/applications/files/services/files-manager.service.spec.ts b/backend/src/applications/files/services/files-manager.service.spec.ts
index 7c896dc3..dfc3c107 100644
--- a/backend/src/applications/files/services/files-manager.service.spec.ts
+++ b/backend/src/applications/files/services/files-manager.service.spec.ts
@@ -7,7 +7,6 @@ import { Readable } from 'node:stream'
import { transformAndValidate } from '../../../common/functions'
import * as imageUtils from '../../../common/image'
import { configuration } from '../../../configuration/config.environment'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import { NotificationsManager } from '../../notifications/services/notifications-manager.service'
import { SpacesManager } from '../../spaces/services/spaces-manager.service'
import * as spacesPathUtils from '../../spaces/utils/paths'
@@ -43,7 +42,6 @@ describe(FilesManager.name, () => {
const lookupMock = lookup as Mock
let filesQueries: { moveFiles: Mock; deleteFiles: Mock }
let spacesManager: { spaceEnv: Mock }
- let contextManager: { headerOriginUrl: Mock }
let notificationsManager: { create: Mock }
let filesLockManager: {
create: Mock
@@ -126,9 +124,6 @@ describe(FilesManager.name, () => {
spacesManager = {
spaceEnv: vi.fn().mockResolvedValue(makeSpace())
}
- contextManager = {
- headerOriginUrl: vi.fn().mockReturnValue('https://sync-in.example')
- }
notificationsManager = {
create: vi.fn().mockResolvedValue(undefined)
}
@@ -173,7 +168,6 @@ describe(FilesManager.name, () => {
providers: [
{ provide: FilesQueries, useValue: filesQueries },
{ provide: SpacesManager, useValue: spacesManager },
- { provide: ContextManager, useValue: contextManager },
{ provide: NotificationsManager, useValue: notificationsManager },
{ provide: HttpService, useValue: http },
{ provide: FilesLockManager, useValue: filesLockManager },
@@ -1909,7 +1903,7 @@ describe(FilesManager.name, () => {
expect(notificationsManager.create).toHaveBeenCalledWith(
[42],
expect.objectContaining({ element: 'file.txt', url: 'files/personal' }),
- expect.objectContaining({ author: user, currentUrl: 'https://sync-in.example' })
+ expect.objectContaining({ author: user })
)
})
})
diff --git a/backend/src/applications/files/services/files-manager.service.ts b/backend/src/applications/files/services/files-manager.service.ts
index cee9b1e4..cf3dbce3 100644
--- a/backend/src/applications/files/services/files-manager.service.ts
+++ b/backend/src/applications/files/services/files-manager.service.ts
@@ -6,7 +6,6 @@ import { FastifyAuthenticatedRequest } from '../../../authentication/interfaces/
import { generateThumbnail } from '../../../common/image'
import { SERVER_NAME } from '../../../common/shared'
import { configuration } from '../../../configuration/config.environment'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import { HTTP_METHOD } from '../../applications.constants'
import { NOTIFICATION_APP, NOTIFICATION_APP_EVENT } from '../../notifications/constants/notifications'
import { NotificationContent } from '../../notifications/interfaces/notification-properties.interface'
@@ -86,7 +85,6 @@ export class FilesManager {
private readonly http: HttpService,
private readonly filesQueries: FilesQueries,
private readonly spacesManager: SpacesManager,
- private readonly contextManager: ContextManager,
private readonly notificationsManager: NotificationsManager,
public readonly filesLockManager: FilesLockManager,
private readonly filesTasksTransfer: FilesTasksTransfer
@@ -846,8 +844,7 @@ export class FilesManager {
}
this.notificationsManager
.create([lock.owner.id], notification, {
- author: user,
- currentUrl: this.contextManager.headerOriginUrl()
+ author: user
})
.catch((e: Error) => this.logger.error({ tag: this.unlockRequest.name, msg: `${e}` }))
}
diff --git a/backend/src/applications/notifications/interfaces/notification-properties.interface.ts b/backend/src/applications/notifications/interfaces/notification-properties.interface.ts
index 9194303e..79192f77 100644
--- a/backend/src/applications/notifications/interfaces/notification-properties.interface.ts
+++ b/backend/src/applications/notifications/interfaces/notification-properties.interface.ts
@@ -14,7 +14,6 @@ export interface NotificationContent {
export interface NotificationOptions {
author?: UserModel
- currentUrl?: string
content?: string
action?: ACTION
linkUUID?: string
diff --git a/backend/src/applications/notifications/mails/models.ts b/backend/src/applications/notifications/mails/models.ts
index a838df56..328530a9 100644
--- a/backend/src/applications/notifications/mails/models.ts
+++ b/backend/src/applications/notifications/mails/models.ts
@@ -9,12 +9,16 @@ import { NotificationContent } from '../interfaces/notification-properties.inter
import { defaultFooter, mailAuthor, mailEventOnElement, mailItalicContent, mailTemplate } from './templates'
import { urlFromLink, urlFromSpace, urlFromSpaceFile, urlFromSync } from './urls'
+function mailActionLink(urlText: string, url?: string): string {
+ return `<br>${urlText}&nbsp;${url ? `<a href="${escapeUTF8(url)}">${SERVER_NAME}</a>` : SERVER_NAME}`
+}
+
export function commentMail(
language: i18nLocale,
notification: NotificationContent,
options: {
content: string
- currentUrl: string
+ publicUrl?: string
author: UserModel
}
): [string, string] {
@@ -28,7 +32,8 @@ export function commentMail(
const content = `${mailAuthor(options.author)}${mailEventOnElement(tr.event, notification.element)}${mailItalicContent(options.content)}`
- const footer = `<br>${tr.urlText}&nbsp;<a href="${escapeUTF8(urlFromSpaceFile(options.currentUrl, notification))}">${SERVER_NAME}</a><br>${tr.footer}<br>${tr.defaultFooter}`
+ const notificationUrl = options.publicUrl ? urlFromSpaceFile(options.publicUrl, notification) : undefined
+ const footer = `${mailActionLink(tr.urlText, notificationUrl)}<br>${tr.footer}<br>${tr.defaultFooter}`
return [`${tr.title}: ${capitalizeString(notification.element)}`, mailTemplate(content, footer)]
}
@@ -37,7 +42,7 @@ export function spaceMail(
language: i18nLocale,
notification: NotificationContent,
options: {
- currentUrl: string
+ publicUrl?: string
action: ACTION
}
): [string, string] {
@@ -48,11 +53,11 @@ export function spaceMail(
event: notification.event
})
- const spaceUrl = urlFromSpace(options.currentUrl, options.action === ACTION.ADD ? notification.element : undefined)
+ const spaceUrl = options.publicUrl ? urlFromSpace(options.publicUrl, options.action === ACTION.ADD ? notification.element : undefined) : undefined
const content = `${mailEventOnElement(tr.event, notification.element)}`
- const footer = `<br>${tr.urlText}&nbsp;<a href="${escapeUTF8(spaceUrl)}">${SERVER_NAME}</a><br>${tr.defaultFooter}`
+ const footer = `${mailActionLink(tr.urlText, spaceUrl)}<br>${tr.defaultFooter}`
return [`${tr.title}: ${capitalizeString(notification.element)}`, mailTemplate(content, footer)]
}
@@ -61,7 +66,7 @@ export function spaceRootMail(
language: i18nLocale,
notification: NotificationContent,
options: {
- currentUrl: string
+ publicUrl?: string
author: UserModel
action: ACTION
}
@@ -75,12 +80,15 @@ export function spaceRootMail(
})
const spaceName = fileName(notification.url)
- const spaceRootUrl =
- options.action === ACTION.ADD ? urlFromSpaceFile(options.currentUrl, notification) : urlFromSpace(options.currentUrl, spaceName)
+ const spaceRootUrl = options.publicUrl
+ ? options.action === ACTION.ADD
+ ? urlFromSpaceFile(options.publicUrl, notification)
+ : urlFromSpace(options.publicUrl, spaceName)
+ : undefined
const content = `${mailAuthor(options.author)}${mailEventOnElement(tr.event, notification.element)}&nbsp;${tr.originEvent}&nbsp;<b>${escapeUTF8(spaceName)}</b>`
- const footer = `<br>${tr.urlText}&nbsp;<a href="${escapeUTF8(spaceRootUrl)}">${SERVER_NAME}</a><br>${tr.defaultFooter}`
+ const footer = `${mailActionLink(tr.urlText, spaceRootUrl)}<br>${tr.defaultFooter}`
return [`${tr.title}: ${capitalizeString(spaceName)}`, mailTemplate(content, footer)]
}
@@ -89,7 +97,7 @@ export function shareMail(
language: i18nLocale,
notification: NotificationContent,
options: {
- currentUrl: string
+ publicUrl?: string
author: UserModel
action: ACTION
}
@@ -103,7 +111,8 @@ export function shareMail(
const content = `${options.author ? mailAuthor(options.author) : ''}${mailEventOnElement(tr.event, notification.element)}`
- const footer = `<br>${tr.urlText}&nbsp;<a href="${escapeUTF8(urlFromSpaceFile(options.currentUrl, notification))}">${SERVER_NAME}</a><br>${tr.defaultFooter}`
+ const notificationUrl = options.publicUrl ? urlFromSpaceFile(options.publicUrl, notification) : undefined
+ const footer = `${mailActionLink(tr.urlText, notificationUrl)}<br>${tr.defaultFooter}`
return [`${tr.title}: ${capitalizeString(notification.element)}`, mailTemplate(content, footer)]
}
@@ -112,7 +121,7 @@ export function linkMail(
language: i18nLocale,
notification: NotificationContent,
options: {
- currentUrl: string
+ publicUrl?: string
author: UserModel
action: ACTION
linkUUID: string
@@ -132,7 +141,8 @@ export function linkMail(
content += `<br><br>${tr.passwordText}:&nbsp;<div style="border:1px solid #000; padding:8px; display:inline-block;">${escapeUTF8(options.linkPassword)}</div>`
}
- const footer = `<br>${tr.urlText}&nbsp;<a href="${escapeUTF8(urlFromLink(options.currentUrl, options.linkUUID))}">${SERVER_NAME}</a>`
+ const notificationUrl = options.publicUrl ? urlFromLink(options.publicUrl, options.linkUUID) : undefined
+ const footer = mailActionLink(tr.urlText, notificationUrl)
return [`${tr.title}: ${capitalizeString(notification.element)}`, mailTemplate(content, footer)]
}
@@ -141,7 +151,7 @@ export function syncMail(
language: i18nLocale,
notification: NotificationContent,
options: {
- currentUrl: string
+ publicUrl?: string
action: ACTION
}
): [string, string] {
@@ -152,11 +162,11 @@ export function syncMail(
event: notification.event
})
- const syncUrl = urlFromSync(options.currentUrl)
+ const syncUrl = options.publicUrl ? urlFromSync(options.publicUrl) : undefined
const content = `${mailEventOnElement(tr.event, notification.element)}`
- const footer = `<br>${tr.urlText}&nbsp;<a href="${escapeUTF8(syncUrl)}">${SERVER_NAME}</a><br>${tr.defaultFooter}`
+ const footer = `${mailActionLink(tr.urlText, syncUrl)}<br>${tr.defaultFooter}`
return [`${tr.title}: ${capitalizeString(notification.element)}`, mailTemplate(content, footer)]
}
@@ -198,7 +208,7 @@ export function requestUnlockMail(
language: i18nLocale,
notification: NotificationContent,
options: {
- currentUrl: string
+ publicUrl?: string
author: UserModel
}
): [string, string] {
@@ -212,7 +222,8 @@ export function requestUnlockMail(
const content = `${options.author ? mailAuthor(options.author) : ''}${mailEventOnElement(tr.event, notification.element)}`
- const footer = `<br>${tr.urlText}&nbsp;<a href="${escapeUTF8(urlFromSpaceFile(options.currentUrl, notification))}">${SERVER_NAME}</a><br>${tr.footer}<br>${tr.defaultFooter}`
+ const notificationUrl = options.publicUrl ? urlFromSpaceFile(options.publicUrl, notification) : undefined
+ const footer = `${mailActionLink(tr.urlText, notificationUrl)}<br>${tr.footer}<br>${tr.defaultFooter}`
return [`${tr.title}: ${capitalizeString(notification.element)}`, mailTemplate(content, footer)]
}
diff --git a/backend/src/applications/notifications/mails/templates.spec.ts b/backend/src/applications/notifications/mails/templates.spec.ts
index 919072dd..f00e1f86 100644
--- a/backend/src/applications/notifications/mails/templates.spec.ts
+++ b/backend/src/applications/notifications/mails/templates.spec.ts
@@ -35,7 +35,7 @@ describe('mail templates escaping', () => {
} as any,
{
content: payload,
- currentUrl: 'https://sync-in.test',
+ publicUrl: 'https://sync-in.test',
author: { fullName: payload, avatarBase64: 'avatar', login: 'attacker' } as any
}
)
@@ -45,4 +45,24 @@ describe('mail templates escaping', () => {
expect(html).toContain(`select=file%20${escapedUrlPayload}.txt`)
expect(html).not.toContain('<img src=x onerror=')
})
+
+ it('omits the action link when publicUrl is not configured', () => {
+ const [, html] = commentMail(
+ language,
+ {
+ app: 'comments',
+ event: 'created',
+ element: 'file.txt',
+ url: 'space'
+ } as any,
+ {
+ content: 'content',
+ publicUrl: undefined,
+ author: { fullName: 'Author', login: 'author' } as any
+ }
+ )
+
+ expect(html).not.toContain('<a href=')
+ expect(html).not.toContain('undefined')
+ })
})
diff --git a/backend/src/applications/notifications/services/notifications-manager.service.spec.ts b/backend/src/applications/notifications/services/notifications-manager.service.spec.ts
index 83a659e7..cf918f09 100644
--- a/backend/src/applications/notifications/services/notifications-manager.service.spec.ts
+++ b/backend/src/applications/notifications/services/notifications-manager.service.spec.ts
@@ -24,6 +24,10 @@ vi.mock('../../users/utils/avatar', () => ({
getAvatarBase64: vi.fn()
}))
+vi.mock('../../../configuration/config.environment', () => ({
+ configuration: { server: { publicUrl: 'https://sync-in.example' } }
+}))
+
describe(NotificationsManager.name, () => {
let service: NotificationsManager
@@ -189,7 +193,7 @@ describe(NotificationsManager.name, () => {
{ id: 1, email: 'a@test', language: 'en' },
{ id: 2, email: 'b@test', language: 'fr' }
]
- const options: any = { author: { id: 9, login: 'jdoe' }, content: 'hello', currentUrl: 'https://app.test/path' }
+ const options: any = { author: { id: 9, login: 'jdoe' }, content: 'hello' }
const content = { app: NOTIFICATION_APP.COMMENTS } as any
await service.sendEmailNotification(toUsers as any, content, options)
expect(getAvatarBase64).toHaveBeenCalledWith('jdoe')
@@ -216,23 +220,23 @@ describe(NotificationsManager.name, () => {
name: 'COMMENTS',
app: NOTIFICATION_APP.COMMENTS,
fn: 'commentMail',
- options: { content: 'c', currentUrl: 'u', author: { id: 1, login: 'x' } }
+ options: { content: 'c', author: { id: 1, login: 'x' } }
},
- { name: 'SPACES', app: NOTIFICATION_APP.SPACES, fn: 'spaceMail', options: { currentUrl: 'u', action: 'A' } },
+ { name: 'SPACES', app: NOTIFICATION_APP.SPACES, fn: 'spaceMail', options: { action: 'A' } },
{
name: 'SPACE_ROOTS',
app: NOTIFICATION_APP.SPACE_ROOTS,
fn: 'spaceRootMail',
- options: { currentUrl: 'u', author: { id: 2, login: 'y' }, action: 'B' }
+ options: { author: { id: 2, login: 'y' }, action: 'B' }
},
- { name: 'SHARES', app: NOTIFICATION_APP.SHARES, fn: 'shareMail', options: { currentUrl: 'u', author: { id: 3, login: 'z' }, action: 'C' } },
+ { name: 'SHARES', app: NOTIFICATION_APP.SHARES, fn: 'shareMail', options: { author: { id: 3, login: 'z' }, action: 'C' } },
{
name: 'LINKS',
app: NOTIFICATION_APP.LINKS,
fn: 'linkMail',
- options: { currentUrl: 'u', author: { id: 4, login: 'w' }, linkUUID: 'uuid', action: 'D' }
+ options: { author: { id: 4, login: 'w' }, linkUUID: 'uuid', action: 'D' }
},
- { name: 'SYNC', app: NOTIFICATION_APP.SYNC, fn: 'syncMail', options: { currentUrl: 'u', action: 'E' } }
+ { name: 'SYNC', app: NOTIFICATION_APP.SYNC, fn: 'syncMail', options: { action: 'E' } }
] as const
it.each(cases)('uses $fn for $name', ({ app, fn, options }) => {
@@ -242,6 +246,19 @@ describe(NotificationsManager.name, () => {
`${fn.replace('Mail', '')} html`.replace('spaceRoot', 'spaceRoot')
])
expect((mailModels as any)[fn]).toHaveBeenCalled()
+ expect((mailModels as any)[fn].mock.calls[0][2]).toMatchObject({ publicUrl: 'https://sync-in.example' })
+ })
+
+ it('ignores a URL supplied through notification options', () => {
+ ;(service as any).genMail(
+ 'en',
+ { app: NOTIFICATION_APP.COMMENTS } as any,
+ { content: 'c', currentUrl: 'https://attacker.example', author: { id: 1, login: 'x' } } as any
+ )
+
+ const mailOptions = vi.mocked(mailModels.commentMail).mock.calls[0][2]
+ expect(mailOptions).toMatchObject({ publicUrl: 'https://sync-in.example' })
+ expect(mailOptions).not.toHaveProperty('currentUrl')
})
it('logs error for unhandled app', () => {
diff --git a/backend/src/applications/notifications/services/notifications-manager.service.ts b/backend/src/applications/notifications/services/notifications-manager.service.ts
index 68935c40..8fa375eb 100644
--- a/backend/src/applications/notifications/services/notifications-manager.service.ts
+++ b/backend/src/applications/notifications/services/notifications-manager.service.ts
@@ -1,5 +1,6 @@
import { Injectable, Logger } from '@nestjs/common'
import { i18nLocale } from '../../../common/i18n'
+import { configuration } from '../../../configuration/config.environment'
import { MailProps } from '../../../infrastructure/mailer/interfaces/mail.interface'
import { Mailer } from '../../../infrastructure/mailer/mailer.service'
import { USER_NOTIFICATION } from '../../users/constants/user'
@@ -27,12 +28,17 @@ import { NotificationsQueries } from './notifications-queries.service'
@Injectable()
export class NotificationsManager {
private readonly logger = new Logger(NotificationsManager.name)
+ private readonly publicUrl = configuration.server.publicUrl
constructor(
private readonly mailer: Mailer,
private readonly notificationsQueries: NotificationsQueries,
private readonly webSocketNotifications: WebSocketNotifications
- ) {}
+ ) {
+ if (this.mailer.available && !this.publicUrl) {
+ this.logger.warn('Notification email action links are disabled because server.publicUrl is not configured.')
+ }
+ }
list(user: UserModel, onlyUnread: boolean = false): Promise<NotificationFromUser[]> {
return this.notificationsQueries.list(user.id, onlyUnread)
@@ -104,29 +110,29 @@ export class NotificationsManager {
private genMail(language: i18nLocale, content: NotificationContent, options?: NotificationOptions): [string, string] {
switch (content.app) {
case NOTIFICATION_APP.COMMENTS:
- return commentMail(language, content, { content: options.content, currentUrl: options.currentUrl, author: options.author })
+ return commentMail(language, content, { content: options.content, publicUrl: this.publicUrl, author: options.author })
case NOTIFICATION_APP.SPACES:
- return spaceMail(language, content, { currentUrl: options.currentUrl, action: options.action })
+ return spaceMail(language, content, { publicUrl: this.publicUrl, action: options.action })
case NOTIFICATION_APP.SPACE_ROOTS:
- return spaceRootMail(language, content, { currentUrl: options.currentUrl, author: options.author, action: options.action })
+ return spaceRootMail(language, content, { publicUrl: this.publicUrl, author: options.author, action: options.action })
case NOTIFICATION_APP.SHARES:
- return shareMail(language, content, { currentUrl: options.currentUrl, author: options.author, action: options.action })
+ return shareMail(language, content, { publicUrl: this.publicUrl, author: options.author, action: options.action })
case NOTIFICATION_APP.LINKS:
return linkMail(language, content, {
- currentUrl: options.currentUrl,
+ publicUrl: this.publicUrl,
author: options.author,
linkUUID: options.linkUUID,
linkPassword: options.linkPassword,
action: options.action
})
case NOTIFICATION_APP.SYNC:
- return syncMail(language, content, { currentUrl: options.currentUrl, action: options.action })
+ return syncMail(language, content, { publicUrl: this.publicUrl, action: options.action })
case NOTIFICATION_APP.AUTH_2FA:
return auth2FaMail(language, content)
case NOTIFICATION_APP.AUTH_LOCKED:
return authLockedMail(language, content)
case NOTIFICATION_APP.UNLOCK_REQUEST:
- return requestUnlockMail(language, content, { currentUrl: options.currentUrl, author: options.author })
+ return requestUnlockMail(language, content, { publicUrl: this.publicUrl, author: options.author })
case NOTIFICATION_APP.UPDATE_AVAILABLE:
return serverUpdateAvailableMail(language, content)
default:
diff --git a/backend/src/applications/shares/services/shares-manager.service.spec.ts b/backend/src/applications/shares/services/shares-manager.service.spec.ts
index 10c35663..51503551 100644
--- a/backend/src/applications/shares/services/shares-manager.service.spec.ts
+++ b/backend/src/applications/shares/services/shares-manager.service.spec.ts
@@ -2,7 +2,6 @@ import { HttpException, HttpStatus } from '@nestjs/common'
import { Test, TestingModule } from '@nestjs/testing'
import * as commonFunctions from '../../../common/functions'
import { intersectPermissions } from '../../../common/shared'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import { DB_TOKEN_PROVIDER } from '../../../infrastructure/database/constants'
import { LINK_TYPE } from '../../links/constants/links'
import { LinksQueries } from '../../links/services/links-queries.service'
@@ -56,10 +55,6 @@ describe(SharesManager.name, () => {
let service: SharesManager
// Mocks
- const contextManagerMock = {
- headerOriginUrl: vi.fn()
- }
-
const notificationsManagerMock = {
create: vi.fn().mockResolvedValue(undefined),
sendEmailNotification: vi.fn().mockResolvedValue(undefined)
@@ -114,7 +109,6 @@ describe(SharesManager.name, () => {
provide: FilesQuotaManager,
useValue: { updateStorageQuota: () => vi.fn() }
},
- { provide: ContextManager, useValue: contextManagerMock },
{ provide: NotificationsManager, useValue: notificationsManagerMock },
{ provide: SpacesQueries, useValue: spacesQueriesMock },
{ provide: UsersQueries, useValue: usersQueriesMock },
diff --git a/backend/src/applications/shares/services/shares-manager.service.ts b/backend/src/applications/shares/services/shares-manager.service.ts
index 5adaefb5..7f69e6d7 100644
--- a/backend/src/applications/shares/services/shares-manager.service.ts
+++ b/backend/src/applications/shares/services/shares-manager.service.ts
@@ -11,7 +11,6 @@ import {
} from '../../../common/functions'
import type { Entries } from '../../../common/interfaces'
import { intersectPermissions, InvalidSlugError } from '../../../common/shared'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import type { FileProps } from '../../files/interfaces/file-props.interface'
import { FileError } from '../../files/models/file-error'
import { checkExternalPath, getProps, isPathExists, removeFiles } from '../../files/utils/files'
@@ -55,7 +54,6 @@ export class SharesManager {
private readonly logger = new Logger(SharesManager.name)
constructor(
- private readonly contextManager: ContextManager,
private readonly notificationsManager: NotificationsManager,
private readonly filesQuotaManager: FilesQuotaManager,
private readonly sharesQueries: SharesQueries,
@@ -1172,7 +1170,6 @@ export class SharesManager {
}
this.notificationsManager
.create(memberIds, notification, {
- currentUrl: this.contextManager.headerOriginUrl(),
author: user,
action: action
})
@@ -1204,7 +1201,6 @@ export class SharesManager {
author: user,
linkUUID: link.linkSettings.uuid,
linkPassword: link.linkSettings.password,
- currentUrl: this.contextManager.headerOriginUrl(),
action: action
} satisfies NotificationOptions
)
diff --git a/backend/src/applications/spaces/services/spaces-manager.service.spec.ts b/backend/src/applications/spaces/services/spaces-manager.service.spec.ts
index 79abbc77..cdf89f9d 100644
--- a/backend/src/applications/spaces/services/spaces-manager.service.spec.ts
+++ b/backend/src/applications/spaces/services/spaces-manager.service.spec.ts
@@ -7,7 +7,6 @@ import path from 'node:path'
import { transformAndValidate } from '../../../common/functions'
import { exportConfiguration } from '../../../configuration/config.environment'
import { Cache } from '../../../infrastructure/cache/cache.service'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import { DB_TOKEN_PROVIDER } from '../../../infrastructure/database/constants'
import { FilesConfig } from '../../files/files.config'
import { FileError } from '../../files/models/file-error'
@@ -48,7 +47,6 @@ describe(SpacesManager.name, () => {
provide: Cache,
useValue: { get: () => null }
},
- { provide: ContextManager, useValue: {} },
{
provide: NotificationsManager,
useValue: {}
diff --git a/backend/src/applications/spaces/services/spaces-manager.service.ts b/backend/src/applications/spaces/services/spaces-manager.service.ts
index d6630f0d..fa734b9f 100644
--- a/backend/src/applications/spaces/services/spaces-manager.service.ts
+++ b/backend/src/applications/spaces/services/spaces-manager.service.ts
@@ -7,7 +7,6 @@ import { convertDiffUpdate, diffCollection, differencePermissions } from '../../
import type { Entries } from '../../../common/interfaces'
import { createSlug, InvalidSlugError, regExpNumberSuffix } from '../../../common/shared'
import { configuration } from '../../../configuration/config.environment'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import { FileError } from '../../files/models/file-error'
import { dirListFileNames, getProps, isInternalTemporaryEntry, isPathExists, moveFiles, removeFiles } from '../../files/utils/files'
import { LINK_TYPE } from '../../links/constants/links'
@@ -54,7 +53,6 @@ export class SpacesManager {
private readonly logger = new Logger(SpacesManager.name)
constructor(
- private readonly contextManager: ContextManager,
private readonly spacesQueries: SpacesQueries,
private readonly usersQueries: UsersQueries,
private readonly sharesManager: SharesManager,
@@ -861,7 +859,6 @@ export class SpacesManager {
}
this.notificationsManager
.create(memberIds, notification, {
- currentUrl: this.contextManager.headerOriginUrl(),
action: action
})
.catch((e: Error) => this.logger.error({ tag: this.clearCachePermissionsAndOrNotify.name, msg: `${e}` }))
@@ -897,7 +894,6 @@ export class SpacesManager {
}
this.notificationsManager
.create(spaceUserIds, notification, {
- currentUrl: this.contextManager.headerOriginUrl(),
author: user,
action: action
})
diff --git a/backend/src/applications/sync/services/sync-paths-manager.service.spec.ts b/backend/src/applications/sync/services/sync-paths-manager.service.spec.ts
index 2a430ffd..4354f960 100644
--- a/backend/src/applications/sync/services/sync-paths-manager.service.spec.ts
+++ b/backend/src/applications/sync/services/sync-paths-manager.service.spec.ts
@@ -1,7 +1,7 @@
import { HttpStatus } from '@nestjs/common'
import { Test, TestingModule } from '@nestjs/testing'
import { currentTimeStamp } from '../../../common/shared'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
+import type { FileProps } from '../../files/interfaces/file-props.interface'
import { FilesQueries } from '../../files/services/files-queries.service'
import { getProps, isPathExists, isPathIsDir } from '../../files/utils/files'
import { NotificationsManager } from '../../notifications/services/notifications-manager.service'
@@ -63,7 +63,6 @@ vi.mock('../../notifications/constants/notifications', async (importOriginal) =>
describe(SyncPathsManager.name, () => {
let service: SyncPathsManager
- let contextManager: { headerOriginUrl: Mock }
let spacesManager: { spaceEnv: Mock }
let usersQueries: Record<string, Mock>
let filesQueries: { getSpaceFileId: Mock; getOrCreateSpaceFile: Mock }
@@ -81,9 +80,7 @@ describe(SyncPathsManager.name, () => {
const userWith = (clientId?: string) => ({ id: 1, clientId })
const flush = () => new Promise((r) => setImmediate(r))
-
beforeEach(async () => {
- contextManager = { headerOriginUrl: vi.fn(() => 'http://origin.local') }
spacesManager = { spaceEnv: vi.fn() }
usersQueries = {}
filesQueries = {
@@ -112,7 +109,6 @@ describe(SyncPathsManager.name, () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
SyncPathsManager,
- { provide: ContextManager, useValue: contextManager },
{ provide: SpacesManager, useValue: spacesManager },
{ provide: UsersQueries, useValue: usersQueries },
{ provide: FilesQueries, useValue: filesQueries },
@@ -589,7 +585,7 @@ describe(SyncPathsManager.name, () => {
describe('getOrCreateFileId (private) branches', () => {
it('should return existing file id without creation', async () => {
- vi.mocked(getProps).mockResolvedValue({ name: 'file' })
+ vi.mocked(getProps).mockResolvedValue({ name: 'file' } as FileProps)
filesQueries.getSpaceFileId.mockResolvedValue(101)
const id = await (service as any).getOrCreateFileId({
realPath: '/rp',
@@ -600,7 +596,7 @@ describe(SyncPathsManager.name, () => {
})
it('should create file when not exists and return its id', async () => {
- vi.mocked(getProps).mockResolvedValue({ id: 999, name: 'file' })
+ vi.mocked(getProps).mockResolvedValue({ id: 999, name: 'file' } as FileProps)
filesQueries.getSpaceFileId.mockResolvedValue(0)
filesQueries.getOrCreateSpaceFile.mockResolvedValue(202)
const id = await (service as any).getOrCreateFileId({
diff --git a/backend/src/applications/sync/services/sync-paths-manager.service.ts b/backend/src/applications/sync/services/sync-paths-manager.service.ts
index 4a68b0f7..bdaea9bf 100644
--- a/backend/src/applications/sync/services/sync-paths-manager.service.ts
+++ b/backend/src/applications/sync/services/sync-paths-manager.service.ts
@@ -1,7 +1,6 @@
import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'
import { ACTION } from '../../../common/constants'
import { currentTimeStamp } from '../../../common/shared'
-import { ContextManager } from '../../../infrastructure/context/services/context-manager.service'
import { FILE_ERROR } from '../../files/constants/errors'
import type { FileProps } from '../../files/interfaces/file-props.interface'
import { FilesQueries } from '../../files/services/files-queries.service'
@@ -26,7 +25,6 @@ export class SyncPathsManager {
private readonly logger = new Logger(SyncPathsManager.name)
constructor(
- private readonly contextManager: ContextManager,
private readonly spacesManager: SpacesManager,
private readonly filesQueries: FilesQueries,
private readonly syncQueries: SyncQueries,
@@ -236,7 +234,6 @@ export class SyncPathsManager {
}
this.notificationsManager
.create([userId], notification, {
- currentUrl: this.contextManager.headerOriginUrl(),
action: action
})
.catch((e: Error) => this.logger.error({ tag: this.notify.name, msg: `${e}` }))
diff --git a/backend/src/configuration/config.validation.ts b/backend/src/configuration/config.validation.ts
index 4b9ffb60..1281e360 100644
--- a/backend/src/configuration/config.validation.ts
+++ b/backend/src/configuration/config.validation.ts
@@ -9,6 +9,7 @@ import {
IsObject,
IsOptional,
IsString,
+ IsUrl,
Max,
Min,
ValidateNested
@@ -32,6 +33,18 @@ export class ServerConfig {
@Max(65535)
port: number = 8080
+ @Transform(({ value }) => (typeof value === 'string' ? value.trim().replace(/\/+$/, '') || undefined : value))
+ @IsOptional()
+ @IsUrl({
+ protocols: ['http', 'https'],
+ require_protocol: true,
+ require_tld: false,
+ disallow_auth: true,
+ allow_query_components: false,
+ allow_fragments: false
+ })
+ publicUrl?: string
+
@Transform(({ value }) => (value === 0 || value === 'auto' ? cpus().length : Math.max(Number(value), 1)))
@IsInt()
@Min(1)
diff --git a/environment/environment.dist.yaml b/environment/environment.dist.yaml
index 0dbecd5c..4254734f 100644
--- a/environment/environment.dist.yaml
+++ b/environment/environment.dist.yaml
@@ -3,6 +3,12 @@ server:
host: 0.0.0.0
# default port : `8080`
port: 8080
+ # publicUrl: Canonical public URL used to build links in notification emails.
+ # When unset, notification emails are sent without action links.
+ # It will become required in a future major release.
+ # e.g.: https://sync-in.domain.com
+ # optional
+ publicUrl:
# workers: `auto` or `0` (use all cpus) | number of CPUs to use
# default: 1
workers: 1