1 import { logger } from '@server/helpers/logger'
2 import { WEBSERVER } from '@server/initializers/constants'
3 import { UserModel } from '@server/models/user/user'
4 import { UserNotificationModel } from '@server/models/user/user-notification'
5 import { MPlugin, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models'
6 import { UserNotificationType, UserRight } from '@shared/models'
7 import { AbstractNotification } from '../common/abstract-notification'
9 export class NewPluginVersionForAdmins extends AbstractNotification <MPlugin> {
10 private admins: MUserDefault[]
13 // Use the debug right to know who is an administrator
14 this.admins = await UserModel.listWithRight(UserRight.MANAGE_DEBUG)
18 logger.info('Notifying %s admins of new PeerTube version %s.', this.admins.length, this.payload.latestVersion)
21 getSetting (user: MUserWithNotificationSetting) {
22 return user.NotificationSetting.newPluginVersion
29 async createNotification (user: MUserWithNotificationSetting) {
30 const notification = await UserNotificationModel.create<UserNotificationModelForApi>({
31 type: UserNotificationType.NEW_PLUGIN_VERSION,
33 pluginId: this.plugin.id
35 notification.Plugin = this.plugin
40 createEmail (to: string) {
41 const pluginUrl = WEBSERVER.URL + '/admin/plugins/list-installed?pluginType=' + this.plugin.type
45 template: 'plugin-version-new',
46 subject: `A new plugin/theme version is available: ${this.plugin.name}@${this.plugin.latestVersion}`,
48 pluginName: this.plugin.name,
49 latestVersion: this.plugin.latestVersion,
55 private get plugin () {