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
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/.idea/.idea.Ombi/.idea/dbnavigator.xml b/src/.idea/.idea.Ombi/.idea/dbnavigator.xml
new file mode 100644
index 000000000..4e210d20a
--- /dev/null
+++ b/src/.idea/.idea.Ombi/.idea/dbnavigator.xml
@@ -0,0 +1,440 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/.idea/.idea.Ombi/.idea/modules.xml b/src/.idea/.idea.Ombi/.idea/modules.xml
deleted file mode 100644
index 4d6d71637..000000000
--- a/src/.idea/.idea.Ombi/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/.idea/.idea.Ombi/.idea/projectSettingsUpdater.xml b/src/.idea/.idea.Ombi/.idea/projectSettingsUpdater.xml
new file mode 100644
index 000000000..64af657f5
--- /dev/null
+++ b/src/.idea/.idea.Ombi/.idea/projectSettingsUpdater.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/.idea/.idea.Ombi/.idea/workspace.xml b/src/.idea/.idea.Ombi/.idea/workspace.xml
index 5f2397863..c32735aa1 100644
--- a/src/.idea/.idea.Ombi/.idea/workspace.xml
+++ b/src/.idea/.idea.Ombi/.idea/workspace.xml
@@ -5,9 +5,21 @@
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -234,6 +246,12 @@
+ {
+ "lastFilter": {
+ "state": "OPEN",
+ "assignee": "tidusjar"
+ }
+}
+ {
+ "selectedUrlAndAccountId": {
+ "url": "https://github.com/ombi-app/ombi",
+ "accountId": "22dd09fe-fb9e-48a4-bfcc-3c152edf3f25"
+ }
+}
@@ -308,12 +332,17 @@
+ {
+ "customColor": "",
+ "associatedIndex": 0
+}
+
@@ -376,11 +405,23 @@
+
+
+
+
@@ -460,6 +501,7 @@
+
@@ -468,6 +510,9 @@
1563957157468
+
+
+
@@ -512,7 +557,13 @@
+
+
+
+
+
+
@@ -536,12 +587,12 @@
file://$PROJECT_DIR$/Ombi.Core/Engine/V2/MultiSearchEngine.cs
59
-
+
-
+
-
+
@@ -549,12 +600,12 @@
file://$PROJECT_DIR$/Ombi.Core/Engine/V2/MultiSearchEngine.cs
49
-
+
-
+
-
+
@@ -562,16 +613,42 @@
file://$PROJECT_DIR$/Ombi.Api.MusicBrainz/MusicBrainzApi.cs
30
-
+
-
+
-
+
+
+ file://$PROJECT_DIR$/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs
+ 110
+
+
+
+
+
+
+
+
+
+
+
+ file://$PROJECT_DIR$/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs
+ 77
+
+
+
+
+
+
+
+
+
+
diff --git a/src/.idea/.idea.Ombi/riderModule.iml b/src/.idea/.idea.Ombi/riderModule.iml
deleted file mode 100644
index d716cec6d..000000000
--- a/src/.idea/.idea.Ombi/riderModule.iml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/.vscode/tasks.json b/src/.vscode/tasks.json
index ad868d2dc..ad83d25c8 100644
--- a/src/.vscode/tasks.json
+++ b/src/.vscode/tasks.json
@@ -1,22 +1,31 @@
{
- "version": "0.1.0",
+ "version": "2.0.0",
"command": "dotnet",
- "isShellCommand": true,
"args": [],
"tasks": [
{
- "taskName": "build",
+ "label": "build",
+ "type": "shell",
+ "command": "dotnet",
"args": [
+ "build",
"${workspaceRoot}/Ombi/Ombi.csproj"
],
- "isBuildCommand": true,
- "problemMatcher": "$msCompile"
+ "problemMatcher": "$msCompile",
+ "group": {
+ "_id": "build",
+ "isDefault": false
+ }
},
{
- "taskName": "lint",
+ "label": "lint",
+ "type": "shell",
"command": "npm",
- "isShellCommand": true,
- "args": ["run", "lint"]
+ "args": [
+ "run",
+ "lint"
+ ],
+ "problemMatcher": []
}
]
}
\ No newline at end of file
diff --git a/src/Ombi.Helpers/NotificationType.cs b/src/Ombi.Helpers/NotificationType.cs
index bd6bd6f87..274813531 100644
--- a/src/Ombi.Helpers/NotificationType.cs
+++ b/src/Ombi.Helpers/NotificationType.cs
@@ -14,6 +14,7 @@
IssueResolved = 9,
IssueComment = 10,
Newsletter = 11,
- PartiallyAvailable = 12
+ PartiallyAvailable = 12,
+ PlexWatchlistTokenExpired = 13
}
}
diff --git a/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj b/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj
index 97c999497..0ca27a075 100644
--- a/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj
+++ b/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj
@@ -2,6 +2,9 @@
net8.0
+
+ false
+
Debug;Release;NonUiBuild
@@ -13,7 +16,7 @@
-
+
diff --git a/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs b/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs
index 4af981363..1d0981dd3 100644
--- a/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs
+++ b/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs
@@ -20,6 +20,10 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using Ombi.Notifications.Models;
+using Ombi.Core.Notifications;
+using Ombi.Helpers;
+using Ombi.Core;
namespace Ombi.Schedule.Tests
{
@@ -35,12 +39,13 @@ namespace Ombi.Schedule.Tests
public void Setup()
{
_mocker = new AutoMocker();
- var um = MockHelper.MockUserManager(new List { new OmbiUser { Id = "abc", UserType = UserType.PlexUser, MediaServerToken = "token1", UserName = "abc", NormalizedUserName = "ABC" } });
+ var um = MockHelper.MockUserManager(new List { new OmbiUser { Id = "abc", Email = "email@email.com", UserType = UserType.PlexUser, MediaServerToken = "token1", UserName = "abc", NormalizedUserName = "ABC" } });
_mocker.Use(um);
_context = _mocker.GetMock();
_context.Setup(x => x.CancellationToken).Returns(CancellationToken.None);
_subject = _mocker.CreateInstance();
_mocker.Setup, IQueryable>(x => x.GetAll()).Returns(new List().AsQueryable().BuildMock());
+ _mocker.Setup(x => x.Notify(It.IsAny()));
}
[Test]
@@ -777,5 +782,62 @@ namespace Ombi.Schedule.Tests
_mocker.Verify>(x => x.GetAll(), Times.Once);
_mocker.Verify>(x => x.Add(It.IsAny()), Times.Once);
}
+
+ [Test]
+ public async Task AuthenticationError_NotificationsEnabled_WithEmail_SendsNotification()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync())
+ .ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true, NotifyOnWatchlistTokenExpiration = true });
+ _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny()))
+ .ReturnsAsync(new PlexWatchlistContainer { AuthError = true });
+
+ // Act
+ await _subject.Execute(_context.Object);
+
+ // Assert
+ _mocker.Verify(x => x.Notify(It.Is(n =>
+ n.NotificationType == NotificationType.PlexWatchlistTokenExpired &&
+ n.Recipient == "email@email.com" &&
+ n.Substitutes["UserName"] == "abc" &&
+ n.Substitutes["ApplicationName"] == "Ombi"
+ )), Times.Once);
+ }
+
+ [Test]
+ public async Task AuthenticationError_NotificationsDisabled_WithEmail_DoesNotSendNotification()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync())
+ .ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true, NotifyOnWatchlistTokenExpiration = false });
+ _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny()))
+ .ReturnsAsync(new PlexWatchlistContainer { AuthError = true });
+
+ // Act
+ await _subject.Execute(_context.Object);
+
+ // Assert
+ _mocker.Verify(x => x.Notify(It.IsAny()), Times.Never);
+ }
+
+ [Test]
+ public async Task AuthenticationError_NotificationsEnabled_NoEmail_DoesNotSendNotification()
+ {
+ // Arrange
+ var user = new OmbiUser { Id = "abc", UserType = UserType.PlexUser, MediaServerToken = "token1", UserName = "abc", NormalizedUserName = "ABC" };
+ var um = MockHelper.MockUserManager(new List { user });
+ _mocker.Use(um);
+
+ _mocker.Setup, Task>(x => x.GetSettingsAsync())
+ .ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true, NotifyOnWatchlistTokenExpiration = true });
+ _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny()))
+ .ReturnsAsync(new PlexWatchlistContainer { AuthError = true });
+
+ _subject = _mocker.CreateInstance();
+
+ // Act
+ await _subject.Execute(_context.Object);
+
+ // Assert
+ _mocker.Verify(x => x.Notify(It.IsAny()), Times.Never);
+ }
}
}
diff --git a/src/Ombi.Schedule.Tests/Properties/launchSettings.json b/src/Ombi.Schedule.Tests/Properties/launchSettings.json
deleted file mode 100644
index 57de33708..000000000
--- a/src/Ombi.Schedule.Tests/Properties/launchSettings.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "iisSettings": {
- "windowsAuthentication": false,
- "anonymousAuthentication": true,
- "iisExpress": {
- "applicationUrl": "http://localhost:62604/",
- "sslPort": 0
- }
- },
- "profiles": {
- "IIS Express": {
- "commandName": "IISExpress",
- "launchBrowser": true,
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
- }
- },
- "Ombi.Schedule.Tests": {
- "commandName": "Project",
- "launchBrowser": true,
- "environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Development"
- },
- "applicationUrl": "http://localhost:62605/"
- }
- }
-}
diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs b/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs
index dc1aa5d56..947e54406 100644
--- a/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs
+++ b/src/Ombi.Schedule/Jobs/Plex/PlexWatchlistImport.cs
@@ -22,6 +22,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using Ombi.Notifications.Models;
+using Ombi.Core.Notifications;
+using Microsoft.AspNetCore.Identity;
+using Ombi.Store.Repository.Requests;
+using Ombi.Core;
namespace Ombi.Schedule.Jobs.Plex
{
@@ -37,11 +42,12 @@ namespace Ombi.Schedule.Jobs.Plex
private readonly IExternalRepository _watchlistRepo;
private readonly IRepository _userError;
private readonly IMovieDbApi _movieDbApi;
+ private readonly INotificationHelper _notificationHelper;
public PlexWatchlistImport(IPlexApi plexApi, ISettingsService settings, OmbiUserManager ombiUserManager,
IMovieRequestEngine movieRequestEngine, ITvRequestEngine tvRequestEngine, INotificationHubService notificationHubService,
ILogger logger, IExternalRepository watchlistRepo, IRepository userError,
- IMovieDbApi movieDbApi)
+ IMovieDbApi movieDbApi, INotificationHelper notificationHelper)
{
_plexApi = plexApi;
_settings = settings;
@@ -53,6 +59,7 @@ namespace Ombi.Schedule.Jobs.Plex
_watchlistRepo = watchlistRepo;
_userError = userError;
_movieDbApi = movieDbApi;
+ _notificationHelper = notificationHelper;
}
public async Task Execute(IJobExecutionContext context)
@@ -99,6 +106,22 @@ namespace Ombi.Schedule.Jobs.Plex
UserId = user.Id,
MediaServerToken = user.MediaServerToken,
});
+
+ // Send notification to user about token expiration
+ if (settings.NotifyOnWatchlistTokenExpiration && !string.IsNullOrEmpty(user.Email))
+ {
+ var notificationModel = new NotificationOptions
+ {
+ NotificationType = NotificationType.PlexWatchlistTokenExpired,
+ Recipient = user.Email,
+ DateTime = DateTime.Now,
+ Substitutes = new Dictionary
+ {
+ { "UserName", user.UserName }
+ }
+ };
+ await _notificationHelper.Notify(notificationModel);
+ }
continue;
}
if (watchlist == null || !(watchlist.MediaContainer?.Metadata?.Any() ?? false))
diff --git a/src/Ombi.Settings/Settings/Models/External/PlexSettings.cs b/src/Ombi.Settings/Settings/Models/External/PlexSettings.cs
index 6edfe0351..649f1d0c7 100644
--- a/src/Ombi.Settings/Settings/Models/External/PlexSettings.cs
+++ b/src/Ombi.Settings/Settings/Models/External/PlexSettings.cs
@@ -9,6 +9,7 @@ namespace Ombi.Core.Settings.Models.External
public bool Enable { get; set; }
public bool EnableWatchlistImport { get; set; }
public bool MonitorAll { get; set; }
+ public bool NotifyOnWatchlistTokenExpiration { get; set; }
///
/// This is the ClientId for OAuth
///
diff --git a/src/Ombi.Store/Context/OmbiContext.cs b/src/Ombi.Store/Context/OmbiContext.cs
index eea83a03d..624f2c2c4 100644
--- a/src/Ombi.Store/Context/OmbiContext.cs
+++ b/src/Ombi.Store/Context/OmbiContext.cs
@@ -217,6 +217,16 @@ namespace Ombi.Store.Context
Enabled = true,
};
break;
+ case NotificationType.PlexWatchlistTokenExpired:
+ notificationToAdd = new NotificationTemplates
+ {
+ NotificationType = notificationType,
+ Message = "Hello {UserName}! Your Plex watchlist token has expired. Please re-authenticate with Ombi to continue using the watchlist feature.",
+ Subject = "{ApplicationName}: Plex Watchlist Token Expired",
+ Agent = agent,
+ Enabled = true,
+ };
+ break;
default:
throw new ArgumentOutOfRangeException();
}
diff --git a/src/Ombi/ClientApp/src/app/interfaces/INotificationSettings.ts b/src/Ombi/ClientApp/src/app/interfaces/INotificationSettings.ts
index 460a970fe..5f6085362 100644
--- a/src/Ombi/ClientApp/src/app/interfaces/INotificationSettings.ts
+++ b/src/Ombi/ClientApp/src/app/interfaces/INotificationSettings.ts
@@ -52,6 +52,7 @@ export enum NotificationType {
IssueComment = 10,
Newsletter = 11,
PartiallyAvailable = 12,
+ PlexWatchlistTokenExpired = 13
}
export interface IDiscordNotifcationSettings extends INotificationSettings {
diff --git a/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts b/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts
index 532b8625f..008628c16 100644
--- a/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts
+++ b/src/Ombi/ClientApp/src/app/interfaces/ISettings.ts
@@ -114,6 +114,7 @@ export interface IPlexSettings extends ISettings {
enable: boolean;
enableWatchlistImport: boolean;
monitorAll: boolean;
+ notifyOnWatchlistTokenExpiration: boolean;
servers: IPlexServer[];
}
diff --git a/src/Ombi/ClientApp/src/app/settings/plex/plex.component.html b/src/Ombi/ClientApp/src/app/settings/plex/plex.component.html
index 4bfcbf1c5..b8fe85666 100644
--- a/src/Ombi/ClientApp/src/app/settings/plex/plex.component.html
+++ b/src/Ombi/ClientApp/src/app/settings/plex/plex.component.html
@@ -21,7 +21,11 @@
-
+
+ When enabled, users will receive a notification if their Plex watchlist token expires and they need to log into Ombi again to continue using the watchlist feature.
+
Note: This requires email notifications to be configured in the notification settings, and users must have an email address set on their account to receive these notifications.
+
+