]>
Commit | Line | Data |
---|---|---|
d26836cd C |
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 | ||
e364e31e | 9 | export 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 | } |