From d573926e9b94fb19c8f51c53f71fc853182e1761 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 28 Jul 2020 09:57:16 +0200 Subject: Add migrations for abuse messages --- server/lib/emailer.ts | 30 ++++++++++++++++++++------- server/lib/emails/abuse-new-message/html.pug | 4 ++-- server/lib/emails/abuse-state-change/html.pug | 4 ++-- server/lib/notifier.ts | 9 +++++--- 4 files changed, 32 insertions(+), 15 deletions(-) (limited to 'server/lib') diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index 9c49aa2f6..25b0aaedd 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts @@ -11,7 +11,7 @@ import { isTestInstance, root } from '../helpers/core-utils' import { bunyanLogger, logger } from '../helpers/logger' import { CONFIG, isEmailEnabled } from '../initializers/config' import { WEBSERVER } from '../initializers/constants' -import { MAbuseFull, MAbuseMessage, MActorFollowActors, MActorFollowFull, MUser } from '../types/models' +import { MAbuseFull, MAbuseMessage, MAccountDefault, MActorFollowActors, MActorFollowFull, MUser } from '../types/models' import { MCommentOwnerVideo, MVideo, MVideoAccountLight } from '../types/models/video' import { JobQueue } from './job-queue' @@ -362,9 +362,11 @@ class Emailer { ? 'Report #' + abuse.id + ' has been accepted' : 'Report #' + abuse.id + ' has been rejected' + const abuseUrl = WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id + const action = { text, - url: WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id + url: abuseUrl } const emailPayload: EmailPayload = { @@ -374,6 +376,7 @@ class Emailer { locals: { action, abuseId: abuse.id, + abuseUrl, isAccepted: abuse.state === AbuseState.ACCEPTED } } @@ -381,15 +384,24 @@ class Emailer { return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload }) } - addAbuseNewMessageNotification (to: string[], options: { target: 'moderator' | 'reporter', abuse: MAbuseFull, message: MAbuseMessage }) { - const { abuse, target, message } = options + addAbuseNewMessageNotification ( + to: string[], + options: { + target: 'moderator' | 'reporter' + abuse: MAbuseFull + message: MAbuseMessage + accountMessage: MAccountDefault + }) { + const { abuse, target, message, accountMessage } = options + + const text = 'New message on report #' + abuse.id + const abuseUrl = target === 'moderator' + ? WEBSERVER.URL + '/admin/moderation/abuses/list?search=%23' + abuse.id + : WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id - const text = 'New message on abuse #' + abuse.id const action = { text, - url: target === 'moderator' - ? WEBSERVER.URL + '/admin/moderation/abuses/list?search=%23' + abuse.id - : WEBSERVER.URL + '/my-account/abuses?search=%23' + abuse.id + url: abuseUrl } const emailPayload: EmailPayload = { @@ -397,7 +409,9 @@ class Emailer { to, subject: text, locals: { + abuseId: abuse.id, abuseUrl: action.url, + messageAccountName: accountMessage.getDisplayName(), messageText: message.message, action } diff --git a/server/lib/emails/abuse-new-message/html.pug b/server/lib/emails/abuse-new-message/html.pug index a4180aba1..0841775d2 100644 --- a/server/lib/emails/abuse-new-message/html.pug +++ b/server/lib/emails/abuse-new-message/html.pug @@ -2,10 +2,10 @@ extends ../common/greetings include ../common/mixins.pug block title - | New abuse message + | New message on abuse report block content p - | A new message was created on #[a(href=WEBSERVER.URL) abuse ##{abuseId} on #{WEBSERVER.HOST}] + | A new message by #{messageAccountName} was posted on #[a(href=abuseUrl) abuse report ##{abuseId}] on #{WEBSERVER.HOST} blockquote #{messageText} br(style="display: none;") diff --git a/server/lib/emails/abuse-state-change/html.pug b/server/lib/emails/abuse-state-change/html.pug index a94c8521d..ca89a2f05 100644 --- a/server/lib/emails/abuse-state-change/html.pug +++ b/server/lib/emails/abuse-state-change/html.pug @@ -2,8 +2,8 @@ extends ../common/greetings include ../common/mixins.pug block title - | Abuse state changed + | Abuse report state changed block content p - | #[a(href=abuseUrl) Your abuse ##{abuseId} on #{WEBSERVER.HOST}] has been #{isAccepted ? 'accepted' : 'rejected'} + | #[a(href=abuseUrl) Your abuse report ##{abuseId}] on #{WEBSERVER.HOST} has been #{isAccepted ? 'accepted' : 'rejected'} diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts index 5c50fcf01..9c2f16c27 100644 --- a/server/lib/notifier.ts +++ b/server/lib/notifier.ts @@ -24,6 +24,7 @@ import { MCommentOwnerVideo, MVideoAccountLight, MVideoFullLight } from '../type import { isBlockedByServerOrAccount } from './blocklist' import { Emailer } from './emailer' import { PeerTubeSocket } from './peertube-socket' +import { AccountModel } from '@server/models/account/account' class Notifier { @@ -137,7 +138,7 @@ class Notifier { }) } - notifyOnAbuseMessage (abuse: MAbuseFull, message: AbuseMessageModel): void { + notifyOnAbuseMessage (abuse: MAbuseFull, message: MAbuseMessage): void { this.notifyOfNewAbuseMessage(abuse, message) .catch(err => { logger.error('Cannot notify on new abuse %d message.', abuse.id, { err }) @@ -436,6 +437,8 @@ class Notifier { const url = this.getAbuseUrl(abuse) logger.info('Notifying reporter and moderators of new abuse message on %s.', url) + const accountMessage = await AccountModel.load(message.accountId) + function settingGetter (user: MUserWithNotificationSetting) { return user.NotificationSetting.abuseNewMessage } @@ -452,11 +455,11 @@ class Notifier { } function emailSenderReporter (emails: string[]) { - return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'reporter', abuse, message }) + return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'reporter', abuse, message, accountMessage }) } function emailSenderModerators (emails: string[]) { - return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'moderator', abuse, message }) + return Emailer.Instance.addAbuseNewMessageNotification(emails, { target: 'moderator', abuse, message, accountMessage }) } async function buildReporterOptions () { -- cgit v1.2.3