aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/emailer.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-07-27 16:26:25 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-07-31 11:35:19 +0200
commit594d3e48d8a887bbf48ce4cc594c1c36c9640fb1 (patch)
treebae28fa6215a3a3c6ccd78aea6ea7e75c500a96f /server/lib/emailer.ts
parent94148c9028829b5576a5dcbfba2c7fb9cf6443d3 (diff)
downloadPeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.tar.gz
PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.tar.zst
PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.zip
Add abuse messages/states notifications
Diffstat (limited to 'server/lib/emailer.ts')
-rw-r--r--server/lib/emailer.ts53
1 files changed, 51 insertions, 2 deletions
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index c6ad03328..9c49aa2f6 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -5,13 +5,13 @@ import { join } from 'path'
5import { VideoChannelModel } from '@server/models/video/video-channel' 5import { VideoChannelModel } from '@server/models/video/video-channel'
6import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist' 6import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist'
7import { MVideoImport, MVideoImportVideo } from '@server/types/models/video/video-import' 7import { MVideoImport, MVideoImportVideo } from '@server/types/models/video/video-import'
8import { UserAbuse, EmailPayload } from '@shared/models' 8import { AbuseState, EmailPayload, UserAbuse } from '@shared/models'
9import { SendEmailOptions } from '../../shared/models/server/emailer.model' 9import { SendEmailOptions } from '../../shared/models/server/emailer.model'
10import { isTestInstance, root } from '../helpers/core-utils' 10import { isTestInstance, root } from '../helpers/core-utils'
11import { bunyanLogger, logger } from '../helpers/logger' 11import { bunyanLogger, logger } from '../helpers/logger'
12import { CONFIG, isEmailEnabled } from '../initializers/config' 12import { CONFIG, isEmailEnabled } from '../initializers/config'
13import { WEBSERVER } from '../initializers/constants' 13import { WEBSERVER } from '../initializers/constants'
14import { MAbuseFull, MActorFollowActors, MActorFollowFull, MUser } from '../types/models' 14import { MAbuseFull, MAbuseMessage, MActorFollowActors, MActorFollowFull, MUser } from '../types/models'
15import { MCommentOwnerVideo, MVideo, MVideoAccountLight } from '../types/models/video' 15import { MCommentOwnerVideo, MVideo, MVideoAccountLight } from '../types/models/video'
16import { JobQueue } from './job-queue' 16import { JobQueue } from './job-queue'
17 17
@@ -357,6 +357,55 @@ class Emailer {
357 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) 357 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
358 } 358 }
359 359
360 addAbuseStateChangeNotification (to: string[], abuse: MAbuseFull) {
361 const text = abuse.state === AbuseState.ACCEPTED
362 ? 'Report #' + abuse.id + ' has been accepted'
363 : 'Report #' + abuse.id + ' has been rejected'
364
365 const action = {
366 text,
367 url: WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id
368 }
369
370 const emailPayload: EmailPayload = {
371 template: 'abuse-state-change',
372 to,
373 subject: text,
374 locals: {
375 action,
376 abuseId: abuse.id,
377 isAccepted: abuse.state === AbuseState.ACCEPTED
378 }
379 }
380
381 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
382 }
383
384 addAbuseNewMessageNotification (to: string[], options: { target: 'moderator' | 'reporter', abuse: MAbuseFull, message: MAbuseMessage }) {
385 const { abuse, target, message } = options
386
387 const text = 'New message on abuse #' + abuse.id
388 const action = {
389 text,
390 url: target === 'moderator'
391 ? WEBSERVER.URL + '/admin/moderation/abuses/list?search=%23' + abuse.id
392 : WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id
393 }
394
395 const emailPayload: EmailPayload = {
396 template: 'abuse-new-message',
397 to,
398 subject: text,
399 locals: {
400 abuseUrl: action.url,
401 messageText: message.message,
402 action
403 }
404 }
405
406 return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
407 }
408
360 async addVideoAutoBlacklistModeratorsNotification (to: string[], videoBlacklist: MVideoBlacklistLightVideo) { 409 async addVideoAutoBlacklistModeratorsNotification (to: string[], videoBlacklist: MVideoBlacklistLightVideo) {
361 const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' 410 const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list'
362 const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() 411 const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath()