Skip to content

Commit

Permalink
New: OnApplicationUpdate Notifications
Browse files Browse the repository at this point in the history
Fixes #1422

(cherry picked from commit 9e175e28efcfc6ac3e414649b955a10fb0e951e7)
  • Loading branch information
Qstick committed Jan 24, 2023
1 parent f5847e9 commit fbdc9f3
Show file tree
Hide file tree
Showing 38 changed files with 320 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Notification extends Component {
onDownloadFailure,
onImportFailure,
onBookRetag,
onApplicationUpdate,
supportsOnGrab,
supportsOnReleaseImport,
supportsOnUpgrade,
Expand All @@ -78,7 +79,8 @@ class Notification extends Component {
supportsOnHealthIssue,
supportsOnDownloadFailure,
supportsOnImportFailure,
supportsOnBookRetag
supportsOnBookRetag,
supportsOnApplicationUpdate
} = this.props;

return (
Expand Down Expand Up @@ -187,6 +189,14 @@ class Notification extends Component {
null
}

{
supportsOnApplicationUpdate && onApplicationUpdate ?
<Label kind={kinds.SUCCESS} >
{translate('OnApplicationUpdate')}
</Label> :
null
}

{
!onGrab && !onReleaseImport && !onRename && !onBookRetag && !onHealthIssue && !onDownloadFailure && !onImportFailure ?
<Label
Expand Down Expand Up @@ -234,6 +244,7 @@ Notification.propTypes = {
onDownloadFailure: PropTypes.bool.isRequired,
onImportFailure: PropTypes.bool.isRequired,
onBookRetag: PropTypes.bool.isRequired,
onApplicationUpdate: PropTypes.bool.isRequired,
supportsOnGrab: PropTypes.bool.isRequired,
supportsOnReleaseImport: PropTypes.bool.isRequired,
supportsOnUpgrade: PropTypes.bool.isRequired,
Expand All @@ -246,6 +257,7 @@ Notification.propTypes = {
supportsOnDownloadFailure: PropTypes.bool.isRequired,
supportsOnImportFailure: PropTypes.bool.isRequired,
supportsOnBookRetag: PropTypes.bool.isRequired,
supportsOnApplicationUpdate: PropTypes.bool.isRequired,
onConfirmDeleteNotification: PropTypes.func.isRequired
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function NotificationEventItems(props) {
onDownloadFailure,
onImportFailure,
onBookRetag,
onApplicationUpdate,
supportsOnGrab,
supportsOnReleaseImport,
supportsOnUpgrade,
Expand All @@ -38,7 +39,8 @@ function NotificationEventItems(props) {
includeHealthWarnings,
supportsOnDownloadFailure,
supportsOnImportFailure,
supportsOnBookRetag
supportsOnBookRetag,
supportsOnApplicationUpdate
} = item;

return (
Expand Down Expand Up @@ -176,6 +178,17 @@ function NotificationEventItems(props) {
/>
</div>

<div>
<FormInputGroup
type={inputTypes.CHECK}
name="onApplicationUpdate"
helpText={translate('OnApplicationUpdateHelpText')}
isDisabled={!supportsOnApplicationUpdate.value}
{...onApplicationUpdate}
onChange={onInputChange}
/>
</div>

<div>
<FormInputGroup
type={inputTypes.CHECK}
Expand All @@ -200,6 +213,7 @@ function NotificationEventItems(props) {
/>
</div>
}

</div>
</div>
</FormGroup>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/Store/Actions/Settings/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export default {
selectedSchema.onDownloadFailure = selectedSchema.supportsOnDownloadFailure;
selectedSchema.onImportFailure = selectedSchema.supportsOnImportFailure;
selectedSchema.onBookRetag = selectedSchema.supportsOnBookRetag;
selectedSchema.onApplicationUpdate = selectedSchema.supportsOnApplicationUpdate;

return selectedSchema;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public override void OnBookRetag(BookRetagMessage message)
{
TestLogger.Info("OnBookRetag was called");
}

public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
TestLogger.Info("OnApplicationUpdate was called");
}
}

private class TestNotificationWithNoEvents : NotificationBase<TestSetting>
Expand Down Expand Up @@ -138,6 +143,7 @@ public void should_support_all_if_implemented()
notification.SupportsOnDownloadFailure.Should().BeTrue();
notification.SupportsOnImportFailure.Should().BeTrue();
notification.SupportsOnBookRetag.Should().BeTrue();
notification.SupportsOnApplicationUpdate.Should().BeTrue();
}

[Test]
Expand All @@ -157,6 +163,7 @@ public void should_support_none_if_none_are_implemented()
notification.SupportsOnDownloadFailure.Should().BeFalse();
notification.SupportsOnImportFailure.Should().BeFalse();
notification.SupportsOnBookRetag.Should().BeFalse();
notification.SupportsOnApplicationUpdate.Should().BeFalse();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;

namespace NzbDrone.Core.Datastore.Migration
{
[Migration(025)]
public class add_on_update_to_notifications : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Notifications").AddColumn("OnApplicationUpdate").AsBoolean().WithDefaultValue(true);
}
}
}
3 changes: 2 additions & 1 deletion src/NzbDrone.Core/Datastore/TableMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public static void Map()
.Ignore(i => i.SupportsOnHealthIssue)
.Ignore(i => i.SupportsOnDownloadFailure)
.Ignore(i => i.SupportsOnImportFailure)
.Ignore(i => i.SupportsOnBookRetag);
.Ignore(i => i.SupportsOnBookRetag)
.Ignore(i => i.SupportsOnApplicationUpdate);

Mapper.Entity<MetadataDefinition>("Metadata").RegisterModel()
.Ignore(x => x.ImplementationName)
Expand Down
2 changes: 2 additions & 0 deletions src/NzbDrone.Core/Localization/Core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@
"OnBookFileDeleteHelpText": "On Book File Delete",
"OnBookRetagHelpText": "On Book Retag",
"OnBookTagUpdate": "On Book Tag Update",
"OnApplicationUpdate": "On Application Update",
"OnApplicationUpdateHelpText": "On Application Update",
"OnDownloadFailure": "On Download Failure",
"OnDownloadFailureHelpText": "On Download Failure",
"OnGrab": "On Grab",
Expand Down
16 changes: 16 additions & 0 deletions src/NzbDrone.Core/Notifications/ApplicationUpdateMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace NzbDrone.Core.Notifications
{
public class ApplicationUpdateMessage
{
public string Message { get; set; }
public Version PreviousVersion { get; set; }
public Version NewVersion { get; set; }

public override string ToString()
{
return NewVersion.ToString();
}
}
}
5 changes: 5 additions & 0 deletions src/NzbDrone.Core/Notifications/Boxcar/Boxcar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public override void OnImportFailure(BookDownloadMessage message)
_proxy.SendNotification(IMPORT_FAILURE_TITLE, message.Message, Settings);
}

public override void OnApplicationUpdate(ApplicationUpdateMessage message)
{
_proxy.SendNotification(APPLICATION_UPDATE_TITLE, message.Message, Settings);
}

public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
Expand Down
12 changes: 12 additions & 0 deletions src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
ExecuteScript(environmentVariables);
}

public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
var environmentVariables = new StringDictionary();

environmentVariables.Add("Readarr_EventType", "ApplicationUpdate");
environmentVariables.Add("Readarr_Update_Message", updateMessage.Message);
environmentVariables.Add("Readarr_Update_NewVersion", updateMessage.NewVersion.ToString());
environmentVariables.Add("Readarr_Update_PreviousVersion", updateMessage.PreviousVersion.ToString());

ExecuteScript(environmentVariables);
}

public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
Expand Down
35 changes: 35 additions & 0 deletions src/NzbDrone.Core/Notifications/Discord/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,41 @@ public override void OnImportFailure(BookDownloadMessage message)
_proxy.SendPayload(payload, Settings);
}

