]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/notifier/shared/instance/registration-for-moderators.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / notifier / shared / instance / registration-for-moderators.ts
1 import { logger } from '@server/helpers/logger'
2 import { CONFIG } from '@server/initializers/config'
3 import { UserModel } from '@server/models/user/user'
4 import { UserNotificationModel } from '@server/models/user/user-notification'
5 import { MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
6 import { UserNotificationType, UserRight } from '@shared/models'
7 import { AbstractNotification } from '../common/abstract-notification'
8
9 export class RegistrationForModerators extends AbstractNotification <MUserDefault> {
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
28 async createNotification (user: MUserWithNotificationSetting) {
29 const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
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
39 createEmail (to: string) {
40 return {
41 template: 'user-registered',
42 to,
43 subject: `a new user registered on ${CONFIG.INSTANCE.NAME}: ${this.payload.username}`,
44 locals: {
45 user: this.payload
46 }
47 }
48 }
49 }