fix(notif): include year in notifications (#1439)

* fix(notif): include year in notifications

* fix(lang): fix shared overwritten strings

* fix: check if email agent is actually enabled when generating passwords
This commit is contained in:
TheCatLady
2021-04-18 06:11:56 -04:00
committed by GitHub
parent 3ae7d0098b
commit 4e98f56753
8 changed files with 35 additions and 19 deletions

View File

@@ -142,7 +142,9 @@ export class MediaRequest {
if (this.type === MediaType.MOVIE) { if (this.type === MediaType.MOVIE) {
const movie = await tmdb.getMovie({ movieId: media.tmdbId }); const movie = await tmdb.getMovie({ movieId: media.tmdbId });
notificationManager.sendNotification(Notification.MEDIA_PENDING, { notificationManager.sendNotification(Notification.MEDIA_PENDING, {
subject: movie.title, subject: `${movie.title}${
movie.release_date ? ` (${movie.release_date.slice(0, 4)})` : ''
}`,
message: movie.overview, message: movie.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`, image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`,
media, media,
@@ -153,7 +155,9 @@ export class MediaRequest {
if (this.type === MediaType.TV) { if (this.type === MediaType.TV) {
const tv = await tmdb.getTvShow({ tvId: media.tmdbId }); const tv = await tmdb.getTvShow({ tvId: media.tmdbId });
notificationManager.sendNotification(Notification.MEDIA_PENDING, { notificationManager.sendNotification(Notification.MEDIA_PENDING, {
subject: tv.name, subject: `${tv.name}${
tv.first_air_date ? ` (${tv.first_air_date.slice(0, 4)})` : ''
}`,
message: tv.overview, message: tv.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${tv.poster_path}`, image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${tv.poster_path}`,
media, media,
@@ -210,7 +214,9 @@ export class MediaRequest {
: Notification.MEDIA_APPROVED : Notification.MEDIA_APPROVED
: Notification.MEDIA_DECLINED, : Notification.MEDIA_DECLINED,
{ {
subject: movie.title, subject: `${movie.title}${
movie.release_date ? ` (${movie.release_date.slice(0, 4)})` : ''
}`,
message: movie.overview, message: movie.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`, image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`,
notifyUser: autoApproved ? undefined : this.requestedBy, notifyUser: autoApproved ? undefined : this.requestedBy,
@@ -227,7 +233,9 @@ export class MediaRequest {
: Notification.MEDIA_APPROVED : Notification.MEDIA_APPROVED
: Notification.MEDIA_DECLINED, : Notification.MEDIA_DECLINED,
{ {
subject: tv.name, subject: `${tv.name}${
tv.first_air_date ? ` (${tv.first_air_date.slice(0, 4)})` : ''
}`,
message: tv.overview, message: tv.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${tv.poster_path}`, image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${tv.poster_path}`,
notifyUser: autoApproved ? undefined : this.requestedBy, notifyUser: autoApproved ? undefined : this.requestedBy,
@@ -492,7 +500,9 @@ export class MediaRequest {
); );
notificationManager.sendNotification(Notification.MEDIA_FAILED, { notificationManager.sendNotification(Notification.MEDIA_FAILED, {
subject: movie.title, subject: `${movie.title}${
movie.release_date ? ` (${movie.release_date.slice(0, 4)})` : ''
}`,
message: movie.overview, message: movie.overview,
media, media,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`, image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${movie.poster_path}`,
@@ -700,7 +710,11 @@ export class MediaRequest {
); );
notificationManager.sendNotification(Notification.MEDIA_FAILED, { notificationManager.sendNotification(Notification.MEDIA_FAILED, {
subject: series.name, subject: `${series.name}${
series.first_air_date
? ` (${series.first_air_date.slice(0, 4)})`
: ''
}`,
message: series.overview, message: series.overview,
image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${series.poster_path}`, image: `https://image.tmdb.org/t/p/w600_and_h900_bestv2${series.poster_path}`,
media, media,

View File

@@ -1,5 +1,4 @@
import logger from '../../logger'; import logger from '../../logger';
import { getSettings } from '../settings';
import type { NotificationAgent, NotificationPayload } from './agents/agent'; import type { NotificationAgent, NotificationPayload } from './agents/agent';
export enum Notification { export enum Notification {
@@ -45,13 +44,13 @@ class NotificationManager {
type: Notification, type: Notification,
payload: NotificationPayload payload: NotificationPayload
): void { ): void {
const settings = getSettings().notifications;
logger.info(`Sending notification(s) for ${Notification[type]}`, { logger.info(`Sending notification(s) for ${Notification[type]}`, {
label: 'Notifications', label: 'Notifications',
subject: payload.subject, subject: payload.subject,
}); });
this.activeAgents.forEach((agent) => { this.activeAgents.forEach((agent) => {
if (settings.enabled && agent.shouldSend(type)) { if (agent.shouldSend(type)) {
agent.send(type, payload); agent.send(type, payload);
} }
}); });

View File

@@ -179,7 +179,6 @@ interface NotificationAgents {
} }
interface NotificationSettings { interface NotificationSettings {
enabled: boolean;
agents: NotificationAgents; agents: NotificationAgents;
} }
@@ -234,7 +233,6 @@ class Settings {
initialized: false, initialized: false,
}, },
notifications: { notifications: {
enabled: true,
agents: { agents: {
email: { email: {
enabled: false, enabled: false,

View File

@@ -84,7 +84,10 @@ router.post(
const passedExplicitPassword = body.password && body.password.length > 0; const passedExplicitPassword = body.password && body.password.length > 0;
const avatar = gravatarUrl(body.email, { default: 'mm', size: 200 }); const avatar = gravatarUrl(body.email, { default: 'mm', size: 200 });
if (!passedExplicitPassword && !settings.notifications.agents.email) { if (
!passedExplicitPassword &&
!settings.notifications.agents.email.enabled
) {
throw new Error('Email notifications must be enabled'); throw new Error('Email notifications must be enabled');
} }

View File

@@ -18,7 +18,7 @@ const messages = defineMessages({
webhookUrlPlaceholder: 'Server Settings → Integrations → Webhooks', webhookUrlPlaceholder: 'Server Settings → Integrations → Webhooks',
discordsettingssaved: 'Discord notification settings saved successfully!', discordsettingssaved: 'Discord notification settings saved successfully!',
discordsettingsfailed: 'Discord notification settings failed to save.', discordsettingsfailed: 'Discord notification settings failed to save.',
testsent: 'Discord test notification sent!', discordtestsent: 'Discord test notification sent!',
validationUrl: 'You must provide a valid URL', validationUrl: 'You must provide a valid URL',
}); });
@@ -96,7 +96,7 @@ const NotificationsDiscord: React.FC = () => {
}, },
}); });
addToast(intl.formatMessage(messages.testsent), { addToast(intl.formatMessage(messages.discordtestsent), {
appearance: 'info', appearance: 'info',
autoDismiss: true, autoDismiss: true,
}); });

View File

@@ -24,7 +24,7 @@ const messages = defineMessages({
authPass: 'SMTP Password', authPass: 'SMTP Password',
emailsettingssaved: 'Email notification settings saved successfully!', emailsettingssaved: 'Email notification settings saved successfully!',
emailsettingsfailed: 'Email notification settings failed to save.', emailsettingsfailed: 'Email notification settings failed to save.',
testsent: 'Email test notification sent!', emailtestsent: 'Email test notification sent!',
allowselfsigned: 'Allow Self-Signed Certificates', allowselfsigned: 'Allow Self-Signed Certificates',
ssldisabletip: ssldisabletip:
'SSL should be disabled on standard TLS connections (port 587)', 'SSL should be disabled on standard TLS connections (port 587)',
@@ -188,7 +188,7 @@ const NotificationsEmail: React.FC = () => {
}, },
}); });
addToast(intl.formatMessage(messages.testsent), { addToast(intl.formatMessage(messages.emailtestsent), {
appearance: 'info', appearance: 'info',
autoDismiss: true, autoDismiss: true,
}); });

View File

@@ -22,7 +22,7 @@ const messages = defineMessages({
validationChatIdRequired: 'You must provide a valid chat ID', validationChatIdRequired: 'You must provide a valid chat ID',
telegramsettingssaved: 'Telegram notification settings saved successfully!', telegramsettingssaved: 'Telegram notification settings saved successfully!',
telegramsettingsfailed: 'Telegram notification settings failed to save.', telegramsettingsfailed: 'Telegram notification settings failed to save.',
testsent: 'Telegram test notification sent!', telegramtestsent: 'Telegram test notification sent!',
settinguptelegramDescription: settinguptelegramDescription:
'To configure Telegram notifications, you will need to <CreateBotLink>create a bot</CreateBotLink> and get the bot API key. Additionally, you will need the chat ID for the chat to which you would like to send notifications. You can find this by adding <GetIdBotLink>@get_id_bot</GetIdBotLink> to the chat and issuing the <code>/my_id</code> command.', 'To configure Telegram notifications, you will need to <CreateBotLink>create a bot</CreateBotLink> and get the bot API key. Additionally, you will need the chat ID for the chat to which you would like to send notifications. You can find this by adding <GetIdBotLink>@get_id_bot</GetIdBotLink> to the chat and issuing the <code>/my_id</code> command.',
sendSilently: 'Send Silently', sendSilently: 'Send Silently',
@@ -113,7 +113,7 @@ const NotificationsTelegram: React.FC = () => {
}, },
}); });
addToast(intl.formatMessage(messages.testsent), { addToast(intl.formatMessage(messages.telegramtestsent), {
appearance: 'info', appearance: 'info',
autoDismiss: true, autoDismiss: true,
}); });

View File

@@ -290,11 +290,13 @@
"components.Settings.Notifications.chatId": "Chat ID", "components.Settings.Notifications.chatId": "Chat ID",
"components.Settings.Notifications.discordsettingsfailed": "Discord notification settings failed to save.", "components.Settings.Notifications.discordsettingsfailed": "Discord notification settings failed to save.",
"components.Settings.Notifications.discordsettingssaved": "Discord notification settings saved successfully!", "components.Settings.Notifications.discordsettingssaved": "Discord notification settings saved successfully!",
"components.Settings.Notifications.discordtestsent": "Discord test notification sent!",
"components.Settings.Notifications.emailNotificationTypesAlertDescription": "<strong>Media Requested</strong>, <strong>Media Automatically Approved</strong>, and <strong>Media Failed</strong> email notifications are sent to all users with the <strong>Manage Requests</strong> permission.", "components.Settings.Notifications.emailNotificationTypesAlertDescription": "<strong>Media Requested</strong>, <strong>Media Automatically Approved</strong>, and <strong>Media Failed</strong> email notifications are sent to all users with the <strong>Manage Requests</strong> permission.",
"components.Settings.Notifications.emailNotificationTypesAlertDescriptionPt2": "<strong>Media Approved</strong>, <strong>Media Declined</strong>, and <strong>Media Available</strong> email notifications are sent to the user who submitted the request.", "components.Settings.Notifications.emailNotificationTypesAlertDescriptionPt2": "<strong>Media Approved</strong>, <strong>Media Declined</strong>, and <strong>Media Available</strong> email notifications are sent to the user who submitted the request.",
"components.Settings.Notifications.emailsender": "Sender Address", "components.Settings.Notifications.emailsender": "Sender Address",
"components.Settings.Notifications.emailsettingsfailed": "Email notification settings failed to save.", "components.Settings.Notifications.emailsettingsfailed": "Email notification settings failed to save.",
"components.Settings.Notifications.emailsettingssaved": "Email notification settings saved successfully!", "components.Settings.Notifications.emailsettingssaved": "Email notification settings saved successfully!",
"components.Settings.Notifications.emailtestsent": "Email test notification sent!",
"components.Settings.Notifications.enableSsl": "Enable SSL", "components.Settings.Notifications.enableSsl": "Enable SSL",
"components.Settings.Notifications.pgpPassword": "PGP Password", "components.Settings.Notifications.pgpPassword": "PGP Password",
"components.Settings.Notifications.pgpPasswordTip": "Sign encrypted email messages using <OpenPgpLink>OpenPGP</OpenPgpLink>", "components.Settings.Notifications.pgpPasswordTip": "Sign encrypted email messages using <OpenPgpLink>OpenPGP</OpenPgpLink>",
@@ -309,7 +311,7 @@
"components.Settings.Notifications.ssldisabletip": "SSL should be disabled on standard TLS connections (port 587)", "components.Settings.Notifications.ssldisabletip": "SSL should be disabled on standard TLS connections (port 587)",
"components.Settings.Notifications.telegramsettingsfailed": "Telegram notification settings failed to save.", "components.Settings.Notifications.telegramsettingsfailed": "Telegram notification settings failed to save.",
"components.Settings.Notifications.telegramsettingssaved": "Telegram notification settings saved successfully!", "components.Settings.Notifications.telegramsettingssaved": "Telegram notification settings saved successfully!",
"components.Settings.Notifications.testsent": "Telegram test notification sent!", "components.Settings.Notifications.telegramtestsent": "Telegram test notification sent!",
"components.Settings.Notifications.validationBotAPIRequired": "You must provide a bot authentication token", "components.Settings.Notifications.validationBotAPIRequired": "You must provide a bot authentication token",
"components.Settings.Notifications.validationChatIdRequired": "You must provide a valid chat ID", "components.Settings.Notifications.validationChatIdRequired": "You must provide a valid chat ID",
"components.Settings.Notifications.validationEmail": "You must provide a valid email address", "components.Settings.Notifications.validationEmail": "You must provide a valid email address",