From d573926e9b94fb19c8f51c53f71fc853182e1761 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 28 Jul 2020 09:57:16 +0200 Subject: [PATCH 1/1] Add migrations for abuse messages --- ...ount-notification-preferences.component.ts | 4 +- .../core/renderer/html-renderer.service.ts | 21 ++++++-- .../abuse-list-table.component.html | 7 ++- .../abuse-list-table.component.ts | 2 +- .../abuse-message-modal.component.html | 4 +- .../abuse-message-modal.component.scss | 1 + .../abuse-message-modal.component.ts | 24 +++++---- .../users/user-notification.model.ts | 28 +++++++++- .../users/user-notification.service.ts | 5 +- .../users/user-notifications.component.html | 26 +++++++-- .../users/user-notifications.component.ts | 6 ++- scripts/dev/server.sh | 1 + server/initializers/constants.ts | 2 +- .../migrations/0525-abuse-messages.ts | 54 +++++++++++++++++++ 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 ++-- 18 files changed, 189 insertions(+), 43 deletions(-) create mode 100644 server/initializers/migrations/0525-abuse-messages.ts diff --git a/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts b/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts index 8562e564b..89a04c078 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts @@ -42,7 +42,9 @@ export class MyAccountNotificationPreferencesComponent implements OnInit { newFollow: this.i18n('You or your channel(s) has a new follower'), commentMention: this.i18n('Someone mentioned you in video comments'), newInstanceFollower: this.i18n('Your instance has a new follower'), - autoInstanceFollowing: this.i18n('Your instance auto followed another instance') + autoInstanceFollowing: this.i18n('Your instance auto followed another instance'), + abuseNewMessage: this.i18n('An abuse received a new message'), + abuseStateChange: this.i18n('One of your abuse has been accepted or rejected by moderators') } this.notificationSettingKeys = Object.keys(this.labelNotifications) as (keyof UserNotificationSetting)[] diff --git a/client/src/app/core/renderer/html-renderer.service.ts b/client/src/app/core/renderer/html-renderer.service.ts index f0527c759..302d92ed9 100644 --- a/client/src/app/core/renderer/html-renderer.service.ts +++ b/client/src/app/core/renderer/html-renderer.service.ts @@ -3,19 +3,29 @@ import { LinkifierService } from './linkifier.service' @Injectable() export class HtmlRendererService { + private sanitizeHtml: typeof import ('sanitize-html') constructor (private linkifier: LinkifierService) { } + async convertToBr (text: string) { + await this.loadSanitizeHtml() + + const html = text.replace(/\r?\n/g, '
') + + return this.sanitizeHtml(html, { + allowedTags: [ 'br' ] + }) + } + async toSafeHtml (text: string) { - // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function - const sanitizeHtml: typeof import ('sanitize-html') = (await import('sanitize-html') as any).default + await this.loadSanitizeHtml() // Convert possible markdown to html const html = this.linkifier.linkify(text) - return sanitizeHtml(html, { + return this.sanitizeHtml(html, { allowedTags: [ 'a', 'p', 'span', 'br', 'strong', 'em', 'ul', 'ol', 'li' ], allowedSchemes: [ 'http', 'https' ], allowedAttributes: { @@ -37,4 +47,9 @@ export class HtmlRendererService { } }) } + + private async loadSanitizeHtml () { + // FIXME: import('..') returns a struct module, containing a "default" field corresponding to our sanitizeHtml function + this.sanitizeHtml = (await import('sanitize-html') as any).default + } } diff --git a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html index 17b3742d6..d90b93fff 100644 --- a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html +++ b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.html @@ -42,6 +42,7 @@ Created State Messages + Internal note @@ -144,13 +145,11 @@ - {{ abuse.createdAt | date: 'short' }} - @@ -161,6 +160,10 @@ + + {{ abuse.moderationComment }} + + this.isLocalAbuse(abuse) }, { - label: this.i18n('Update note'), + label: this.i18n('Update internal note'), handler: abuse => this.openModerationCommentModal(abuse), isDisplayed: abuse => this.isAdminView() && !!abuse.moderationComment }, diff --git a/client/src/app/shared/shared-abuse-list/abuse-message-modal.component.html b/client/src/app/shared/shared-abuse-list/abuse-message-modal.component.html index cb965b71d..17e9ce4cf 100644 --- a/client/src/app/shared/shared-abuse-list/abuse-message-modal.component.html +++ b/client/src/app/shared/shared-abuse-list/abuse-message-modal.component.html @@ -9,7 +9,7 @@