diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-30 16:51:27 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-02 10:39:51 +0200 |
commit | d26836cd95e981d636006652927773c7943e77ce (patch) | |
tree | 934a4a835bfddbf1c2c7da98d84ebd7623d60d49 /server/lib/notifier/shared/instance/new-peertube-version-for-admins.ts | |
parent | 2bee9db56ade2b3b1bb0efa8716840d87efdb93f (diff) | |
download | PeerTube-d26836cd95e981d636006652927773c7943e77ce.tar.gz PeerTube-d26836cd95e981d636006652927773c7943e77ce.tar.zst PeerTube-d26836cd95e981d636006652927773c7943e77ce.zip |
Refactor notifier
Diffstat (limited to 'server/lib/notifier/shared/instance/new-peertube-version-for-admins.ts')
-rw-r--r-- | server/lib/notifier/shared/instance/new-peertube-version-for-admins.ts | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/server/lib/notifier/shared/instance/new-peertube-version-for-admins.ts b/server/lib/notifier/shared/instance/new-peertube-version-for-admins.ts new file mode 100644 index 000000000..ab5bfb1ac --- /dev/null +++ b/server/lib/notifier/shared/instance/new-peertube-version-for-admins.ts | |||
@@ -0,0 +1,54 @@ | |||
1 | import { logger } from '@server/helpers/logger' | ||
2 | import { UserModel } from '@server/models/user/user' | ||
3 | import { UserNotificationModel } from '@server/models/user/user-notification' | ||
4 | import { MApplication, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models' | ||
5 | import { UserNotificationType, UserRight } from '@shared/models' | ||
6 | import { AbstractNotification } from '../common/abstract-notification' | ||
7 | |||
8 | export type NewPeerTubeVersionForAdminsPayload = { | ||
9 | application: MApplication | ||
10 | latestVersion: string | ||
11 | } | ||
12 | |||
13 | export class NewPeerTubeVersionForAdmins extends AbstractNotification <NewPeerTubeVersionForAdminsPayload> { | ||
14 | private admins: MUserDefault[] | ||
15 | |||
16 | async prepare () { | ||
17 | // Use the debug right to know who is an administrator | ||
18 | this.admins = await UserModel.listWithRight(UserRight.MANAGE_DEBUG) | ||
19 | } | ||
20 | |||
21 | log () { | ||
22 | logger.info('Notifying %s admins of new PeerTube version %s.', this.admins.length, this.payload.latestVersion) | ||
23 | } | ||
24 | |||
25 | getSetting (user: MUserWithNotificationSetting) { | ||
26 | return user.NotificationSetting.newPeerTubeVersion | ||
27 | } | ||
28 | |||
29 | getTargetUsers () { | ||
30 | return this.admins | ||
31 | } | ||
32 | |||
33 | async createNotification (user: MUserWithNotificationSetting) { | ||
34 | const notification = await UserNotificationModel.create<UserNotificationModelForApi>({ | ||
35 | type: UserNotificationType.NEW_PEERTUBE_VERSION, | ||
36 | userId: user.id, | ||
37 | applicationId: this.payload.application.id | ||
38 | }) | ||
39 | notification.Application = this.payload.application | ||
40 | |||
41 | return notification | ||
42 | } | ||
43 | |||
44 | async createEmail (to: string) { | ||
45 | return { | ||
46 | to, | ||
47 | template: 'peertube-version-new', | ||
48 | subject: `A new PeerTube version is available: ${this.payload.latestVersion}`, | ||
49 | locals: { | ||
50 | latestVersion: this.payload.latestVersion | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | } | ||