]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/notifier/shared/instance/direct-registration-for-moderators.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / server / lib / notifier / shared / instance / direct-registration-for-moderators.ts
CommitLineData
d26836cd
C
1import { logger } from '@server/helpers/logger'
2import { CONFIG } from '@server/initializers/config'
3import { UserModel } from '@server/models/user/user'
4import { UserNotificationModel } from '@server/models/user/user-notification'
5import { MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
6import { UserNotificationType, UserRight } from '@shared/models'
7import { AbstractNotification } from '../common/abstract-notification'
8
e364e31e 9export class DirectRegistrationForModerators extends AbstractNotification <MUserDefault> {
d26836cd
C
10 private moderators: MUserDefault[]
11
12 async prepare () {
13 this.moderators = await UserModel.listWithRight(UserRight.MANAGE_USERS)
14 }
15
16 log () {
17 logger.info('Notifying %s moderators of new user registration of %s.', this.moderators.length, this.payload.username)
18 }
19
20 getSetting (user: MUserWithNotificationSetting) {
21 return user.NotificationSetting.newUserRegistration
22 }
23
24 getTargetUsers () {
25 return this.moderators
26 }
27
785f1897
C
28 createNotification (user: MUserWithNotificationSetting) {
29 const notification = UserNotificationModel.build<UserNotificationModelForApi>({
d26836cd
C
30 type: UserNotificationType.NEW_USER_REGISTRATION,
31 userId: user.id,
32 accountId: this.payload.Account.id
33 })
34 notification.Account = this.payload.Account
35
36 return notification
37 }
38
98ab5dc8 39 createEmail (to: string) {
d26836cd
C
40 return {
41 template: 'user-registered',
42 to,
e364e31e 43 subject: `A new user registered on ${CONFIG.INSTANCE.NAME}: ${this.payload.username}`,
d26836cd
C
44 locals: {
45 user: this.payload
46 }
47 }
48 }
49}