diff options
Diffstat (limited to 'server/lib/notifier/shared/instance/registration-for-moderators.ts')
-rw-r--r-- | server/lib/notifier/shared/instance/registration-for-moderators.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/server/lib/notifier/shared/instance/registration-for-moderators.ts b/server/lib/notifier/shared/instance/registration-for-moderators.ts new file mode 100644 index 000000000..4deb5a2cc --- /dev/null +++ b/server/lib/notifier/shared/instance/registration-for-moderators.ts | |||
@@ -0,0 +1,49 @@ | |||
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 | async 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 | } | ||