Add email body for completed exports to file library (#19550)

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
Azri Kahar
2023-08-31 21:08:48 +08:00
committed by GitHub
parent 92c6aaecea
commit 1857340bcd
3 changed files with 30 additions and 3 deletions

View File

@@ -78,6 +78,10 @@ export class ActivityService extends ItemsService {
comment = `> ${comment.replace(/\n+/gm, '\n> ')}`;
const href = new Url(env['PUBLIC_URL'])
.addPath('admin', 'content', data['collection'], data['item'])
.toString();
const message = `
Hello ${userName(user)},
@@ -85,9 +89,7 @@ ${userName(sender)} has mentioned you in a comment:
${comment}
<a href="${new Url(env['PUBLIC_URL'])
.addPath('admin', 'content', data['collection'], data['item'])
.toString()}">Click here to view.</a>
<a href="${href}">Click here to view.</a>
`;
await this.notificationsService.createOne({

View File

@@ -26,9 +26,12 @@ import {
import logger from '../logger.js';
import type { AbstractServiceOptions, ActionEventParams, File } from '../types/index.js';
import { getDateFormatted } from '../utils/get-date-formatted.js';
import { userName } from '../utils/user-name.js';
import { FilesService } from './files.js';
import { ItemsService } from './items.js';
import { NotificationsService } from './notifications.js';
import { UsersService } from './users.js';
import { Url } from '../utils/url.js';
type ExportFormat = 'csv' | 'json' | 'xml' | 'yaml';
@@ -297,10 +300,27 @@ export class ExportService {
schema: this.schema,
});
const usersService = new UsersService({
schema: this.schema,
});
const user = await usersService.readOne(this.accountability.user, {
fields: ['first_name', 'last_name', 'email'],
});
const href = new Url(env['PUBLIC_URL']).addPath('admin', 'files', savedFile).toString();
const message = `
Hello ${userName(user)},
Your export of ${collection} is ready. <a href="${href}">Click here to view.</a>
`;
await notificationsService.createOne({
recipient: this.accountability.user,
sender: this.accountability.user,
subject: `Your export of ${collection} is ready`,
message,
collection: `directus_files`,
item: savedFile,
});