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