PeerTube/server/lib/notifier/shared/instance/direct-registration-for-mod...

50 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-07-30 16:51:27 +02:00
import { logger } from '@server/helpers/logger'
import { CONFIG } from '@server/initializers/config'
import { UserModel } from '@server/models/user/user'
import { UserNotificationModel } from '@server/models/user/user-notification'
import { MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
import { UserNotificationType, UserRight } from '@shared/models'
import { AbstractNotification } from '../common/abstract-notification'
2023-01-19 09:27:16 +01:00
export class DirectRegistrationForModerators extends AbstractNotification <MUserDefault> {
2021-07-30 16:51:27 +02:00
private moderators: MUserDefault[]
async prepare () {
this.moderators = await UserModel.listWithRight(UserRight.MANAGE_USERS)
}
log () {
logger.info('Notifying %s moderators of new user registration of %s.', this.moderators.length, this.payload.username)
}
getSetting (user: MUserWithNotificationSetting) {
return user.NotificationSetting.newUserRegistration
}
getTargetUsers () {
return this.moderators
}
2022-08-03 11:33:43 +02:00
createNotification (user: MUserWithNotificationSetting) {
const notification = UserNotificationModel.build<UserNotificationModelForApi>({
2021-07-30 16:51:27 +02:00
type: UserNotificationType.NEW_USER_REGISTRATION,
userId: user.id,
accountId: this.payload.Account.id
})
notification.Account = this.payload.Account
return notification
}
2021-08-25 16:14:11 +02:00
createEmail (to: string) {
2021-07-30 16:51:27 +02:00
return {
template: 'user-registered',
to,
2023-01-19 09:27:16 +01:00
subject: `A new user registered on ${CONFIG.INSTANCE.NAME}: ${this.payload.username}`,
2021-07-30 16:51:27 +02:00
locals: {
user: this.payload
}
}
}
}