diff options
author | Chocobozzz <me@florianbigard.com> | 2020-07-27 16:26:25 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-07-31 11:35:19 +0200 |
commit | 594d3e48d8a887bbf48ce4cc594c1c36c9640fb1 (patch) | |
tree | bae28fa6215a3a3c6ccd78aea6ea7e75c500a96f /shared/extra-utils | |
parent | 94148c9028829b5576a5dcbfba2c7fb9cf6443d3 (diff) | |
download | PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.tar.gz PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.tar.zst PeerTube-594d3e48d8a887bbf48ce4cc594c1c36c9640fb1.zip |
Add abuse messages/states notifications
Diffstat (limited to 'shared/extra-utils')
-rw-r--r-- | shared/extra-utils/users/user-notifications.ts | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts index 2061e3353..98d222e1d 100644 --- a/shared/extra-utils/users/user-notifications.ts +++ b/shared/extra-utils/users/user-notifications.ts | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { inspect } from 'util' | 4 | import { inspect } from 'util' |
5 | import { AbuseState } from '@shared/models' | ||
5 | import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' | 6 | import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' |
6 | import { MockSmtpServer } from '../miscs/email' | 7 | import { MockSmtpServer } from '../miscs/email' |
7 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | 8 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
@@ -464,6 +465,62 @@ async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUU | |||
464 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | 465 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) |
465 | } | 466 | } |
466 | 467 | ||
468 | async function checkNewAbuseMessage (base: CheckerBaseParams, abuseId: number, message: string, toEmail: string, type: CheckerType) { | ||
469 | const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE | ||
470 | |||
471 | function notificationChecker (notification: UserNotification, type: CheckerType) { | ||
472 | if (type === 'presence') { | ||
473 | expect(notification).to.not.be.undefined | ||
474 | expect(notification.type).to.equal(notificationType) | ||
475 | |||
476 | expect(notification.abuse.id).to.equal(abuseId) | ||
477 | } else { | ||
478 | expect(notification).to.satisfy((n: UserNotification) => { | ||
479 | return n === undefined || n.type !== notificationType || n.abuse === undefined || n.abuse.id !== abuseId | ||
480 | }) | ||
481 | } | ||
482 | } | ||
483 | |||
484 | function emailNotificationFinder (email: object) { | ||
485 | const text = email['text'] | ||
486 | const to = email['to'].filter(t => t.address === toEmail) | ||
487 | |||
488 | return text.indexOf(message) !== -1 && to.length !== 0 | ||
489 | } | ||
490 | |||
491 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | ||
492 | } | ||
493 | |||
494 | async function checkAbuseStateChange (base: CheckerBaseParams, abuseId: number, state: AbuseState, type: CheckerType) { | ||
495 | const notificationType = UserNotificationType.ABUSE_STATE_CHANGE | ||
496 | |||
497 | function notificationChecker (notification: UserNotification, type: CheckerType) { | ||
498 | if (type === 'presence') { | ||
499 | expect(notification).to.not.be.undefined | ||
500 | expect(notification.type).to.equal(notificationType) | ||
501 | |||
502 | expect(notification.abuse.id).to.equal(abuseId) | ||
503 | expect(notification.abuse.state).to.equal(state) | ||
504 | } else { | ||
505 | expect(notification).to.satisfy((n: UserNotification) => { | ||
506 | return n === undefined || n.abuse === undefined || n.abuse.id !== abuseId | ||
507 | }) | ||
508 | } | ||
509 | } | ||
510 | |||
511 | function emailNotificationFinder (email: object) { | ||
512 | const text = email['text'] | ||
513 | |||
514 | const contains = state === AbuseState.ACCEPTED | ||
515 | ? ' accepted' | ||
516 | : ' rejected' | ||
517 | |||
518 | return text.indexOf(contains) !== -1 | ||
519 | } | ||
520 | |||
521 | await checkNotification(base, notificationChecker, emailNotificationFinder, type) | ||
522 | } | ||
523 | |||
467 | async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { | 524 | async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { |
468 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS | 525 | const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS |
469 | 526 | ||
@@ -579,6 +636,8 @@ function getAllNotificationsSettings () { | |||
579 | newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 636 | newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
580 | newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 637 | newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
581 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | 638 | newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, |
639 | abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
640 | abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, | ||
582 | autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL | 641 | autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL |
583 | } as UserNotificationSetting | 642 | } as UserNotificationSetting |
584 | } | 643 | } |
@@ -676,6 +735,8 @@ export { | |||
676 | updateMyNotificationSettings, | 735 | updateMyNotificationSettings, |
677 | checkNewVideoAbuseForModerators, | 736 | checkNewVideoAbuseForModerators, |
678 | checkVideoAutoBlacklistForModerators, | 737 | checkVideoAutoBlacklistForModerators, |
738 | checkNewAbuseMessage, | ||
739 | checkAbuseStateChange, | ||
679 | getUserNotifications, | 740 | getUserNotifications, |
680 | markAsReadNotifications, | 741 | markAsReadNotifications, |
681 | getLastNotification, | 742 | getLastNotification, |