]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/notifier/shared/instance/new-plugin-version-for-admins.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / server / lib / notifier / shared / instance / new-plugin-version-for-admins.ts
CommitLineData
d26836cd
C
1import { logger } from '@server/helpers/logger'
2import { WEBSERVER } from '@server/initializers/constants'
3import { UserModel } from '@server/models/user/user'
4import { UserNotificationModel } from '@server/models/user/user-notification'
5import { MPlugin, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
6import { UserNotificationType, UserRight } from '@shared/models'
7import { AbstractNotification } from '../common/abstract-notification'
8
9export class NewPluginVersionForAdmins extends AbstractNotification <MPlugin> {
10 private admins: MUserDefault[]
11
12 async prepare () {
13 // Use the debug right to know who is an administrator
14 this.admins = await UserModel.listWithRight(UserRight.MANAGE_DEBUG)
15 }
16
17 log () {
18 logger.info('Notifying %s admins of new PeerTube version %s.', this.admins.length, this.payload.latestVersion)
19 }
20
21 getSetting (user: MUserWithNotificationSetting) {
22 return user.NotificationSetting.newPluginVersion
23 }
24
25 getTargetUsers () {
26 return this.admins
27 }
28
785f1897
C
29 createNotification (user: MUserWithNotificationSetting) {
30 const notification = UserNotificationModel.build<UserNotificationModelForApi>({
d26836cd
C
31 type: UserNotificationType.NEW_PLUGIN_VERSION,
32 userId: user.id,
33 pluginId: this.plugin.id
34 })
35 notification.Plugin = this.plugin
36
37 return notification
38 }
39
98ab5dc8 40 createEmail (to: string) {
d26836cd
C
41 const pluginUrl = WEBSERVER.URL + '/admin/plugins/list-installed?pluginType=' + this.plugin.type
42
43 return {
44 to,
45 template: 'plugin-version-new',
46 subject: `A new plugin/theme version is available: ${this.plugin.name}@${this.plugin.latestVersion}`,
47 locals: {
48 pluginName: this.plugin.name,
49 latestVersion: this.plugin.latestVersion,
50 pluginUrl
51 }
52 }
53 }
54
55 private get plugin () {
56 return this.payload
57 }
58}