diff options
Diffstat (limited to 'server/lib/notifier/shared/blacklist')
4 files changed, 176 insertions, 0 deletions
diff --git a/server/lib/notifier/shared/blacklist/index.ts b/server/lib/notifier/shared/blacklist/index.ts new file mode 100644 index 000000000..2f98d88ae --- /dev/null +++ b/server/lib/notifier/shared/blacklist/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './new-auto-blacklist-for-moderators' | ||
2 | export * from './new-blacklist-for-owner' | ||
3 | export * from './unblacklist-for-owner' | ||
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 | } | ||
diff --git a/server/lib/notifier/shared/blacklist/new-blacklist-for-owner.ts b/server/lib/notifier/shared/blacklist/new-blacklist-for-owner.ts new file mode 100644 index 000000000..45bc30eb2 --- /dev/null +++ b/server/lib/notifier/shared/blacklist/new-blacklist-for-owner.ts | |||
@@ -0,0 +1,58 @@ | |||
1 | import { logger } from '@server/helpers/logger' | ||
2 | import { CONFIG } from '@server/initializers/config' | ||
3 | import { WEBSERVER } from '@server/initializers/constants' | ||
4 | import { UserModel } from '@server/models/user/user' | ||
5 | import { UserNotificationModel } from '@server/models/user/user-notification' | ||
6 | import { MUserDefault, MUserWithNotificationSetting, MVideoBlacklistVideo, UserNotificationModelForApi } from '@server/types/models' | ||
7 | import { UserNotificationType } from '@shared/models' | ||
8 | import { AbstractNotification } from '../common/abstract-notification' | ||
9 | |||
10 | export class NewBlacklistForOwner extends AbstractNotification <MVideoBlacklistVideo> { | ||
11 | private user: MUserDefault | ||
12 | |||
13 | async prepare () { | ||
14 | this.user = await UserModel.loadByVideoId(this.payload.videoId) | ||
15 | } | ||
16 | |||
17 | log () { | ||
18 | logger.info('Notifying user %s that its video %s has been blacklisted.', this.user.username, this.payload.Video.url) | ||
19 | } | ||
20 | |||
21 | getSetting (user: MUserWithNotificationSetting) { | ||
22 | return user.NotificationSetting.blacklistOnMyVideo | ||
23 | } | ||
24 | |||
25 | getTargetUsers () { | ||
26 | if (!this.user) return [] | ||
27 | |||
28 | return [ this.user ] | ||
29 | } | ||
30 | |||
31 | async createNotification (user: MUserWithNotificationSetting) { | ||
32 | const notification = await UserNotificationModel.create<UserNotificationModelForApi>({ | ||
33 | type: UserNotificationType.BLACKLIST_ON_MY_VIDEO, | ||
34 | userId: user.id, | ||
35 | videoBlacklistId: this.payload.id | ||
36 | }) | ||
37 | notification.VideoBlacklist = this.payload | ||
38 | |||
39 | return notification | ||
40 | } | ||
41 | |||
42 | createEmail (to: string) { | ||
43 | const videoName = this.payload.Video.name | ||
44 | const videoUrl = WEBSERVER.URL + this.payload.Video.getWatchStaticPath() | ||
45 | |||
46 | const reasonString = this.payload.reason ? ` for the following reason: ${this.payload.reason}` : '' | ||
47 | const blockedString = `Your video ${videoName} (${videoUrl} on ${CONFIG.INSTANCE.NAME} has been blacklisted${reasonString}.` | ||
48 | |||
49 | return { | ||
50 | to, | ||
51 | subject: `Video ${videoName} blacklisted`, | ||
52 | text: blockedString, | ||
53 | locals: { | ||
54 | title: 'Your video was blacklisted' | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | } | ||
diff --git a/server/lib/notifier/shared/blacklist/unblacklist-for-owner.ts b/server/lib/notifier/shared/blacklist/unblacklist-for-owner.ts new file mode 100644 index 000000000..21f5a1c2d --- /dev/null +++ b/server/lib/notifier/shared/blacklist/unblacklist-for-owner.ts | |||
@@ -0,0 +1,55 @@ | |||
1 | import { logger } from '@server/helpers/logger' | ||
2 | import { CONFIG } from '@server/initializers/config' | ||
3 | import { WEBSERVER } from '@server/initializers/constants' | ||
4 | import { UserModel } from '@server/models/user/user' | ||
5 | import { UserNotificationModel } from '@server/models/user/user-notification' | ||
6 | import { MUserDefault, MUserWithNotificationSetting, MVideoFullLight, UserNotificationModelForApi } from '@server/types/models' | ||
7 | import { UserNotificationType } from '@shared/models' | ||
8 | import { AbstractNotification } from '../common/abstract-notification' | ||
9 | |||
10 | export class UnblacklistForOwner extends AbstractNotification <MVideoFullLight> { | ||
11 | private user: MUserDefault | ||
12 | |||
13 | async prepare () { | ||
14 | this.user = await UserModel.loadByVideoId(this.payload.id) | ||
15 | } | ||
16 | |||
17 | log () { | ||
18 | logger.info('Notifying user %s that its video %s has been unblacklisted.', this.user.username, this.payload.url) | ||
19 | } | ||
20 | |||
21 | getSetting (user: MUserWithNotificationSetting) { | ||
22 | return user.NotificationSetting.blacklistOnMyVideo | ||
23 | } | ||
24 | |||
25 | getTargetUsers () { | ||
26 | if (!this.user) return [] | ||
27 | |||
28 | return [ this.user ] | ||
29 | } | ||
30 | |||
31 | async createNotification (user: MUserWithNotificationSetting) { | ||
32 | const notification = await UserNotificationModel.create<UserNotificationModelForApi>({ | ||
33 | type: UserNotificationType.UNBLACKLIST_ON_MY_VIDEO, | ||
34 | userId: user.id, | ||
35 | videoId: this.payload.id | ||
36 | }) | ||
37 | notification.Video = this.payload | ||
38 | |||
39 | return notification | ||
40 | } | ||
41 | |||
42 | createEmail (to: string) { | ||
43 | const video = this.payload | ||
44 | const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() | ||
45 | |||
46 | return { | ||
47 | to, | ||
48 | subject: `Video ${video.name} unblacklisted`, | ||
49 | text: `Your video "${video.name}" (${videoUrl}) on ${CONFIG.INSTANCE.NAME} has been unblacklisted.`, | ||
50 | locals: { | ||
51 | title: 'Your video was unblacklisted' | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | } | ||