From c91fabcf2d14afda7dc689c8e2a73edba50c2639 Mon Sep 17 00:00:00 2001
From: Robin Dadswell <19610103+RobinDadswell@users.noreply.github.com>
Date: Sun, 24 Jan 2021 09:21:29 +0000
Subject: [PATCH] New: On Delete Notifications
Closes #2410
---
.../EditNotificationModalContent.js | 30 +++++++++++
.../Notifications/Notification.js | 54 ++++++++++++++-----
.../Store/Actions/Settings/notifications.js | 2 +
.../NotificationBaseFixture.cs | 13 ++++-
.../149_add_on_delete_to_notifications.cs | 16 ++++++
src/NzbDrone.Core/Datastore/TableMapping.cs | 2 +
.../MediaFiles/Events/DeleteCompletedEvent.cs | 9 ++++
.../MediaFiles/MediaFileDeletionService.cs | 6 +++
.../Notifications/Boxcar/Boxcar.cs | 10 ++++
.../CustomScript/CustomScript.cs | 50 +++++++++++++++++
.../Notifications/Discord/Discord.cs | 36 +++++++++++++
.../Notifications/Email/Email.cs | 14 +++++
.../Notifications/EpisodeDeleteMessage.cs | 20 +++++++
.../Notifications/Gotify/Gotify.cs | 10 ++++
.../Notifications/INotification.cs | 4 ++
src/NzbDrone.Core/Notifications/Join/Join.cs | 9 ++++
.../Notifications/NotificationBase.cs | 17 ++++++
.../Notifications/NotificationDefinition.cs | 6 ++-
.../Notifications/NotificationFactory.cs | 14 +++++
.../Notifications/NotificationService.cs | 53 ++++++++++++++++++
.../Notifications/Plex/Server/PlexServer.cs | 13 +++++
.../Notifications/Prowl/Prowl.cs | 10 ++++
.../Notifications/PushBullet/PushBullet.cs | 9 ++++
.../Notifications/Pushover/Pushover.cs | 10 ++++
.../Notifications/SendGrid/SendGrid.cs | 9 ++++
.../Notifications/SeriesDeleteMessage.cs | 28 ++++++++++
.../Notifications/Slack/Slack.cs | 48 +++++++++++++++++
.../Notifications/Synology/SynologyIndexer.cs | 19 +++++++
.../Notifications/Telegram/Telegram.cs | 10 ++++
.../Notifications/Twitter/Twitter.cs | 10 ++++
.../Notifications/Webhook/Webhook.cs | 21 ++++++++
.../Webhook/WebhookEpisodeDeletePayload.cs | 11 ++++
.../Notifications/Webhook/WebhookEventType.cs | 1 +
.../Webhook/WebhookSeriesDeletePayload.cs | 11 ++++
src/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs | 18 +++++++
.../Notifications/NotificationResource.cs | 12 +++++
36 files changed, 601 insertions(+), 14 deletions(-)
create mode 100644 src/NzbDrone.Core/Datastore/Migration/149_add_on_delete_to_notifications.cs
create mode 100644 src/NzbDrone.Core/MediaFiles/Events/DeleteCompletedEvent.cs
create mode 100644 src/NzbDrone.Core/Notifications/EpisodeDeleteMessage.cs
create mode 100644 src/NzbDrone.Core/Notifications/SeriesDeleteMessage.cs
create mode 100644 src/NzbDrone.Core/Notifications/Webhook/WebhookEpisodeDeletePayload.cs
create mode 100644 src/NzbDrone.Core/Notifications/Webhook/WebhookSeriesDeletePayload.cs
diff --git a/frontend/src/Settings/Notifications/Notifications/EditNotificationModalContent.js b/frontend/src/Settings/Notifications/Notifications/EditNotificationModalContent.js
index 4deb2e78c..0b993942a 100644
--- a/frontend/src/Settings/Notifications/Notifications/EditNotificationModalContent.js
+++ b/frontend/src/Settings/Notifications/Notifications/EditNotificationModalContent.js
@@ -42,11 +42,15 @@ function EditNotificationModalContent(props) {
onDownload,
onUpgrade,
onRename,
+ onSeriesDelete,
+ onEpisodeFileDelete,
onHealthIssue,
supportsOnGrab,
supportsOnDownload,
supportsOnUpgrade,
supportsOnRename,
+ supportsOnSeriesDelete,
+ supportsOnEpisodeFileDelete,
supportsOnHealthIssue,
includeHealthWarnings,
tags,
@@ -150,6 +154,32 @@ function EditNotificationModalContent(props) {
/>
+
+ On Series Delete
+
+
+
+
+
+ On Episode File Delete
+
+
+
+
On Health Issue
diff --git a/frontend/src/Settings/Notifications/Notifications/Notification.js b/frontend/src/Settings/Notifications/Notifications/Notification.js
index ecea5b6db..30ec1777c 100644
--- a/frontend/src/Settings/Notifications/Notifications/Notification.js
+++ b/frontend/src/Settings/Notifications/Notifications/Notification.js
@@ -58,11 +58,15 @@ class Notification extends Component {
onDownload,
onUpgrade,
onRename,
+ onSeriesDelete,
+ onEpisodeFileDelete,
onHealthIssue,
supportsOnGrab,
supportsOnDownload,
supportsOnUpgrade,
supportsOnRename,
+ supportsOnSeriesDelete,
+ supportsOnEpisodeFileDelete,
supportsOnHealthIssue
} = this.props;
@@ -77,48 +81,70 @@ class Notification extends Component {
{
- supportsOnGrab && onGrab &&
+ supportsOnGrab && onGrab ?
+ :
+ null
}
{
- supportsOnDownload && onDownload &&
+ supportsOnDownload && onDownload ?
+ :
+ null
}
{
- supportsOnUpgrade && onDownload && onUpgrade &&
+ supportsOnUpgrade && onDownload && onUpgrade ?
+ :
+ null
}
{
- supportsOnRename && onRename &&
+ supportsOnRename && onRename ?
+ :
+ null
}
{
- supportsOnHealthIssue && onHealthIssue &&
+ supportsOnHealthIssue && onHealthIssue ?
+ :
+ null
}
{
- !onGrab && !onDownload && !onRename && !onHealthIssue &&
+ supportsOnSeriesDelete && onSeriesDelete ?
+ :
+ null
+ }
+
+ {
+ supportsOnEpisodeFileDelete && onEpisodeFileDelete ?
+ :
+ null
+ }
+
+ {
+ !onGrab && !onDownload && !onRename && !onHealthIssue && !onSeriesDelete && !onEpisodeFileDelete ?
+ :
+ null
}
i.SupportsOnDownload)
.Ignore(i => i.SupportsOnUpgrade)
.Ignore(i => i.SupportsOnRename)
+ .Ignore(i => i.SupportsOnSeriesDelete)
+ .Ignore(i => i.SupportsOnEpisodeFileDelete)
.Ignore(i => i.SupportsOnHealthIssue);
Mapper.Entity().RegisterDefinition("Metadata")
diff --git a/src/NzbDrone.Core/MediaFiles/Events/DeleteCompletedEvent.cs b/src/NzbDrone.Core/MediaFiles/Events/DeleteCompletedEvent.cs
new file mode 100644
index 000000000..883ac4df9
--- /dev/null
+++ b/src/NzbDrone.Core/MediaFiles/Events/DeleteCompletedEvent.cs
@@ -0,0 +1,9 @@
+using NzbDrone.Common.Messaging;
+
+namespace NzbDrone.Core.MediaFiles.Events
+{
+ public class DeleteCompletedEvent : IEvent
+ {
+
+ }
+}
diff --git a/src/NzbDrone.Core/MediaFiles/MediaFileDeletionService.cs b/src/NzbDrone.Core/MediaFiles/MediaFileDeletionService.cs
index b8c4b7ee0..00fdc8254 100644
--- a/src/NzbDrone.Core/MediaFiles/MediaFileDeletionService.cs
+++ b/src/NzbDrone.Core/MediaFiles/MediaFileDeletionService.cs
@@ -28,6 +28,7 @@ namespace NzbDrone.Core.MediaFiles
private readonly IMediaFileService _mediaFileService;
private readonly ISeriesService _seriesService;
private readonly IConfigService _configService;
+ private readonly IEventAggregator _eventAggregator;
private readonly Logger _logger;
public MediaFileDeletionService(IDiskProvider diskProvider,
@@ -35,6 +36,7 @@ namespace NzbDrone.Core.MediaFiles
IMediaFileService mediaFileService,
ISeriesService seriesService,
IConfigService configService,
+ IEventAggregator eventAggregator,
Logger logger)
{
_diskProvider = diskProvider;
@@ -42,6 +44,7 @@ namespace NzbDrone.Core.MediaFiles
_mediaFileService = mediaFileService;
_seriesService = seriesService;
_configService = configService;
+ _eventAggregator = eventAggregator;
_logger = logger;
}
@@ -81,6 +84,8 @@ namespace NzbDrone.Core.MediaFiles
// Delete the episode file from the database to clean it up even if the file was already deleted
_mediaFileService.Delete(episodeFile, DeleteMediaFileReason.Manual);
+
+ _eventAggregator.PublishEvent(new DeleteCompletedEvent());
}
public void HandleAsync(SeriesDeletedEvent message)
@@ -111,6 +116,7 @@ namespace NzbDrone.Core.MediaFiles
{
_recycleBinProvider.DeleteFolder(message.Series.Path);
}
+ _eventAggregator.PublishEvent(new DeleteCompletedEvent());
}
}
diff --git a/src/NzbDrone.Core/Notifications/Boxcar/Boxcar.cs b/src/NzbDrone.Core/Notifications/Boxcar/Boxcar.cs
index 125534fd2..326bc85af 100644
--- a/src/NzbDrone.Core/Notifications/Boxcar/Boxcar.cs
+++ b/src/NzbDrone.Core/Notifications/Boxcar/Boxcar.cs
@@ -26,6 +26,16 @@ namespace NzbDrone.Core.Notifications.Boxcar
_proxy.SendNotification(EPISODE_DOWNLOADED_TITLE , message.Message, Settings);
}
+ public override void OnEpisodeFileDelete(EpisodeDeleteMessage deleteMessage)
+ {
+ _proxy.SendNotification(EPISODE_DELETED_TITLE, deleteMessage.Message, Settings);
+ }
+
+ public override void OnSeriesDelete(SeriesDeleteMessage deleteMessage)
+ {
+ _proxy.SendNotification(SERIES_DELETED_TITLE, deleteMessage.Message, Settings);
+ }
+
public override void OnHealthIssue(HealthCheck.HealthCheck message)
{
_proxy.SendNotification(HEALTH_ISSUE_TITLE, message.Message, Settings);
diff --git a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs
index 32e3e8b34..7b6aff744 100644
--- a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs
+++ b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs
@@ -127,6 +127,56 @@ namespace NzbDrone.Core.Notifications.CustomScript
ExecuteScript(environmentVariables);
}
+ public override void OnEpisodeFileDelete(EpisodeDeleteMessage deleteMessage)
+ {
+ var series = deleteMessage.Series;
+ var episodeFile = deleteMessage.EpisodeFile;
+
+ var environmentVariables = new StringDictionary();
+
+ environmentVariables.Add("Sonarr_EventType", "EpisodeDeleted");
+ environmentVariables.Add("Sonarr_Series_Id", series.Id.ToString());
+ environmentVariables.Add("Sonarr_Series_Title", series.Title);
+ environmentVariables.Add("Sonarr_Series_Path", series.Path);
+ environmentVariables.Add("Sonarr_Series_TvdbId", series.TvdbId.ToString());
+ environmentVariables.Add("Sonarr_Series_TvMazeId", series.TvMazeId.ToString());
+ environmentVariables.Add("Sonarr_Series_ImdbId", series.ImdbId ?? string.Empty);
+ environmentVariables.Add("Sonarr_Series_Type", series.SeriesType.ToString());
+ environmentVariables.Add("Sonarr_EpisodeFile_Id", episodeFile.Id.ToString());
+ environmentVariables.Add("Sonarr_EpisodeFile_EpisodeCount", episodeFile.Episodes.Value.Count.ToString());
+ environmentVariables.Add("Sonarr_EpisodeFile_RelativePath", episodeFile.RelativePath);
+ environmentVariables.Add("Sonarr_EpisodeFile_Path", Path.Combine(series.Path, episodeFile.RelativePath));
+ environmentVariables.Add("Sonarr_EpisodeFile_EpisodeIds", string.Join(",", episodeFile.Episodes.Value.Select(e => e.Id)));
+ environmentVariables.Add("Sonarr_EpisodeFile_SeasonNumber", episodeFile.SeasonNumber.ToString());
+ environmentVariables.Add("Sonarr_EpisodeFile_EpisodeNumbers", string.Join(",", episodeFile.Episodes.Value.Select(e => e.EpisodeNumber)));
+ environmentVariables.Add("Sonarr_EpisodeFile_EpisodeAirDates", string.Join(",", episodeFile.Episodes.Value.Select(e => e.AirDate)));
+ environmentVariables.Add("Sonarr_EpisodeFile_EpisodeAirDatesUtc", string.Join(",", episodeFile.Episodes.Value.Select(e => e.AirDateUtc)));
+ environmentVariables.Add("Sonarr_EpisodeFile_EpisodeTitles", string.Join("|", episodeFile.Episodes.Value.Select(e => e.Title)));
+ environmentVariables.Add("Sonarr_EpisodeFile_Quality", episodeFile.Quality.Quality.Name);
+ environmentVariables.Add("Sonarr_EpisodeFile_QualityVersion", episodeFile.Quality.Revision.Version.ToString());
+ environmentVariables.Add("Sonarr_EpisodeFile_ReleaseGroup", episodeFile.ReleaseGroup ?? string.Empty);
+ environmentVariables.Add("Sonarr_EpisodeFile_SceneName", episodeFile.SceneName ?? string.Empty);
+
+ }
+
+ public override void OnSeriesDelete(SeriesDeleteMessage deleteMessage)
+ {
+ var series = deleteMessage.Series;
+ var environmentVariables = new StringDictionary();
+
+ environmentVariables.Add("Sonarr_EventType", "SeriesDeleted");
+ environmentVariables.Add("Sonarr_Series_Id", series.Id.ToString());
+ environmentVariables.Add("Sonarr_Series_Title", series.Title);
+ environmentVariables.Add("Sonarr_Series_Path", series.Path);
+ environmentVariables.Add("Sonarr_Series_TvdbId", series.TvdbId.ToString());
+ environmentVariables.Add("Sonarr_Series_TvMazeId", series.TvMazeId.ToString());
+ environmentVariables.Add("Sonarr_Series_ImdbId", series.ImdbId ?? string.Empty);
+ environmentVariables.Add("Sonarr_Series_Type", series.SeriesType.ToString());
+ environmentVariables.Add("Sonarr_Series_DeletedFiles", deleteMessage.DeletedFiles.ToString());
+
+ ExecuteScript(environmentVariables);
+ }
+
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
var environmentVariables = new StringDictionary();
diff --git a/src/NzbDrone.Core/Notifications/Discord/Discord.cs b/src/NzbDrone.Core/Notifications/Discord/Discord.cs
index 5f68d29c9..062103288 100644
--- a/src/NzbDrone.Core/Notifications/Discord/Discord.cs
+++ b/src/NzbDrone.Core/Notifications/Discord/Discord.cs
@@ -235,6 +235,42 @@ namespace NzbDrone.Core.Notifications.Discord
_proxy.SendPayload(payload, Settings);
}
+ public override void OnEpisodeFileDelete(EpisodeDeleteMessage deleteMessage)
+ {
+ var series = deleteMessage.Series;
+ var episodes = deleteMessage.EpisodeFile.Episodes;
+
+ var attachments = new List