From ce79fec216005a18e8ea109b712ab25ab95ccbcf Mon Sep 17 00:00:00 2001 From: TidusJar Date: Tue, 21 Aug 2018 13:55:24 +0100 Subject: [PATCH 1/3] Stript out certain characters when sending a pushover message #2385 --- src/Ombi.Core.Tests/Ombi.Core.Tests.csproj | 8 +++--- src/Ombi.Core.Tests/StringHelperTests.cs | 26 +++++++++++++++++++ src/Ombi.Helpers/StringHelper.cs | 5 ++++ .../Agents/PushoverNotification.cs | 3 ++- 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/Ombi.Core.Tests/StringHelperTests.cs diff --git a/src/Ombi.Core.Tests/Ombi.Core.Tests.csproj b/src/Ombi.Core.Tests/Ombi.Core.Tests.csproj index 8f0abee8f..30de4b6f0 100644 --- a/src/Ombi.Core.Tests/Ombi.Core.Tests.csproj +++ b/src/Ombi.Core.Tests/Ombi.Core.Tests.csproj @@ -5,10 +5,10 @@ - - - - + + + + diff --git a/src/Ombi.Core.Tests/StringHelperTests.cs b/src/Ombi.Core.Tests/StringHelperTests.cs new file mode 100644 index 000000000..c1b95fcd7 --- /dev/null +++ b/src/Ombi.Core.Tests/StringHelperTests.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; + +using NUnit.Framework; +using Ombi.Helpers; + +namespace Ombi.Core.Tests +{ + [TestFixture] + public class StringHelperTests + { + [TestCaseSource(nameof(StripCharsData))] + public string StripCharacters(string str, char[] chars) + { + return str.StripCharacters(chars); + } + + private static IEnumerable StripCharsData + { + get + { + yield return new TestCaseData("this!is^a*string",new []{'!','^','*'}).Returns("thisisastring").SetName("Basic Strip Multipe Chars"); + yield return new TestCaseData("What is this madness'",new []{'\'','^','*'}).Returns("What is this madness").SetName("Basic Strip Multipe Chars"); + } + } + } +} \ No newline at end of file diff --git a/src/Ombi.Helpers/StringHelper.cs b/src/Ombi.Helpers/StringHelper.cs index aba120c65..2dad81015 100644 --- a/src/Ombi.Helpers/StringHelper.cs +++ b/src/Ombi.Helpers/StringHelper.cs @@ -75,5 +75,10 @@ namespace Ombi.Helpers return -1; } + + public static string StripCharacters(this string str, params char[] chars) + { + return string.Concat(str.Where(c => !chars.Contains(c))); + } } } \ No newline at end of file diff --git a/src/Ombi.Notifications/Agents/PushoverNotification.cs b/src/Ombi.Notifications/Agents/PushoverNotification.cs index 5b82eb8a3..72af001dc 100644 --- a/src/Ombi.Notifications/Agents/PushoverNotification.cs +++ b/src/Ombi.Notifications/Agents/PushoverNotification.cs @@ -177,7 +177,8 @@ namespace Ombi.Notifications.Agents { try { - await Api.PushAsync(settings.AccessToken, model.Message, settings.UserToken); + //&+' < > + await Api.PushAsync(settings.AccessToken, model.Message.StripCharacters('&','+','<','>'), settings.UserToken); } catch (Exception e) { From c6bb864be758b6f92baa0005bbc3650c8a5be513 Mon Sep 17 00:00:00 2001 From: David Pooley Date: Sun, 26 Aug 2018 20:57:39 +0100 Subject: [PATCH 2/3] Allow for the ability to set Pushover notification sound and priority from within Ombi. --- src/Ombi.Api.Pushover/IPushoverApi.cs | 2 +- src/Ombi.Api.Pushover/PushoverApi.cs | 4 +- .../Agents/PushoverNotification.cs | 2 +- .../Models/Notifications/PushoverSettings.cs | 2 + .../app/interfaces/INotificationSettings.ts | 2 + .../notifications/pushover.component.html | 42 +++++++++++++++++++ .../notifications/pushover.component.ts | 2 + 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/Ombi.Api.Pushover/IPushoverApi.cs b/src/Ombi.Api.Pushover/IPushoverApi.cs index 42e8e9060..554a15b60 100644 --- a/src/Ombi.Api.Pushover/IPushoverApi.cs +++ b/src/Ombi.Api.Pushover/IPushoverApi.cs @@ -5,6 +5,6 @@ namespace Ombi.Api.Pushover { public interface IPushoverApi { - Task PushAsync(string accessToken, string message, string userToken); + Task PushAsync(string accessToken, string message, string userToken, sbyte priority, string sound); } } \ No newline at end of file diff --git a/src/Ombi.Api.Pushover/PushoverApi.cs b/src/Ombi.Api.Pushover/PushoverApi.cs index fd6ca23ea..9f91bc7ca 100644 --- a/src/Ombi.Api.Pushover/PushoverApi.cs +++ b/src/Ombi.Api.Pushover/PushoverApi.cs @@ -16,13 +16,13 @@ namespace Ombi.Api.Pushover private readonly IApi _api; private const string PushoverEndpoint = "https://api.pushover.net/1"; - public async Task PushAsync(string accessToken, string message, string userToken) + public async Task PushAsync(string accessToken, string message, string userToken, sbyte priority, string sound) { if (message.Contains("'")) { message = message.Replace("'", "'"); } - var request = new Request($"messages.json?token={accessToken}&user={userToken}&message={WebUtility.HtmlEncode(message)}", PushoverEndpoint, HttpMethod.Post); + var request = new Request($"messages.json?token={accessToken}&user={userToken}&priority={priority}&sound={sound}&message={WebUtility.HtmlEncode(message)}", PushoverEndpoint, HttpMethod.Post); var result = await _api.Request(request); return result; diff --git a/src/Ombi.Notifications/Agents/PushoverNotification.cs b/src/Ombi.Notifications/Agents/PushoverNotification.cs index 5b82eb8a3..2719c3861 100644 --- a/src/Ombi.Notifications/Agents/PushoverNotification.cs +++ b/src/Ombi.Notifications/Agents/PushoverNotification.cs @@ -177,7 +177,7 @@ namespace Ombi.Notifications.Agents { try { - await Api.PushAsync(settings.AccessToken, model.Message, settings.UserToken); + await Api.PushAsync(settings.AccessToken, model.Message, settings.UserToken, settings.Priority, settings.Sound); } catch (Exception e) { diff --git a/src/Ombi.Settings/Settings/Models/Notifications/PushoverSettings.cs b/src/Ombi.Settings/Settings/Models/Notifications/PushoverSettings.cs index d845e8695..3e65d628d 100644 --- a/src/Ombi.Settings/Settings/Models/Notifications/PushoverSettings.cs +++ b/src/Ombi.Settings/Settings/Models/Notifications/PushoverSettings.cs @@ -8,5 +8,7 @@ namespace Ombi.Settings.Settings.Models.Notifications public bool Enabled { get; set; } public string AccessToken { get; set; } public string UserToken { get; set; } + public sbyte Priority { get; set; } + public string Sound { get; set; } } } \ No newline at end of file diff --git a/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts b/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts index 8c5fcd5bc..fc8b89f1e 100644 --- a/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts +++ b/src/Ombi/ClientApp/app/interfaces/INotificationSettings.ts @@ -88,6 +88,8 @@ export interface IPushoverNotificationSettings extends INotificationSettings { accessToken: string; notificationTemplates: INotificationTemplates[]; userToken: string; + priority: number; + sound: string; } export interface IMattermostNotifcationSettings extends INotificationSettings { diff --git a/src/Ombi/ClientApp/app/settings/notifications/pushover.component.html b/src/Ombi/ClientApp/app/settings/notifications/pushover.component.html index b56467c9f..499263dec 100644 --- a/src/Ombi/ClientApp/app/settings/notifications/pushover.component.html +++ b/src/Ombi/ClientApp/app/settings/notifications/pushover.component.html @@ -28,6 +28,48 @@ +
+ +
+ +
+
+ +
+ +
+ +
+
+
diff --git a/src/Ombi/ClientApp/app/settings/notifications/pushover.component.ts b/src/Ombi/ClientApp/app/settings/notifications/pushover.component.ts index 5d208568c..64f339192 100644 --- a/src/Ombi/ClientApp/app/settings/notifications/pushover.component.ts +++ b/src/Ombi/ClientApp/app/settings/notifications/pushover.component.ts @@ -27,6 +27,8 @@ export class PushoverComponent implements OnInit { enabled: [x.enabled], userToken: [x.userToken], accessToken: [x.accessToken, [Validators.required]], + priority: [x.priority], + sound: [x.sound], }); }); } From 067ffae3031601cc8018c880c49a9bc87baeaccf Mon Sep 17 00:00:00 2001 From: David Pooley Date: Sun, 26 Aug 2018 22:48:46 +0100 Subject: [PATCH 3/3] Add default values for Priority and Sound. --- .../Settings/Models/Notifications/PushoverSettings.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ombi.Settings/Settings/Models/Notifications/PushoverSettings.cs b/src/Ombi.Settings/Settings/Models/Notifications/PushoverSettings.cs index 3e65d628d..9c3dfc350 100644 --- a/src/Ombi.Settings/Settings/Models/Notifications/PushoverSettings.cs +++ b/src/Ombi.Settings/Settings/Models/Notifications/PushoverSettings.cs @@ -8,7 +8,7 @@ namespace Ombi.Settings.Settings.Models.Notifications public bool Enabled { get; set; } public string AccessToken { get; set; } public string UserToken { get; set; } - public sbyte Priority { get; set; } - public string Sound { get; set; } + public sbyte Priority { get; set; } = 0; + public string Sound { get; set; } = "pushover"; } } \ No newline at end of file