diff options
Diffstat (limited to 'server/lib/notifier/shared/blacklist/new-auto-blacklist-for-moderators.ts')
-rw-r--r-- | server/lib/notifier/shared/blacklist/new-auto-blacklist-for-moderators.ts | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/server/lib/notifier/shared/blacklist/new-auto-blacklist-for-moderators.ts b/server/lib/notifier/shared/blacklist/new-auto-blacklist-for-moderators.ts new file mode 100644 index 000000000..a92a49a0c --- /dev/null +++ b/server/lib/notifier/shared/blacklist/new-auto-blacklist-for-moderators.ts | |||
@@ -0,0 +1,60 @@ | |||
1 | import { logger } from '@server/helpers/logger' | ||
2 | import { WEBSERVER } from '@server/initializers/constants' | ||
3 | import { UserModel } from '@server/models/user/user' | ||
4 | import { UserNotificationModel } from '@server/models/user/user-notification' | ||
5 | import { VideoChannelModel } from '@server/models/video/video-channel' | ||
6 | import { MUserDefault, MUserWithNotificationSetting, MVideoBlacklistLightVideo, UserNotificationModelForApi } from '@server/types/models' | ||
7 | import { UserNotificationType, UserRight } from '@shared/models' | ||
8 | import { AbstractNotification } from '../common/abstract-notification' | ||
9 | |||
10 | export class NewAutoBlacklistForModerators extends AbstractNotification <MVideoBlacklistLightVideo> { | ||
11 | private moderators: MUserDefault[] | ||
12 | |||
13 | async prepare () { | ||
14 | this.moderators = await UserModel.listWithRight(UserRight.MANAGE_VIDEO_BLACKLIST) | ||
15 | } | ||
16 | |||
17 | log () { | ||
18 | logger.info('Notifying %s moderators of video auto-blacklist %s.', this.moderators.length, this.payload.Video.url) | ||
19 | } | ||
20 | |||
21 | getSetting (user: MUserWithNotificationSetting) { | ||
22 | return user.NotificationSetting.videoAutoBlacklistAsModerator | ||
23 | } | ||
24 | |||
25 | getTargetUsers () { | ||
26 | return this.moderators | ||
27 | } | ||
28 | |||
29 | async createNotification (user: MUserWithNotificationSetting) { | ||
30 | const notification = await UserNotificationModel.create<UserNotificationModelForApi>({ | ||
31 | type: UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS, | ||
32 | userId: user.id, | ||
33 | videoBlacklistId: this.payload.id | ||
34 | }) | ||
35 | notification.VideoBlacklist = this.payload | ||
36 | |||
37 | return notification | ||
38 | } | ||
39 | |||
40 | async createEmail (to: string) { | ||
41 | const videoAutoBlacklistUrl = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' | ||
42 | const videoUrl = WEBSERVER.URL + this.payload.Video.getWatchStaticPath() | ||
43 | const channel = await VideoChannelModel.loadAndPopulateAccount(this.payload.Video.channelId) | ||
44 | |||
45 | return { | ||
46 | template: 'video-auto-blacklist-new', | ||
47 | to, | ||
48 | subject: 'A new video is pending moderation', | ||
49 | locals: { | ||
50 | channel: channel.toFormattedSummaryJSON(), | ||
51 | videoUrl, | ||
52 | videoName: this.payload.Video.name, | ||
53 | action: { | ||
54 | text: 'Review autoblacklist', | ||
55 | url: videoAutoBlacklistUrl | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | } | ||