1
0
Fork 0
peertube/server/lib/notifier/shared/instance/registration-request-for-moderators.ts

49 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-07-30 10:51:27 -04:00
import { logger } from '@server/helpers/logger'
import { UserModel } from '@server/models/user/user'
import { UserNotificationModel } from '@server/models/user/user-notification'
2023-01-19 03:27:16 -05:00
import { MRegistration, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
2021-07-30 10:51:27 -04:00
import { UserNotificationType, UserRight } from '@shared/models'
import { AbstractNotification } from '../common/abstract-notification'
2023-01-19 03:27:16 -05:00
export class RegistrationRequestForModerators extends AbstractNotification <MRegistration> {
2021-07-30 10:51:27 -04:00
private moderators: MUserDefault[]
async prepare () {
2023-01-19 03:27:16 -05:00
this.moderators = await UserModel.listWithRight(UserRight.MANAGE_REGISTRATIONS)
2021-07-30 10:51:27 -04:00
}
log () {
2023-01-19 03:27:16 -05:00
logger.info('Notifying %s moderators of new user registration request of %s.', this.moderators.length, this.payload.username)
2021-07-30 10:51:27 -04:00
}
getSetting (user: MUserWithNotificationSetting) {
return user.NotificationSetting.newUserRegistration
}
getTargetUsers () {
return this.moderators
}
2022-08-03 05:33:43 -04:00
createNotification (user: MUserWithNotificationSetting) {
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
2023-01-19 03:27:16 -05:00
type: UserNotificationType.NEW_USER_REGISTRATION_REQUEST,
2021-07-30 10:51:27 -04:00
userId: user.id,
2023-01-19 03:27:16 -05:00
userRegistrationId: this.payload.id
2021-07-30 10:51:27 -04:00
})
2023-01-19 03:27:16 -05:00
notification.UserRegistration = this.payload
2021-07-30 10:51:27 -04:00
return notification
}
2021-08-25 10:14:11 -04:00
createEmail (to: string) {
2021-07-30 10:51:27 -04:00
return {
2023-01-19 03:27:16 -05:00
template: 'user-registration-request',
2021-07-30 10:51:27 -04:00
to,
2023-01-19 03:27:16 -05:00
subject: `A new user wants to register: ${this.payload.username}`,
2021-07-30 10:51:27 -04:00
locals: {
2023-01-19 03:27:16 -05:00
registration: this.payload
2021-07-30 10:51:27 -04:00
}
}
}
}