From 594d3e48d8a887bbf48ce4cc594c1c36c9640fb1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 27 Jul 2020 16:26:25 +0200 Subject: Add abuse messages/states notifications --- shared/extra-utils/users/user-notifications.ts | 61 ++++++++++++++++++++++ .../users/user-notification-setting.model.ts | 15 ++++-- shared/models/users/user-notification.model.ts | 8 ++- 3 files changed, 79 insertions(+), 5 deletions(-) (limited to 'shared') 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 @@ import { expect } from 'chai' import { inspect } from 'util' +import { AbuseState } from '@shared/models' import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' import { MockSmtpServer } from '../miscs/email' import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' @@ -464,6 +465,62 @@ async function checkNewVideoAbuseForModerators (base: CheckerBaseParams, videoUU await checkNotification(base, notificationChecker, emailNotificationFinder, type) } +async function checkNewAbuseMessage (base: CheckerBaseParams, abuseId: number, message: string, toEmail: string, type: CheckerType) { + const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE + + function notificationChecker (notification: UserNotification, type: CheckerType) { + if (type === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.abuse.id).to.equal(abuseId) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.type !== notificationType || n.abuse === undefined || n.abuse.id !== abuseId + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + const to = email['to'].filter(t => t.address === toEmail) + + return text.indexOf(message) !== -1 && to.length !== 0 + } + + await checkNotification(base, notificationChecker, emailNotificationFinder, type) +} + +async function checkAbuseStateChange (base: CheckerBaseParams, abuseId: number, state: AbuseState, type: CheckerType) { + const notificationType = UserNotificationType.ABUSE_STATE_CHANGE + + function notificationChecker (notification: UserNotification, type: CheckerType) { + if (type === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.abuse.id).to.equal(abuseId) + expect(notification.abuse.state).to.equal(state) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.abuse === undefined || n.abuse.id !== abuseId + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + + const contains = state === AbuseState.ACCEPTED + ? ' accepted' + : ' rejected' + + return text.indexOf(contains) !== -1 + } + + await checkNotification(base, notificationChecker, emailNotificationFinder, type) +} + async function checkNewCommentAbuseForModerators (base: CheckerBaseParams, videoUUID: string, videoName: string, type: CheckerType) { const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS @@ -579,6 +636,8 @@ function getAllNotificationsSettings () { newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL } as UserNotificationSetting } @@ -676,6 +735,8 @@ export { updateMyNotificationSettings, checkNewVideoAbuseForModerators, checkVideoAutoBlacklistForModerators, + checkNewAbuseMessage, + checkAbuseStateChange, getUserNotifications, markAsReadNotifications, getLastNotification, diff --git a/shared/models/users/user-notification-setting.model.ts b/shared/models/users/user-notification-setting.model.ts index 4e2230a76..c7590fa8a 100644 --- a/shared/models/users/user-notification-setting.model.ts +++ b/shared/models/users/user-notification-setting.model.ts @@ -5,16 +5,23 @@ export enum UserNotificationSettingValue { } export interface UserNotificationSetting { - newVideoFromSubscription: UserNotificationSettingValue - newCommentOnMyVideo: UserNotificationSettingValue abuseAsModerator: UserNotificationSettingValue videoAutoBlacklistAsModerator: UserNotificationSettingValue + newUserRegistration: UserNotificationSettingValue + + newVideoFromSubscription: UserNotificationSettingValue + blacklistOnMyVideo: UserNotificationSettingValue myVideoPublished: UserNotificationSettingValue myVideoImportFinished: UserNotificationSettingValue - newUserRegistration: UserNotificationSettingValue - newFollow: UserNotificationSettingValue + commentMention: UserNotificationSettingValue + newCommentOnMyVideo: UserNotificationSettingValue + + newFollow: UserNotificationSettingValue newInstanceFollower: UserNotificationSettingValue autoInstanceFollowing: UserNotificationSettingValue + + abuseStateChange: UserNotificationSettingValue + abuseNewMessage: UserNotificationSettingValue } diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts index 5f7c33976..e2f2234e4 100644 --- a/shared/models/users/user-notification.model.ts +++ b/shared/models/users/user-notification.model.ts @@ -1,4 +1,5 @@ import { FollowState } from '../actors' +import { AbuseState } from '../moderation' export enum UserNotificationType { NEW_VIDEO_FROM_SUBSCRIPTION = 1, @@ -21,7 +22,11 @@ export enum UserNotificationType { NEW_INSTANCE_FOLLOWER = 13, - AUTO_INSTANCE_FOLLOWING = 14 + AUTO_INSTANCE_FOLLOWING = 14, + + ABUSE_STATE_CHANGE = 15, + + ABUSE_NEW_MESSAGE = 16 } export interface VideoInfo { @@ -66,6 +71,7 @@ export interface UserNotification { abuse?: { id: number + state: AbuseState video?: VideoInfo -- cgit v1.2.3