public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
var attachments = new List<Embed>
{
new Embed
{
Author = new DiscordAuthor
{
Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
IconUrl = "https://raw.githubusercontent.com/Readarr/Readarr/develop/Logo/256.png"
},
Title = APPLICATION_UPDATE_TITLE,
Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
Color = (int)DiscordColors.Standard,
Fields = new List<DiscordField>()
{
new DiscordField()
{
Name = "Previous Version",
Value = updateMessage.PreviousVersion.ToString()
},
new DiscordField()
{
Name = "New Version",
Value = updateMessage.NewVersion.ToString()
}
},
}
};

var payload = CreatePayload(null, attachments);

_proxy.SendPayload(payload, Settings);
}

public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
Expand Down
2 changes: 2 additions & 0 deletions src/NzbDrone.Core/Notifications/Discord/DiscordSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class DiscordSettings : IProviderConfig

[FieldDefinition(2, Label = "Avatar", HelpText = "Change the avatar that is used for messages from this integration", Type = FieldType.Textbox)]
public string Avatar { get; set; }
[FieldDefinition(3, Label = "Host", Advanced = true, HelpText = "Override the Host that shows for this notification, Blank is machine name", Type = FieldType.Textbox)]
public string Author { get; set; }

public NzbDroneValidationResult Validate()
{
Expand Down
12 changes: 12 additions & 0 deletions src/NzbDrone.Core/Notifications/Discord/Payloads/DiscordAuthor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Newtonsoft.Json;

namespace NzbDrone.Core.Notifications.Discord.Payloads
{
public class DiscordAuthor
{
public string Name { get; set; }

[JsonProperty("icon_url")]
public string IconUrl { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NzbDrone.Core.Notifications.Discord.Payloads
{
public class DiscordField
{
public string Name { get; set; }
public string Value { get; set; }
public bool Inline { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace NzbDrone.Core.Notifications.Discord.Payloads
{
public class DiscordImage
{
public string Url { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/NzbDrone.Core/Notifications/Discord/Payloads/Embed.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;

namespace NzbDrone.Core.Notifications.Discord.Payloads
{
public class Embed
Expand All @@ -6,5 +8,11 @@ public class Embed
public string Title { get; set; }
public string Text { get; set; }
public int Color { get; set; }
public string Url { get; set; }
public DiscordAuthor Author { get; set; }
public DiscordImage Thumbnail { get; set; }
public DiscordImage Image { get; set; }
public string Timestamp { get; set; }
public List<DiscordField> Fields { get; set; }
}
}
7 changes: 7 additions & 0 deletions src/NzbDrone.Core/Notifications/Email/Email.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public override void OnImportFailure(BookDownloadMessage message)
SendEmail(Settings, IMPORT_FAILURE_TITLE_BRANDED, message.Message);
}

public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
var body = $"{updateMessage.Message}";

SendEmail(Settings, APPLICATION_UPDATE_TITLE_BRANDED, body);
}

public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
Expand Down
5 changes: 5 additions & 0 deletions src/NzbDrone.Core/Notifications/Gotify/Gotify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public override void OnImportFailure(BookDownloadMessage message)
_proxy.SendNotification(IMPORT_FAILURE_TITLE, message.Message, Settings);
}

public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
_proxy.SendNotification(APPLICATION_UPDATE_TITLE, updateMessage.Message, Settings);
}

public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
Expand Down
2 changes: 2 additions & 0 deletions src/NzbDrone.Core/Notifications/INotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface INotification : IProvider
void OnBookDelete(BookDeleteMessage deleteMessage);
void OnBookFileDelete(BookFileDeleteMessage deleteMessage);
void OnHealthIssue(HealthCheck.HealthCheck healthCheck);
void OnApplicationUpdate(ApplicationUpdateMessage updateMessage);
void OnDownloadFailure(DownloadFailedMessage message);
void OnImportFailure(BookDownloadMessage message);
void OnBookRetag(BookRetagMessage message);
Expand All @@ -27,6 +28,7 @@ public interface INotification : IProvider
bool SupportsOnBookFileDelete { get; }
bool SupportsOnBookFileDeleteForUpgrade { get; }
bool SupportsOnHealthIssue { get; }
bool SupportsOnApplicationUpdate { get; }
bool SupportsOnDownloadFailure { get; }
bool SupportsOnImportFailure { get; }
bool SupportsOnBookRetag { get; }
Expand Down
5 changes: 5 additions & 0 deletions src/NzbDrone.Core/Notifications/Join/Join.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public override void OnHealthIssue(HealthCheck.HealthCheck message)
_proxy.SendNotification(HEALTH_ISSUE_TITLE_BRANDED, message.Message, Settings);
}

public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
_proxy.SendNotification(APPLICATION_UPDATE_TITLE_BRANDED, updateMessage.Message, Settings);
}

public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
Expand Down
5 changes: 5 additions & 0 deletions src/NzbDrone.Core/Notifications/Mailgun/Mailgun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public override void OnHealthIssue(HealthCheck.HealthCheck healthCheckMessage)
_proxy.SendNotification(HEALTH_ISSUE_TITLE, healthCheckMessage.Message, Settings);
}

public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
_proxy.SendNotification(APPLICATION_UPDATE_TITLE, updateMessage.Message, Settings);
}

public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
Expand Down
12 changes: 12 additions & 0 deletions src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
_proxy.SendNotification(variables, Settings);
}

public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
var variables = new StringDictionary();

variables.Add("Readarr_EventType", "ApplicationUpdate");
variables.Add("Readarr_Update_Message", updateMessage.Message);
variables.Add("Readarr_Update_NewVersion", updateMessage.NewVersion.ToString());
variables.Add("Readarr_Update_PreviousVersion", updateMessage.PreviousVersion.ToString());

_proxy.SendNotification(variables, Settings);
}

public override ValidationResult Test()
{
var failures = new List<ValidationFailure>();
Expand Down

0 comments on commit fbdc9f3

Please sign in to comment.