diff --git a/src/Ombi.Api.CouchPotato/Ombi.Api.CouchPotato.csproj b/src/Ombi.Api.CouchPotato/Ombi.Api.CouchPotato.csproj
index 6353f4bf9..89c47d251 100644
--- a/src/Ombi.Api.CouchPotato/Ombi.Api.CouchPotato.csproj
+++ b/src/Ombi.Api.CouchPotato/Ombi.Api.CouchPotato.csproj
@@ -2,7 +2,7 @@
net6.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Discord/Ombi.Api.Discord.csproj b/src/Ombi.Api.Discord/Ombi.Api.Discord.csproj
index 4945a2fb2..70032d638 100644
--- a/src/Ombi.Api.Discord/Ombi.Api.Discord.csproj
+++ b/src/Ombi.Api.Discord/Ombi.Api.Discord.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj b/src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj
index 6353f4bf9..89c47d251 100644
--- a/src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj
+++ b/src/Ombi.Api.DogNzb/Ombi.Api.DogNzb.csproj
@@ -2,7 +2,7 @@
net6.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj b/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj
index b524c9ce4..f60971192 100644
--- a/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj
+++ b/src/Ombi.Api.Emby/Ombi.Api.Emby.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.FanartTv/Ombi.Api.FanartTv.csproj b/src/Ombi.Api.FanartTv/Ombi.Api.FanartTv.csproj
index 4945a2fb2..70032d638 100644
--- a/src/Ombi.Api.FanartTv/Ombi.Api.FanartTv.csproj
+++ b/src/Ombi.Api.FanartTv/Ombi.Api.FanartTv.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Github/Ombi.Api.Github.csproj b/src/Ombi.Api.Github/Ombi.Api.Github.csproj
index 6353f4bf9..89c47d251 100644
--- a/src/Ombi.Api.Github/Ombi.Api.Github.csproj
+++ b/src/Ombi.Api.Github/Ombi.Api.Github.csproj
@@ -2,7 +2,7 @@
net6.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Gotify/Ombi.Api.Gotify.csproj b/src/Ombi.Api.Gotify/Ombi.Api.Gotify.csproj
index 1285c073c..be32916f8 100644
--- a/src/Ombi.Api.Gotify/Ombi.Api.Gotify.csproj
+++ b/src/Ombi.Api.Gotify/Ombi.Api.Gotify.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.GroupMe/Ombi.Api.GroupMe.csproj b/src/Ombi.Api.GroupMe/Ombi.Api.GroupMe.csproj
index 6353f4bf9..89c47d251 100644
--- a/src/Ombi.Api.GroupMe/Ombi.Api.GroupMe.csproj
+++ b/src/Ombi.Api.GroupMe/Ombi.Api.GroupMe.csproj
@@ -2,7 +2,7 @@
net6.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj b/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj
index dfdb5a93f..0c745556e 100644
--- a/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj
+++ b/src/Ombi.Api.Jellyfin/Ombi.Api.Jellyfin.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Lidarr/Ombi.Api.Lidarr.csproj b/src/Ombi.Api.Lidarr/Ombi.Api.Lidarr.csproj
index 6353f4bf9..89c47d251 100644
--- a/src/Ombi.Api.Lidarr/Ombi.Api.Lidarr.csproj
+++ b/src/Ombi.Api.Lidarr/Ombi.Api.Lidarr.csproj
@@ -2,7 +2,7 @@
net6.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj b/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj
index a25024b6c..16c3a8558 100644
--- a/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj
+++ b/src/Ombi.Api.Mattermost/Ombi.Api.Mattermost.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj b/src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj
index f167146af..a1b98b765 100644
--- a/src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj
+++ b/src/Ombi.Api.MediaServer/Ombi.Api.MediaServer.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj b/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj
index 584b980ce..c8a78e491 100644
--- a/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj
+++ b/src/Ombi.Api.MusicBrainz/Ombi.Api.MusicBrainz.csproj
@@ -2,7 +2,7 @@
net6.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj b/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj
index f84a8add6..6406ef9de 100644
--- a/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj
+++ b/src/Ombi.Api.Notifications/Ombi.Api.Notifications.csproj
@@ -2,7 +2,7 @@
net6.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Plex/IPlexApi.cs b/src/Ombi.Api.Plex/IPlexApi.cs
index a4597765e..746c85b77 100644
--- a/src/Ombi.Api.Plex/IPlexApi.cs
+++ b/src/Ombi.Api.Plex/IPlexApi.cs
@@ -1,4 +1,5 @@
using System;
+using System.Threading;
using System.Threading.Tasks;
using Ombi.Api.Plex.Models;
using Ombi.Api.Plex.Models.Friends;
@@ -16,9 +17,9 @@ namespace Ombi.Api.Plex
Task GetServer(string authToken);
Task GetLibrarySections(string authToken, string plexFullHost);
Task GetLibrary(string authToken, string plexFullHost, string libraryId);
- Task GetEpisodeMetaData(string authToken, string host, int ratingKey);
- Task GetMetadata(string authToken, string plexFullHost, int itemId);
- Task GetSeasons(string authToken, string plexFullHost, int ratingKey);
+ Task GetEpisodeMetaData(string authToken, string host, string ratingKey);
+ Task GetMetadata(string authToken, string plexFullHost, string itemId);
+ Task GetSeasons(string authToken, string plexFullHost, string ratingKey);
Task GetAllEpisodes(string authToken, string host, string section, int start, int retCount);
Task GetUsers(string authToken);
Task GetAccount(string authToken);
@@ -26,5 +27,7 @@ namespace Ombi.Api.Plex
Task GetPin(int pinId);
Task GetOAuthUrl(string code, string applicationUrl);
Task AddUser(string emailAddress, string serverId, string authToken, int[] libs);
+ Task GetWatchlist(string plexToken, CancellationToken cancellationToken);
+ Task GetWatchlistMetadata(string ratingKey, string plexToken, CancellationToken cancellationToken);
}
}
\ No newline at end of file
diff --git a/src/Ombi.Api.Plex/Models/Metadata.cs b/src/Ombi.Api.Plex/Models/Metadata.cs
index 65cb21e95..3481e9b57 100644
--- a/src/Ombi.Api.Plex/Models/Metadata.cs
+++ b/src/Ombi.Api.Plex/Models/Metadata.cs
@@ -4,7 +4,7 @@ namespace Ombi.Api.Plex.Models
{
public class Metadata
{
- public int ratingKey { get; set; }
+ public string ratingKey { get; set; }
public string key { get; set; }
public string studio { get; set; }
public string type { get; set; }
@@ -22,8 +22,8 @@ namespace Ombi.Api.Plex.Models
public int childCount { get; set; }
public Genre[] Genre { get; set; }
public string primaryExtraKey { get; set; }
- public int parentRatingKey { get; set; }
- public int grandparentRatingKey { get; set; }
+ public string parentRatingKey { get; set; }
+ public string grandparentRatingKey { get; set; }
public string guid { get; set; }
public int librarySectionID { get; set; }
public string librarySectionKey { get; set; }
diff --git a/src/Ombi.Api.Plex/Models/PlexWatchlist.cs b/src/Ombi.Api.Plex/Models/PlexWatchlist.cs
new file mode 100644
index 000000000..52ca82cf9
--- /dev/null
+++ b/src/Ombi.Api.Plex/Models/PlexWatchlist.cs
@@ -0,0 +1,14 @@
+using System.Collections.Generic;
+
+namespace Ombi.Api.Plex.Models
+{
+ public class PlexWatchlist
+ {
+ public string librarySectionID { get; set; }
+ public string librarySectionTitle { get; set; }
+ public int offset { get; set; }
+ public int totalSize { get; set; }
+ public int size { get; set; }
+ public List Metadata { get; set; } = new List();
+ }
+}
\ No newline at end of file
diff --git a/src/Ombi.Api.Plex/Models/PlexWatchlistContainer.cs b/src/Ombi.Api.Plex/Models/PlexWatchlistContainer.cs
new file mode 100644
index 000000000..b208c189f
--- /dev/null
+++ b/src/Ombi.Api.Plex/Models/PlexWatchlistContainer.cs
@@ -0,0 +1,9 @@
+using System.Collections.Generic;
+
+namespace Ombi.Api.Plex.Models
+{
+ public class PlexWatchlistContainer
+ {
+ public PlexWatchlist MediaContainer { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/Ombi.Api.Plex/Models/PlexWatchlistMetadataContainer.cs b/src/Ombi.Api.Plex/Models/PlexWatchlistMetadataContainer.cs
new file mode 100644
index 000000000..b582ca4e1
--- /dev/null
+++ b/src/Ombi.Api.Plex/Models/PlexWatchlistMetadataContainer.cs
@@ -0,0 +1,31 @@
+using System.Collections.Generic;
+
+namespace Ombi.Api.Plex.Models
+{
+ public class PlexWatchlistMetadataContainer
+ {
+ public PlexWatchlistMetadata MediaContainer { get; set; }
+ }
+
+
+ public class PlexWatchlistMetadata
+ {
+ public int offset { get; set; }
+ public int totalSize { get; set; }
+ public string identifier { get; set; }
+ public int size { get; set; }
+ public WatchlistMetadata[] Metadata { get; set; }
+ }
+
+ public class WatchlistMetadata
+ {
+ public string guid { get; set; }
+ public string key { get; set; }
+ public string primaryExtraKey { get; set; }
+ public string ratingKey { get; set; }
+ public string type { get; set; }
+ public string slug { get; set; }
+ public string title { get; set; }
+ public List Guid { get; set; } = new List();
+ }
+}
\ No newline at end of file
diff --git a/src/Ombi.Api.Plex/Ombi.Api.Plex.csproj b/src/Ombi.Api.Plex/Ombi.Api.Plex.csproj
index 4945a2fb2..70032d638 100644
--- a/src/Ombi.Api.Plex/Ombi.Api.Plex.csproj
+++ b/src/Ombi.Api.Plex/Ombi.Api.Plex.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Plex/PlexApi.cs b/src/Ombi.Api.Plex/PlexApi.cs
index 176af31ec..9f91c540c 100644
--- a/src/Ombi.Api.Plex/PlexApi.cs
+++ b/src/Ombi.Api.Plex/PlexApi.cs
@@ -1,5 +1,6 @@
using System;
using System.Net.Http;
+using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Ombi.Api.Plex.Models;
@@ -66,6 +67,7 @@ namespace Ombi.Api.Plex
private const string FriendsUri = "https://plex.tv/pms/friends/all";
private const string GetAccountUri = "https://plex.tv/users/account.json";
private const string ServerUri = "https://plex.tv/pms/servers.xml";
+ private const string WatchlistUri = "https://metadata.provider.plex.tv/";
///
/// Sign into the Plex API
@@ -145,21 +147,21 @@ namespace Ombi.Api.Plex
///
///
///
- public async Task GetEpisodeMetaData(string authToken, string plexFullHost, int ratingKey)
+ public async Task GetEpisodeMetaData(string authToken, string plexFullHost, string ratingKey)
{
var request = new Request($"/library/metadata/{ratingKey}", plexFullHost, HttpMethod.Get);
await AddHeaders(request, authToken);
return await Api.Request(request);
}
- public async Task GetMetadata(string authToken, string plexFullHost, int itemId)
+ public async Task GetMetadata(string authToken, string plexFullHost, string itemId)
{
var request = new Request($"library/metadata/{itemId}", plexFullHost, HttpMethod.Get);
await AddHeaders(request, authToken);
return await Api.Request(request);
}
- public async Task GetSeasons(string authToken, string plexFullHost, int ratingKey)
+ public async Task GetSeasons(string authToken, string plexFullHost, string ratingKey)
{
var request = new Request($"library/metadata/{ratingKey}/children", plexFullHost, HttpMethod.Get);
await AddHeaders(request, authToken);
@@ -288,6 +290,26 @@ namespace Ombi.Api.Plex
}
}
+ public async Task GetWatchlist(string plexToken, CancellationToken cancellationToken)
+ {
+ var request = new Request("library/sections/watchlist/all", WatchlistUri, HttpMethod.Get);
+ await AddHeaders(request, plexToken);
+
+ var result = await Api.Request(request, cancellationToken);
+
+ return result;
+ }
+
+ public async Task GetWatchlistMetadata(string ratingKey, string plexToken, CancellationToken cancellationToken)
+ {
+ var request = new Request($"library/metadata/{ratingKey}", WatchlistUri, HttpMethod.Get);
+ await AddHeaders(request, plexToken);
+
+ var result = await Api.Request(request, cancellationToken);
+
+ return result;
+ }
+
///
/// Adds the required headers and also the authorization header
diff --git a/src/Ombi.Api.Pushbullet/Ombi.Api.Pushbullet.csproj b/src/Ombi.Api.Pushbullet/Ombi.Api.Pushbullet.csproj
index 4945a2fb2..70032d638 100644
--- a/src/Ombi.Api.Pushbullet/Ombi.Api.Pushbullet.csproj
+++ b/src/Ombi.Api.Pushbullet/Ombi.Api.Pushbullet.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Pushover/Ombi.Api.Pushover.csproj b/src/Ombi.Api.Pushover/Ombi.Api.Pushover.csproj
index 1285c073c..be32916f8 100644
--- a/src/Ombi.Api.Pushover/Ombi.Api.Pushover.csproj
+++ b/src/Ombi.Api.Pushover/Ombi.Api.Pushover.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj b/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj
index f14df4f5f..889aa0ea6 100644
--- a/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj
+++ b/src/Ombi.Api.Radarr/Ombi.Api.Radarr.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.RottenTomatoes/Ombi.Api.RottenTomatoes.csproj b/src/Ombi.Api.RottenTomatoes/Ombi.Api.RottenTomatoes.csproj
index 6353f4bf9..89c47d251 100644
--- a/src/Ombi.Api.RottenTomatoes/Ombi.Api.RottenTomatoes.csproj
+++ b/src/Ombi.Api.RottenTomatoes/Ombi.Api.RottenTomatoes.csproj
@@ -2,7 +2,7 @@
net6.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Service/Ombi.Api.Service.csproj b/src/Ombi.Api.Service/Ombi.Api.Service.csproj
index a344de142..38bcd678a 100644
--- a/src/Ombi.Api.Service/Ombi.Api.Service.csproj
+++ b/src/Ombi.Api.Service/Ombi.Api.Service.csproj
@@ -8,7 +8,7 @@
Ombi.Api.Service
Ombi.Api.Service
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.SickRage/Ombi.Api.SickRage.csproj b/src/Ombi.Api.SickRage/Ombi.Api.SickRage.csproj
index 6353f4bf9..89c47d251 100644
--- a/src/Ombi.Api.SickRage/Ombi.Api.SickRage.csproj
+++ b/src/Ombi.Api.SickRage/Ombi.Api.SickRage.csproj
@@ -2,7 +2,7 @@
net6.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Slack/Ombi.Api.Slack.csproj b/src/Ombi.Api.Slack/Ombi.Api.Slack.csproj
index 4945a2fb2..70032d638 100644
--- a/src/Ombi.Api.Slack/Ombi.Api.Slack.csproj
+++ b/src/Ombi.Api.Slack/Ombi.Api.Slack.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj b/src/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj
index 4945a2fb2..70032d638 100644
--- a/src/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj
+++ b/src/Ombi.Api.Sonarr/Ombi.Api.Sonarr.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Telegram/Ombi.Api.Telegram.csproj b/src/Ombi.Api.Telegram/Ombi.Api.Telegram.csproj
index 6353f4bf9..89c47d251 100644
--- a/src/Ombi.Api.Telegram/Ombi.Api.Telegram.csproj
+++ b/src/Ombi.Api.Telegram/Ombi.Api.Telegram.csproj
@@ -2,7 +2,7 @@
net6.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj b/src/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj
index e07f40c60..fd9632e56 100644
--- a/src/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj
+++ b/src/Ombi.Api.Trakt/Ombi.Api.Trakt.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api.TvMaze/Ombi.Api.TvMaze.csproj b/src/Ombi.Api.TvMaze/Ombi.Api.TvMaze.csproj
index f167146af..a1b98b765 100644
--- a/src/Ombi.Api.TvMaze/Ombi.Api.TvMaze.csproj
+++ b/src/Ombi.Api.TvMaze/Ombi.Api.TvMaze.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Api/Ombi.Api.csproj b/src/Ombi.Api/Ombi.Api.csproj
index 83c3ee62e..7670d4d14 100644
--- a/src/Ombi.Api/Ombi.Api.csproj
+++ b/src/Ombi.Api/Ombi.Api.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Core.Tests/Engine/CalendarEngineTests.cs b/src/Ombi.Core.Tests/Engine/CalendarEngineTests.cs
index b922a21c0..0a85fd058 100644
--- a/src/Ombi.Core.Tests/Engine/CalendarEngineTests.cs
+++ b/src/Ombi.Core.Tests/Engine/CalendarEngineTests.cs
@@ -10,6 +10,7 @@ using Ombi.Core.Authentication;
using Ombi.Core.Engine.V2;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository.Requests;
+using Ombi.Core.Helpers;
namespace Ombi.Core.Tests.Engine
{
@@ -25,7 +26,7 @@ namespace Ombi.Core.Tests.Engine
{
MovieRepo = new Mock();
TvRepo = new Mock();
- var principle = new Mock();
+ var principle = new Mock();
var identity = new Mock();
identity.Setup(x => x.Name).Returns("UnitTest");
principle.Setup(x => x.Identity).Returns(identity.Object);
diff --git a/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs b/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs
index 8c37aaa9a..f8ced161f 100644
--- a/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs
+++ b/src/Ombi.Core.Tests/Engine/MovieRequestEngineTests.cs
@@ -4,6 +4,7 @@ using Moq.AutoMock;
using NUnit.Framework;
using Ombi.Core.Authentication;
using Ombi.Core.Engine;
+using Ombi.Core.Helpers;
using Ombi.Core.Models.Requests;
using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests;
@@ -35,12 +36,17 @@ namespace Ombi.Core.Tests.Engine
var identity = new Mock();
identity.Setup(x => x.Name).Returns("Test");
principle.Setup(x => x.Identity).Returns(identity.Object);
+ var currentUser = new Mock();
+ currentUser.Setup(x => x.Identity).Returns(identity.Object);
+ currentUser.Setup(x => x.Username).Returns("Test");
+ currentUser.Setup(x => x.GetUser()).ReturnsAsync(new OmbiUser { NormalizedUserName = "TEST", Id = "a" });
_repoMock = new Mock();
var requestServiceMock = new Mock();
requestServiceMock.Setup(x => x.MovieRequestService).Returns(_repoMock.Object);
_mocker.Use(principle.Object);
+ _mocker.Use(currentUser.Object);
_mocker.Use(userManager.Object);
_mocker.Use(requestServiceMock);
diff --git a/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs b/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs
index f1af160d6..88e1c75d2 100644
--- a/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs
+++ b/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs
@@ -4,6 +4,7 @@ using Moq.AutoMock;
using NUnit.Framework;
using Ombi.Core.Authentication;
using Ombi.Core.Engine;
+using Ombi.Core.Helpers;
using Ombi.Core.Models;
using Ombi.Core.Services;
using Ombi.Helpers;
@@ -36,6 +37,13 @@ namespace Ombi.Core.Tests.Engine
var identityMock = new Mock();
identityMock.SetupGet(x => x.Name).Returns("Test");
principleMock.SetupGet(x => x.Identity).Returns(identityMock.Object);
+
+ var currentUser = new Mock();
+ currentUser.Setup(x => x.Identity).Returns(identityMock.Object);
+ currentUser.Setup(x => x.Username).Returns("Test");
+ currentUser.Setup(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "Test", NormalizedUserName = "TEST", Id = "a" });
+
+ _mocker.Use(currentUser.Object);
_mocker.Use(principleMock.Object);
_subject = _mocker.CreateInstance();
diff --git a/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs b/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs
index f7291409b..93dd5050d 100644
--- a/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs
+++ b/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs
@@ -4,6 +4,7 @@ using Moq.AutoMock;
using NUnit.Framework;
using Ombi.Core.Authentication;
using Ombi.Core.Engine;
+using Ombi.Core.Helpers;
using Ombi.Core.Models;
using Ombi.Core.Services;
using Ombi.Helpers;
@@ -36,7 +37,12 @@ namespace Ombi.Core.Tests.Engine
var identityMock = new Mock();
identityMock.SetupGet(x => x.Name).Returns("Test");
principleMock.SetupGet(x => x.Identity).Returns(identityMock.Object);
+ var currentUser = new Mock();
+ currentUser.Setup(x => x.Identity).Returns(identityMock.Object);
+ currentUser.Setup(x => x.Username).Returns("Test");
+ currentUser.Setup(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "Test", NormalizedUserName = "TEST", Id = "a" });
_mocker.Use(principleMock.Object);
+ _mocker.Use(currentUser.Object);
_subject = _mocker.CreateInstance();
}
diff --git a/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs b/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs
index e601ab84d..ba383da6c 100644
--- a/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs
+++ b/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs
@@ -4,6 +4,7 @@ using Moq.AutoMock;
using NUnit.Framework;
using Ombi.Core.Authentication;
using Ombi.Core.Engine;
+using Ombi.Core.Helpers;
using Ombi.Core.Models;
using Ombi.Core.Services;
using Ombi.Helpers;
@@ -33,7 +34,12 @@ namespace Ombi.Core.Tests.Engine
var identityMock = new Mock();
identityMock.SetupGet(x => x.Name).Returns("Test");
principleMock.SetupGet(x => x.Identity).Returns(identityMock.Object);
+ var currentUser = new Mock();
+ currentUser.Setup(x => x.Identity).Returns(identityMock.Object);
+ currentUser.Setup(x => x.Username).Returns("Test");
+ currentUser.Setup(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "Test", NormalizedUserName = "TEST", Id = "a" });
_mocker.Use(principleMock.Object);
+ _mocker.Use(currentUser.Object);
_subject = _mocker.CreateInstance();
}
diff --git a/src/Ombi.Core.Tests/Engine/V2/MovieRequestEngineTests.cs b/src/Ombi.Core.Tests/Engine/V2/MovieRequestEngineTests.cs
index d9f5b11be..16b7cb811 100644
--- a/src/Ombi.Core.Tests/Engine/V2/MovieRequestEngineTests.cs
+++ b/src/Ombi.Core.Tests/Engine/V2/MovieRequestEngineTests.cs
@@ -7,6 +7,7 @@ using Moq;
using NUnit.Framework;
using Ombi.Api.TheMovieDb;
using Ombi.Core.Engine;
+using Ombi.Core.Helpers;
using Ombi.Core.Models.Requests;
using Ombi.Core.Rule.Interfaces;
using Ombi.Core.Services;
@@ -33,7 +34,7 @@ namespace Ombi.Core.Tests.Engine.V2
var requestService = new Mock();
_movieRequestRepository = new Mock();
requestService.Setup(x => x.MovieRequestService).Returns(_movieRequestRepository.Object);
- var user = new Mock();
+ var user = new Mock();
var notificationHelper = new Mock();
var rules = new Mock();
var movieSender = new Mock();
diff --git a/src/Ombi.Core.Tests/Engine/V2/MusicSearchEngineV2Tests.cs b/src/Ombi.Core.Tests/Engine/V2/MusicSearchEngineV2Tests.cs
index 50ab63346..1b773f060 100644
--- a/src/Ombi.Core.Tests/Engine/V2/MusicSearchEngineV2Tests.cs
+++ b/src/Ombi.Core.Tests/Engine/V2/MusicSearchEngineV2Tests.cs
@@ -23,6 +23,7 @@ using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Ombi.Test.Common;
using Artist = Hqub.MusicBrainz.API.Entities.Artist;
+using Ombi.Core.Helpers;
namespace Ombi.Core.Tests.Engine.V2
{
@@ -45,7 +46,7 @@ namespace Ombi.Core.Tests.Engine.V2
.ForEach(b => F.Behaviors.Remove(b));
F.Behaviors.Add(new OmitOnRecursionBehavior());
- var principle = new Mock();
+ var principle = new Mock();
var requestService = new Mock();
var ruleEval = new Mock();
var um = MockHelper.MockUserManager(new List());
diff --git a/src/Ombi.Core.Tests/Engine/VoteEngineTests.cs b/src/Ombi.Core.Tests/Engine/VoteEngineTests.cs
index 1269cd2bc..4194ae0ea 100644
--- a/src/Ombi.Core.Tests/Engine/VoteEngineTests.cs
+++ b/src/Ombi.Core.Tests/Engine/VoteEngineTests.cs
@@ -9,6 +9,7 @@ using NUnit.Framework;
using Ombi.Core.Authentication;
using Ombi.Core.Engine;
using Ombi.Core.Engine.Interfaces;
+using Ombi.Core.Helpers;
using Ombi.Core.Models;
using Ombi.Core.Rule.Interfaces;
using Ombi.Core.Settings;
@@ -32,8 +33,9 @@ namespace Ombi.Core.Tests.Engine
TvRequestEngine = new Mock();
MovieRequestEngine = new Mock();
MovieRequestEngine = new Mock();
- User = new Mock();
- User.Setup(x => x.Identity.Name).Returns("abc");
+ User = new Mock();
+ User.Setup(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "abc", NormalizedUserName = "ABC", Id = "abc" });
+
UserManager = MockHelper.MockUserManager(new List { new OmbiUser { Id = "abc", UserName = "abc", NormalizedUserName = "ABC" } });
Rule = new Mock();
Engine = new VoteEngine(VoteRepository.Object, User.Object, UserManager.Object, Rule.Object, VoteSettings.Object, MusicRequestEngine.Object,
@@ -48,7 +50,7 @@ namespace Ombi.Core.Tests.Engine
public Fixture F { get; set; }
public VoteEngine Engine { get; set; }
- public Mock User { get; set; }
+ public Mock User { get; set; }
public Mock UserManager { get; set; }
public Mock Rule { get; set; }
public Mock> VoteRepository { get; set; }
diff --git a/src/Ombi.Core.Tests/Rule/Request/AutoApproveRuleTests.cs b/src/Ombi.Core.Tests/Rule/Request/AutoApproveRuleTests.cs
index 9633249d4..c73237097 100644
--- a/src/Ombi.Core.Tests/Rule/Request/AutoApproveRuleTests.cs
+++ b/src/Ombi.Core.Tests/Rule/Request/AutoApproveRuleTests.cs
@@ -11,6 +11,7 @@ using System.Collections.Generic;
using Ombi.Store.Entities;
using System;
using Ombi.Core.Services;
+using Ombi.Core.Helpers;
namespace Ombi.Core.Tests.Rule.Request
{
@@ -27,17 +28,18 @@ namespace Ombi.Core.Tests.Rule.Request
public void Setup()
{
- PrincipalMock = new Mock();
- PrincipalMock.Setup(x => x.Identity.Name).Returns("abc");
FeatureService = new Mock();
+ PrincipalMock = new Mock();
+ PrincipalMock.Setup(x => x.Username).Returns("abc");
+ PrincipalMock.Setup(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "abc", NormalizedUserName = "ABC", Id = "a" });
+
UserManager = MockHelper.MockUserManager(_users);
Rule = new AutoApproveRule(PrincipalMock.Object, UserManager.Object, FeatureService.Object);
}
-
private AutoApproveRule Rule { get; set; }
- private Mock PrincipalMock { get; set; }
+ private Mock PrincipalMock { get; set; }
private Mock UserManager { get; set; }
private Mock FeatureService { get; set; }
@@ -99,7 +101,8 @@ namespace Ombi.Core.Tests.Rule.Request
[Test]
public async Task Should_ReturnSuccess_WhenSystemUserAndRequestTV()
{
- PrincipalMock.Setup(x => x.Identity.Name).Returns("sys");
+ PrincipalMock.Setup(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "sys", NormalizedUserName = "SYS", Id = "a" });
+
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny(), OmbiRoles.AutoApproveTv)).ReturnsAsync(false);
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.TvShow };
var result = await Rule.Execute(request);
diff --git a/src/Ombi.Core.Tests/Rule/Request/CanRequestRuleTests.cs b/src/Ombi.Core.Tests/Rule/Request/CanRequestRuleTests.cs
index f601689dc..9d8db25d1 100644
--- a/src/Ombi.Core.Tests/Rule/Request/CanRequestRuleTests.cs
+++ b/src/Ombi.Core.Tests/Rule/Request/CanRequestRuleTests.cs
@@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using Ombi.Core.Authentication;
+using Ombi.Core.Helpers;
using Ombi.Core.Rule.Rules;
using Ombi.Core.Rule.Rules.Request;
using Ombi.Helpers;
@@ -26,8 +27,9 @@ namespace Ombi.Core.Tests.Rule.Request
public void Setup()
{
- PrincipalMock = new Mock();
- PrincipalMock.Setup(x => x.Identity.Name).Returns("abc");
+ PrincipalMock = new Mock();
+ PrincipalMock.Setup(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "abc", NormalizedUserName = "ABC", Id = "a" });
+
UserManager = MockHelper.MockUserManager(_users);
Rule = new CanRequestRule(PrincipalMock.Object, UserManager.Object);
@@ -35,7 +37,7 @@ namespace Ombi.Core.Tests.Rule.Request
private CanRequestRule Rule { get; set; }
- private Mock PrincipalMock { get; set; }
+ private Mock PrincipalMock { get; set; }
private Mock UserManager { get; set; }
[Test]
@@ -107,7 +109,8 @@ namespace Ombi.Core.Tests.Rule.Request
[Test]
public async Task Should_ReturnSuccess_WhenRequestingMovieWithSystemRole()
{
- PrincipalMock.Setup(x => x.Identity.Name).Returns("sys");
+ PrincipalMock.Setup(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "sys", NormalizedUserName = "SYS", Id = "a" });
+
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny(), OmbiRoles.Admin)).ReturnsAsync(false);
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
var result = await Rule.Execute(request);
diff --git a/src/Ombi.Core/Authentication/OmbiUserManager.cs b/src/Ombi.Core/Authentication/OmbiUserManager.cs
index 87f82c1de..124ff1aeb 100644
--- a/src/Ombi.Core/Authentication/OmbiUserManager.cs
+++ b/src/Ombi.Core/Authentication/OmbiUserManager.cs
@@ -116,16 +116,25 @@ namespace Ombi.Core.Authentication
public async Task GetOmbiUserFromPlexToken(string plexToken)
{
var plexAccount = await _plexApi.GetAccount(plexToken);
-
+
// Check for a ombi user
- if (plexAccount?.user != null)
+ if (plexAccount?.user == null)
+ {
+ return null;
+ }
+
+ var potentialOmbiUser = await Users.FirstOrDefaultAsync(x =>
+ x.ProviderUserId == plexAccount.user.id);
+ // Update ombi user with the token
+
+ if (potentialOmbiUser != null)
{
- var potentialOmbiUser = await Users.FirstOrDefaultAsync(x =>
- x.ProviderUserId == plexAccount.user.id);
- return potentialOmbiUser;
+ potentialOmbiUser.MediaServerToken = plexAccount.user.authentication_token;
+ await UpdateAsync(potentialOmbiUser);
}
- return null;
+ return potentialOmbiUser;
+
}
@@ -142,6 +151,10 @@ namespace Ombi.Core.Authentication
var result = await _plexApi.SignIn(new UserRequest { password = password, login = login });
if (result.user?.authentication_token != null)
{
+ // Update ombi user with the token
+ user.MediaServerToken = result.user?.authentication_token;
+ await UpdateAsync(user);
+
return true;
}
return false;
diff --git a/src/Ombi.Core/Engine/BaseMediaEngine.cs b/src/Ombi.Core/Engine/BaseMediaEngine.cs
index 277144ab1..ee1ce55a8 100644
--- a/src/Ombi.Core/Engine/BaseMediaEngine.cs
+++ b/src/Ombi.Core/Engine/BaseMediaEngine.cs
@@ -26,7 +26,7 @@ namespace Ombi.Core.Engine
private Dictionary _dbMovies;
private Dictionary _dbTv;
- protected BaseMediaEngine(IPrincipal identity, IRequestServiceMain requestService,
+ protected BaseMediaEngine(ICurrentUser identity, IRequestServiceMain requestService,
IRuleEvaluator rules, OmbiUserManager um, ICacheService cache, ISettingsService ombiSettings, IRepository sub) : base(identity, um, rules)
{
RequestService = requestService;
diff --git a/src/Ombi.Core/Engine/Demo/DemoMovieSearchEngine.cs b/src/Ombi.Core/Engine/Demo/DemoMovieSearchEngine.cs
index f392bf7ad..af88813d9 100644
--- a/src/Ombi.Core/Engine/Demo/DemoMovieSearchEngine.cs
+++ b/src/Ombi.Core/Engine/Demo/DemoMovieSearchEngine.cs
@@ -11,6 +11,7 @@ using Ombi.Api.TheMovieDb;
using Ombi.Api.TheMovieDb.Models;
using Ombi.Config;
using Ombi.Core.Authentication;
+using Ombi.Core.Helpers;
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search;
using Ombi.Core.Rule.Interfaces;
@@ -24,7 +25,7 @@ namespace Ombi.Core.Engine.Demo
{
public class DemoMovieSearchEngine : MovieSearchEngine, IDemoMovieSearchEngine
{
- public DemoMovieSearchEngine(IPrincipal identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
+ public DemoMovieSearchEngine(ICurrentUser identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
ILogger logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService s,
IRepository sub, IOptions lists)
: base(identity, service, movApi, mapper, logger, r, um, mem, s, sub)
diff --git a/src/Ombi.Core/Engine/Demo/DemoTvSearchEngine.cs b/src/Ombi.Core/Engine/Demo/DemoTvSearchEngine.cs
index 2c91a458f..706a5337d 100644
--- a/src/Ombi.Core/Engine/Demo/DemoTvSearchEngine.cs
+++ b/src/Ombi.Core/Engine/Demo/DemoTvSearchEngine.cs
@@ -4,6 +4,7 @@ using Ombi.Api.Trakt;
using Ombi.Api.TvMaze;
using Ombi.Config;
using Ombi.Core.Authentication;
+using Ombi.Core.Helpers;
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search;
using Ombi.Core.Rule.Interfaces;
@@ -24,7 +25,7 @@ namespace Ombi.Core.Engine.Demo
public class DemoTvSearchEngine : TvSearchEngine, IDemoTvSearchEngine
{
- public DemoTvSearchEngine(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
+ public DemoTvSearchEngine(ICurrentUser identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um, ICacheService memCache,
ISettingsService s, IRepository sub, IOptions lists, IImageService imageService,
ISettingsService custom)
diff --git a/src/Ombi.Core/Engine/Interfaces/BaseEngine.cs b/src/Ombi.Core/Engine/Interfaces/BaseEngine.cs
index 42aff9a61..2c68ea371 100644
--- a/src/Ombi.Core/Engine/Interfaces/BaseEngine.cs
+++ b/src/Ombi.Core/Engine/Interfaces/BaseEngine.cs
@@ -1,42 +1,35 @@
using System;
using Ombi.Core.Rule;
using System.Collections.Generic;
-using System.Security.Principal;
using System.Threading.Tasks;
using Ombi.Core.Models.Search;
using Ombi.Core.Rule.Interfaces;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Entities;
-using Microsoft.EntityFrameworkCore;
using Ombi.Core.Authentication;
-using Ombi.Helpers;
+using Ombi.Core.Helpers;
namespace Ombi.Core.Engine.Interfaces
{
public abstract class BaseEngine
{
- protected BaseEngine(IPrincipal user, OmbiUserManager um, IRuleEvaluator rules)
+ protected BaseEngine(ICurrentUser user, OmbiUserManager um, IRuleEvaluator rules)
{
- UserPrinciple = user;
+ CurrentUser = user;
Rules = rules;
UserManager = um;
}
- protected IPrincipal UserPrinciple { get; }
+ protected ICurrentUser CurrentUser { get; }
protected IRuleEvaluator Rules { get; }
- protected OmbiUserManager UserManager { get; }
- protected string Username => UserPrinciple.Identity.Name;
+ protected OmbiUserManager UserManager { get; }
+ protected string Username => CurrentUser.Username;
+ protected Task GetUser() => CurrentUser.GetUser();
- private OmbiUser _user;
- protected async Task GetUser()
- {
- if(!Username.HasValue())
- {
- return null;
- }
- var username = Username.ToUpper();
- return _user ??= await UserManager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username);
- }
+ ///
+ /// Only used for background tasks
+ ///
+ public void SetUser(OmbiUser user) => CurrentUser.SetUser(user);
protected async Task UserAlias()
{
@@ -52,7 +45,7 @@ namespace Ombi.Core.Engine.Interfaces
var user = await GetUser();
return await UserManager.IsInRoleAsync(user, roleName);
}
-
+
public async Task> RunRequestRules(BaseRequest model)
{
var ruleResults = await Rules.StartRequestRules(model);
diff --git a/src/Ombi.Core/Engine/Interfaces/IRequestEngine.cs b/src/Ombi.Core/Engine/Interfaces/IRequestEngine.cs
index d0fc04b10..01300287e 100644
--- a/src/Ombi.Core/Engine/Interfaces/IRequestEngine.cs
+++ b/src/Ombi.Core/Engine/Interfaces/IRequestEngine.cs
@@ -25,5 +25,6 @@ namespace Ombi.Core.Engine.Interfaces
Task UnSubscribeRequest(int requestId, RequestType type);
Task SubscribeToRequest(int requestId, RequestType type);
Task ReProcessRequest(int requestId, bool is4K, CancellationToken cancellationToken);
+ void SetUser(OmbiUser user);
}
}
\ No newline at end of file
diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs
index 498cf3e0b..6e81e3e73 100644
--- a/src/Ombi.Core/Engine/MovieRequestEngine.cs
+++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs
@@ -23,12 +23,13 @@ using Ombi.Store.Repository;
using Ombi.Core.Models;
using System.Threading;
using Ombi.Core.Services;
+using Ombi.Core.Helpers;
namespace Ombi.Core.Engine
{
public class MovieRequestEngine : BaseMediaEngine, IMovieRequestEngine
{
- public MovieRequestEngine(IMovieDbApi movieApi, IRequestServiceMain requestService, IPrincipal user,
+ public MovieRequestEngine(IMovieDbApi movieApi, IRequestServiceMain requestService, ICurrentUser user,
INotificationHelper helper, IRuleEvaluator r, IMovieSender sender, ILogger log,
OmbiUserManager manager, IRepository rl, ICacheService cache,
ISettingsService ombiSettings, IRepository sub, IMediaCacheService mediaCacheService,
@@ -142,7 +143,8 @@ namespace Ombi.Core.Engine
RootPathOverride = model.RootFolderOverride.GetValueOrDefault(),
QualityOverride = model.QualityPathOverride.GetValueOrDefault(),
RequestedDate4k = model.Is4kRequest ? DateTime.Now : DateTime.MinValue,
- Is4kRequest = model.Is4kRequest
+ Is4kRequest = model.Is4kRequest,
+ Source = model.Source
};
}
diff --git a/src/Ombi.Core/Engine/MovieSearchEngine.cs b/src/Ombi.Core/Engine/MovieSearchEngine.cs
index 7d84a0b40..682a999eb 100644
--- a/src/Ombi.Core/Engine/MovieSearchEngine.cs
+++ b/src/Ombi.Core/Engine/MovieSearchEngine.cs
@@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging;
using Ombi.Api.TheMovieDb;
using Ombi.Api.TheMovieDb.Models;
using Ombi.Core.Authentication;
+using Ombi.Core.Helpers;
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search;
using Ombi.Core.Rule.Interfaces;
@@ -22,7 +23,7 @@ namespace Ombi.Core.Engine
{
public class MovieSearchEngine : BaseMediaEngine, IMovieEngine
{
- public MovieSearchEngine(IPrincipal identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
+ public MovieSearchEngine(ICurrentUser identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
ILogger logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService s, IRepository sub)
: base(identity, service, r, um, mem, s, sub)
{
diff --git a/src/Ombi.Core/Engine/MusicRequestEngine.cs b/src/Ombi.Core/Engine/MusicRequestEngine.cs
index b9aa183d2..640d2ade3 100644
--- a/src/Ombi.Core/Engine/MusicRequestEngine.cs
+++ b/src/Ombi.Core/Engine/MusicRequestEngine.cs
@@ -24,12 +24,13 @@ using Ombi.Settings.Settings.Models.External;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository;
using System.ComponentModel;
+using Ombi.Core.Helpers;
namespace Ombi.Core.Engine
{
public class MusicRequestEngine : BaseMediaEngine, IMusicRequestEngine
{
- public MusicRequestEngine(IRequestServiceMain requestService, IPrincipal user,
+ public MusicRequestEngine(IRequestServiceMain requestService, ICurrentUser user,
INotificationHelper helper, IRuleEvaluator r, ILogger log,
OmbiUserManager manager, IRepository rl, ICacheService cache,
ISettingsService ombiSettings, IRepository sub, ILidarrApi lidarr,
diff --git a/src/Ombi.Core/Engine/MusicSearchEngine.cs b/src/Ombi.Core/Engine/MusicSearchEngine.cs
index 89bae7069..2602bf71e 100644
--- a/src/Ombi.Core/Engine/MusicSearchEngine.cs
+++ b/src/Ombi.Core/Engine/MusicSearchEngine.cs
@@ -27,7 +27,7 @@ namespace Ombi.Core.Engine
{
public class MusicSearchEngine : BaseMediaEngine, IMusicSearchEngine
{
- public MusicSearchEngine(IPrincipal identity, IRequestServiceMain service, ILidarrApi lidarrApi, IMapper mapper,
+ public MusicSearchEngine(ICurrentUser identity, IRequestServiceMain service, ILidarrApi lidarrApi, IMapper mapper,
ILogger logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService s, IRepository sub,
ISettingsService lidarrSettings)
: base(identity, service, r, um, mem, s, sub)
diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs
index 4b46e8151..5664d276f 100644
--- a/src/Ombi.Core/Engine/TvRequestEngine.cs
+++ b/src/Ombi.Core/Engine/TvRequestEngine.cs
@@ -32,7 +32,7 @@ namespace Ombi.Core.Engine
{
public class TvRequestEngine : BaseMediaEngine, ITvRequestEngine
{
- public TvRequestEngine(ITvMazeApi tvApi, IMovieDbApi movApi, IRequestServiceMain requestService, IPrincipal user,
+ public TvRequestEngine(ITvMazeApi tvApi, IMovieDbApi movApi, IRequestServiceMain requestService, ICurrentUser user,
INotificationHelper helper, IRuleEvaluator rule, OmbiUserManager manager, ILogger logger,
ITvSender sender, IRepository rl, ISettingsService settings, ICacheService cache,
IRepository sub, IMediaCacheService mediaCacheService) : base(user, requestService, rule, manager, cache, settings, sub)
@@ -188,7 +188,7 @@ namespace Ombi.Core.Engine
(await tvBuilder
.GetShowInfo(tv.TheMovieDbId, tv.languageCode))
.CreateTvList(tv)
- .CreateChild(tv, canRequestOnBehalf ? tv.RequestOnBehalf : user.Id);
+ .CreateChild(tv, canRequestOnBehalf ? tv.RequestOnBehalf : user.Id, tv.Source);
await tvBuilder.BuildEpisodes(tv);
diff --git a/src/Ombi.Core/Engine/TvSearchEngine.cs b/src/Ombi.Core/Engine/TvSearchEngine.cs
index 518b97720..2747f262a 100644
--- a/src/Ombi.Core/Engine/TvSearchEngine.cs
+++ b/src/Ombi.Core/Engine/TvSearchEngine.cs
@@ -23,6 +23,7 @@ using Ombi.Api.TheMovieDb;
using Ombi.Api.TheMovieDb.Models;
using System.Threading;
using TraktSharp.Entities;
+using Ombi.Core.Helpers;
namespace Ombi.Core.Engine
{
@@ -32,7 +33,7 @@ namespace Ombi.Core.Engine
private readonly IImageService _imageService;
private readonly IMovieDbApi _theMovieDbApi;
- public TvSearchEngine(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
+ public TvSearchEngine(ICurrentUser identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um, ISettingsService customizationSettings,
ICacheService memCache, ISettingsService s, IRepository sub, IImageService imageService,
IMovieDbApi theMovieDbApi)
diff --git a/src/Ombi.Core/Engine/V2/CalendarEngine.cs b/src/Ombi.Core/Engine/V2/CalendarEngine.cs
index b7ecc8ec6..8347141bb 100644
--- a/src/Ombi.Core/Engine/V2/CalendarEngine.cs
+++ b/src/Ombi.Core/Engine/V2/CalendarEngine.cs
@@ -5,6 +5,7 @@ using System.Security.Principal;
using System.Threading.Tasks;
using Ombi.Core.Authentication;
using Ombi.Core.Engine.Interfaces;
+using Ombi.Core.Helpers;
using Ombi.Core.Models.Search.V2;
using Ombi.Core.Rule.Interfaces;
using Ombi.Store.Entities;
@@ -17,7 +18,7 @@ namespace Ombi.Core.Engine.V2
{
public DateTime DaysAgo => DateTime.Now.AddDays(-90);
public DateTime DaysAhead => DateTime.Now.AddDays(90);
- public CalendarEngine(IPrincipal user, OmbiUserManager um, IRuleEvaluator rules, IMovieRequestRepository movieRepo,
+ public CalendarEngine(ICurrentUser user, OmbiUserManager um, IRuleEvaluator rules, IMovieRequestRepository movieRepo,
ITvRequestRepository tvRequestRepo) : base(user, um, rules)
{
_movieRepo = movieRepo;
diff --git a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs
index 576b511fa..3acd7d1f0 100644
--- a/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs
+++ b/src/Ombi.Core/Engine/V2/MovieSearchEngineV2.cs
@@ -5,6 +5,7 @@ using Ombi.Api.TheMovieDb;
using Ombi.Api.TheMovieDb.Models;
using Ombi.Core.Authentication;
using Ombi.Core.Engine.Interfaces;
+using Ombi.Core.Helpers;
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search;
using Ombi.Core.Models.Search.V2;
@@ -28,7 +29,7 @@ namespace Ombi.Core.Engine.V2
{
public class MovieSearchEngineV2 : BaseMediaEngine, IMovieEngineV2
{
- public MovieSearchEngineV2(IPrincipal identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
+ public MovieSearchEngineV2(ICurrentUser identity, IRequestServiceMain service, IMovieDbApi movApi, IMapper mapper,
ILogger logger, IRuleEvaluator r, OmbiUserManager um, ICacheService mem, ISettingsService s, IRepository sub,
ISettingsService customizationSettings, IMovieRequestEngine movieRequestEngine, IHttpClientFactory httpClientFactory)
: base(identity, service, r, um, mem, s, sub)
diff --git a/src/Ombi.Core/Engine/V2/MultiSearchEngine.cs b/src/Ombi.Core/Engine/V2/MultiSearchEngine.cs
index 44f792415..362a79e43 100644
--- a/src/Ombi.Core/Engine/V2/MultiSearchEngine.cs
+++ b/src/Ombi.Core/Engine/V2/MultiSearchEngine.cs
@@ -7,6 +7,7 @@ using Ombi.Api.MusicBrainz;
using Ombi.Api.TheMovieDb;
using Ombi.Api.TheMovieDb.Models;
using Ombi.Core.Authentication;
+using Ombi.Core.Helpers;
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search.V2;
using Ombi.Core.Rule.Interfaces;
@@ -25,7 +26,7 @@ namespace Ombi.Core.Engine.V2
{
public class MultiSearchEngine : BaseMediaEngine, IMultiSearchEngine
{
- public MultiSearchEngine(IPrincipal identity, IRequestServiceMain requestService, IRuleEvaluator rules,
+ public MultiSearchEngine(ICurrentUser identity, IRequestServiceMain requestService, IRuleEvaluator rules,
OmbiUserManager um, ICacheService cache, ISettingsService ombiSettings, IRepository sub,
IMovieDbApi movieDbApi, ISettingsService lidarrSettings, IMusicBrainzApi musicApi)
: base(identity, requestService, rules, um, cache, ombiSettings, sub)
diff --git a/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs
index b7d9575db..fc3fcf40e 100644
--- a/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs
+++ b/src/Ombi.Core/Engine/V2/MusicSearchEngineV2.cs
@@ -11,6 +11,7 @@ using Ombi.Api.Lidarr.Models;
using Ombi.Api.MusicBrainz;
using Ombi.Core.Authentication;
using Ombi.Core.Engine.Interfaces;
+using Ombi.Core.Helpers;
using Ombi.Core.Models.Requests;
using Ombi.Core.Models.Search.V2.Music;
using Ombi.Core.Rule.Interfaces;
@@ -31,7 +32,7 @@ namespace Ombi.Core.Engine.V2
private readonly ISettingsService _lidarrSettings;
private readonly ILidarrApi _lidarrApi;
- public MusicSearchEngineV2(IPrincipal identity, IRequestServiceMain requestService, IRuleEvaluator rules,
+ public MusicSearchEngineV2(ICurrentUser identity, IRequestServiceMain requestService, IRuleEvaluator rules,
OmbiUserManager um, ICacheService cache, ISettingsService ombiSettings,
IRepository sub, IMusicBrainzApi musicBrainzApi, ISettingsService lidarrSettings,
ILidarrApi lidarrApi)
diff --git a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs
index 07f8ce981..46cd44bf1 100644
--- a/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs
+++ b/src/Ombi.Core/Engine/V2/TvSearchEngineV2.cs
@@ -25,6 +25,7 @@ using Ombi.Api.TheMovieDb.Models;
using System.Diagnostics;
using Ombi.Core.Engine.Interfaces;
using Ombi.Core.Models.UI;
+using Ombi.Core.Helpers;
namespace Ombi.Core.Engine.V2
{
@@ -37,7 +38,7 @@ namespace Ombi.Core.Engine.V2
private readonly ISettingsService _customization;
private readonly ITvRequestEngine _requestEngine;
- public TvSearchEngineV2(IPrincipal identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
+ public TvSearchEngineV2(ICurrentUser identity, IRequestServiceMain service, ITvMazeApi tvMaze, IMapper mapper,
ITraktApi trakt, IRuleEvaluator r, OmbiUserManager um, ICacheService memCache, ISettingsService s,
IRepository sub, IMovieDbApi movieApi, ISettingsService customization, ITvRequestEngine requestEngine)
: base(identity, service, r, um, memCache, s, sub)
diff --git a/src/Ombi.Core/Engine/VoteEngine.cs b/src/Ombi.Core/Engine/VoteEngine.cs
index a63ba1604..3e7f6f542 100644
--- a/src/Ombi.Core/Engine/VoteEngine.cs
+++ b/src/Ombi.Core/Engine/VoteEngine.cs
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Authentication;
using Ombi.Core.Engine.Interfaces;
+using Ombi.Core.Helpers;
using Ombi.Core.Models;
using Ombi.Core.Models.UI;
using Ombi.Core.Rule.Interfaces;
@@ -20,7 +21,7 @@ namespace Ombi.Core.Engine
{
public class VoteEngine : BaseEngine, IVoteEngine
{
- public VoteEngine(IRepository votes, IPrincipal user, OmbiUserManager um, IRuleEvaluator r, ISettingsService voteSettings,
+ public VoteEngine(IRepository votes, ICurrentUser user, OmbiUserManager um, IRuleEvaluator r, ISettingsService voteSettings,
IMusicRequestEngine musicRequestEngine, ITvRequestEngine tvRequestEngine, IMovieRequestEngine movieRequestEngine) : base(user, um, r)
{
_voteRepository = votes;
diff --git a/src/Ombi.Core/Helpers/CurrentUser.cs b/src/Ombi.Core/Helpers/CurrentUser.cs
new file mode 100644
index 000000000..974d59cd6
--- /dev/null
+++ b/src/Ombi.Core/Helpers/CurrentUser.cs
@@ -0,0 +1,47 @@
+using Microsoft.EntityFrameworkCore;
+using Ombi.Core.Authentication;
+using Ombi.Helpers;
+using Ombi.Store.Entities;
+using System.Security.Principal;
+using System.Threading.Tasks;
+
+namespace Ombi.Core.Helpers
+{
+ public class CurrentUser : ICurrentUser
+ {
+ private readonly IPrincipal _principle;
+ private readonly OmbiUserManager _userManager;
+ private OmbiUser _user;
+ public IIdentity Identity { get; set; }
+
+ public CurrentUser(IPrincipal principle, OmbiUserManager userManager)
+ {
+ _principle = principle;
+ _userManager = userManager;
+ Identity = _principle?.Identity ?? null;
+ }
+
+ public void SetUser(OmbiUser user)
+ {
+ _user = user;
+ }
+
+ public string Username => Identity?.Name ?? _user?.UserName;
+ public async Task GetUser()
+ {
+ if (!Username.HasValue() && _user == null)
+ {
+ return null;
+ }
+
+ if (_user != null)
+ {
+ return _user;
+ }
+
+ var username = Username.ToUpper();
+ return _user ??= await _userManager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username);
+ }
+
+ }
+}
diff --git a/src/Ombi.Core/Helpers/ICurrentUser.cs b/src/Ombi.Core/Helpers/ICurrentUser.cs
new file mode 100644
index 000000000..1cce973f3
--- /dev/null
+++ b/src/Ombi.Core/Helpers/ICurrentUser.cs
@@ -0,0 +1,15 @@
+using Ombi.Store.Entities;
+using System.Security.Principal;
+using System.Threading.Tasks;
+
+namespace Ombi.Core.Helpers
+{
+ public interface ICurrentUser
+ {
+ string Username { get; }
+
+ Task GetUser();
+ void SetUser(OmbiUser user);
+ IIdentity Identity { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/src/Ombi.Core/Helpers/TvShowRequestBuilderV2.cs b/src/Ombi.Core/Helpers/TvShowRequestBuilderV2.cs
index 6843332c0..4053109da 100644
--- a/src/Ombi.Core/Helpers/TvShowRequestBuilderV2.cs
+++ b/src/Ombi.Core/Helpers/TvShowRequestBuilderV2.cs
@@ -53,7 +53,7 @@ namespace Ombi.Core.Helpers
return this;
}
- public TvShowRequestBuilderV2 CreateChild(TvRequestViewModelV2 model, string userId)
+ public TvShowRequestBuilderV2 CreateChild(TvRequestViewModelV2 model, string userId, RequestSource source)
{
var animationGenre = TheMovieDbRecord.genres?.Any(s => s.name.Equals("Animation", StringComparison.InvariantCultureIgnoreCase)) ?? false;
var animeKeyword = TheMovieDbRecord.Keywords?.KeywordsValue?.Any(s => s.Name.Equals("Anime", StringComparison.InvariantCultureIgnoreCase)) ?? false;
@@ -68,7 +68,8 @@ namespace Ombi.Core.Helpers
Title = TheMovieDbRecord.name,
ReleaseYear = FirstAir,
RequestedByAlias = model.RequestedByAlias,
- SeriesType = animationGenre && animeKeyword ? SeriesType.Anime : SeriesType.Standard
+ SeriesType = animationGenre && animeKeyword ? SeriesType.Anime : SeriesType.Standard,
+ Source = source
};
return this;
diff --git a/src/Ombi.Core/Models/Requests/MovieRequestViewModel.cs b/src/Ombi.Core/Models/Requests/MovieRequestViewModel.cs
index 39a5b6c2a..18125ed71 100644
--- a/src/Ombi.Core/Models/Requests/MovieRequestViewModel.cs
+++ b/src/Ombi.Core/Models/Requests/MovieRequestViewModel.cs
@@ -1,31 +1,5 @@
-#region Copyright
-// /************************************************************************
-// Copyright (c) 2018 Jamie Rees
-// File: MovieRequestViewModel.cs
-// Created By: Jamie Rees
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-// ************************************************************************/
-#endregion
-
-using Newtonsoft.Json;
+using Newtonsoft.Json;
+using Ombi.Store.Entities.Requests;
namespace Ombi.Core.Models.Requests
{
@@ -41,5 +15,11 @@ namespace Ombi.Core.Models.Requests
///
[JsonIgnore]
public string RequestedByAlias { get; set; }
+
+ ///
+ /// Only set via list imports
+ ///
+ [JsonIgnore]
+ public RequestSource Source { get; set; } = RequestSource.Ombi;
}
}
\ No newline at end of file
diff --git a/src/Ombi.Core/Models/Requests/TvRequestViewModelV2.cs b/src/Ombi.Core/Models/Requests/TvRequestViewModelV2.cs
index a9742fb32..e1df9553f 100644
--- a/src/Ombi.Core/Models/Requests/TvRequestViewModelV2.cs
+++ b/src/Ombi.Core/Models/Requests/TvRequestViewModelV2.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Newtonsoft.Json;
+using Ombi.Store.Entities.Requests;
namespace Ombi.Core.Models.Requests
{
@@ -7,5 +8,6 @@ namespace Ombi.Core.Models.Requests
{
public int TheMovieDbId { get; set; }
public string languageCode { get; set; } = "en";
+ public RequestSource Source { get; set; } = RequestSource.Ombi;
}
}
\ No newline at end of file
diff --git a/src/Ombi.Core/Ombi.Core.csproj b/src/Ombi.Core/Ombi.Core.csproj
index 0f7ca6845..67ecdbe13 100644
--- a/src/Ombi.Core/Ombi.Core.csproj
+++ b/src/Ombi.Core/Ombi.Core.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Core/Rule/Rules/Request/AutoApproveRule.cs b/src/Ombi.Core/Rule/Rules/Request/AutoApproveRule.cs
index 92c1b11a7..23d26625b 100644
--- a/src/Ombi.Core/Rule/Rules/Request/AutoApproveRule.cs
+++ b/src/Ombi.Core/Rule/Rules/Request/AutoApproveRule.cs
@@ -3,6 +3,7 @@ using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Authentication;
+using Ombi.Core.Helpers;
using Ombi.Core.Models.Requests;
using Ombi.Core.Rule.Interfaces;
using Ombi.Core.Services;
@@ -15,20 +16,21 @@ namespace Ombi.Core.Rule.Rules.Request
{
public class AutoApproveRule : BaseRequestRule, IRules
{
- public AutoApproveRule(IPrincipal principal, OmbiUserManager um, IFeatureService featureService)
+ public AutoApproveRule(ICurrentUser principal, OmbiUserManager um, IFeatureService featureService)
{
User = principal;
_manager = um;
_featureService = featureService;
}
- private IPrincipal User { get; }
+ private ICurrentUser User { get; }
private readonly OmbiUserManager _manager;
private readonly IFeatureService _featureService;
public async Task Execute(BaseRequest obj)
{
- var username = User.Identity.Name.ToUpper();
+ var currentUser = await User.GetUser();
+ var username = currentUser.UserName.ToUpper();
var user = await _manager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username);
if (await _manager.IsInRoleAsync(user, OmbiRoles.Admin) || user.IsSystemUser)
{
diff --git a/src/Ombi.Core/Rule/Rules/Request/CanRequestRule.cs b/src/Ombi.Core/Rule/Rules/Request/CanRequestRule.cs
index 2546e1f29..e2e81e612 100644
--- a/src/Ombi.Core/Rule/Rules/Request/CanRequestRule.cs
+++ b/src/Ombi.Core/Rule/Rules/Request/CanRequestRule.cs
@@ -10,23 +10,25 @@ using Ombi.Core.Engine;
using Ombi.Core.Rule.Interfaces;
using Ombi.Helpers;
using Ombi.Store.Entities.Requests;
+using Ombi.Core.Helpers;
namespace Ombi.Core.Rule.Rules.Request
{
public class CanRequestRule : BaseRequestRule, IRules
{
- public CanRequestRule(IPrincipal principal, OmbiUserManager manager)
+ public CanRequestRule(ICurrentUser principal, OmbiUserManager manager)
{
User = principal;
_manager = manager;
}
- private IPrincipal User { get; }
+ private ICurrentUser User { get; }
private readonly OmbiUserManager _manager;
public async Task Execute(BaseRequest obj)
{
- var username = User.Identity.Name.ToUpper();
+ var currentUser = await User.GetUser();
+ var username = currentUser.UserName.ToUpper();
var user = await _manager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username);
if (await _manager.IsInRoleAsync(user, OmbiRoles.Admin) || user.IsSystemUser)
return Success();
diff --git a/src/Ombi.Core/Services/RequestLimitService.cs b/src/Ombi.Core/Services/RequestLimitService.cs
index 83a87c7e7..d90e0d77c 100644
--- a/src/Ombi.Core/Services/RequestLimitService.cs
+++ b/src/Ombi.Core/Services/RequestLimitService.cs
@@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Authentication;
+using Ombi.Core.Helpers;
using Ombi.Core.Models;
using Ombi.Helpers;
using Ombi.Store.Entities;
@@ -20,11 +21,11 @@ namespace Ombi.Core.Services
}
public class RequestLimitService : IRequestLimitService
{
- private readonly IPrincipal _user;
+ private readonly ICurrentUser _user;
private readonly OmbiUserManager _userManager;
private readonly IRepository _requestLog;
- public RequestLimitService(IPrincipal user, OmbiUserManager userManager, IRepository rl)
+ public RequestLimitService(ICurrentUser user, OmbiUserManager userManager, IRepository rl)
{
_user = user;
_userManager = userManager;
@@ -141,7 +142,8 @@ namespace Ombi.Core.Services
private async Task GetUser()
{
- var username = _user.Identity.Name.ToUpper();
+ var currentUser = await _user.GetUser();
+ var username = currentUser.UserName.ToUpper();
return await _userManager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username);
}
diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs
index 3fb5cd643..691aca237 100644
--- a/src/Ombi.DependencyInjection/IocExtensions.cs
+++ b/src/Ombi.DependencyInjection/IocExtensions.cs
@@ -70,6 +70,7 @@ using Ombi.Api.RottenTomatoes;
using System.Net.Http;
using Microsoft.Extensions.Logging;
using Ombi.Core.Services;
+using Ombi.Core.Helpers;
namespace Ombi.DependencyInjection
{
@@ -124,6 +125,8 @@ namespace Ombi.DependencyInjection
var runtimeVersion = AssemblyHelper.GetRuntimeVersion();
services.AddSingleton();
services.AddScoped(sp => sp.GetService().HttpContext.User);
+ // HttpContext User is null for background jobs
+ services.AddScoped(sp => new CurrentUser(sp.GetService()?.HttpContext?.User ?? null, sp.GetService()));
services.AddHttpClient("OmbiClient", client =>
{
client.DefaultRequestHeaders.Add("User-Agent", $"Ombi/{runtimeVersion} (https://ombi.io/)");
@@ -233,6 +236,7 @@ namespace Ombi.DependencyInjection
services.AddSingleton();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
diff --git a/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj b/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj
index e65f2d5a2..93b839c07 100644
--- a/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj
+++ b/src/Ombi.DependencyInjection/Ombi.DependencyInjection.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Helpers/Ombi.Helpers.csproj b/src/Ombi.Helpers/Ombi.Helpers.csproj
index afc881d94..2098fa51f 100644
--- a/src/Ombi.Helpers/Ombi.Helpers.csproj
+++ b/src/Ombi.Helpers/Ombi.Helpers.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Helpers/PlexHelper.cs b/src/Ombi.Helpers/PlexHelper.cs
index 7951a7edf..4ae39f6ce 100644
--- a/src/Ombi.Helpers/PlexHelper.cs
+++ b/src/Ombi.Helpers/PlexHelper.cs
@@ -104,7 +104,7 @@ namespace Ombi.Helpers
return new ProviderId();
}
- public static string GetPlexMediaUrl(string machineId, int mediaId, string plexHost)
+ public static string GetPlexMediaUrl(string machineId, string mediaId, string plexHost)
{
var url =
$"web/#!/server/{machineId}/details?key=%2flibrary%2Fmetadata%2F{mediaId}";
diff --git a/src/Ombi.Hubs/Ombi.Hubs.csproj b/src/Ombi.Hubs/Ombi.Hubs.csproj
index fc65e2dc2..f6bee2eb1 100644
--- a/src/Ombi.Hubs/Ombi.Hubs.csproj
+++ b/src/Ombi.Hubs/Ombi.Hubs.csproj
@@ -2,7 +2,7 @@
net6.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.I18n/Ombi.I18n.csproj b/src/Ombi.I18n/Ombi.I18n.csproj
index f44037974..a3387cdea 100644
--- a/src/Ombi.I18n/Ombi.I18n.csproj
+++ b/src/Ombi.I18n/Ombi.I18n.csproj
@@ -1,4 +1,4 @@
-
+
net6.0
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Mapping/Ombi.Mapping.csproj b/src/Ombi.Mapping/Ombi.Mapping.csproj
index 9ad1f1135..322942cf2 100644
--- a/src/Ombi.Mapping/Ombi.Mapping.csproj
+++ b/src/Ombi.Mapping/Ombi.Mapping.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Notifications.Templates/Ombi.Notifications.Templates.csproj b/src/Ombi.Notifications.Templates/Ombi.Notifications.Templates.csproj
index 87a876caa..99e7509b4 100644
--- a/src/Ombi.Notifications.Templates/Ombi.Notifications.Templates.csproj
+++ b/src/Ombi.Notifications.Templates/Ombi.Notifications.Templates.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Notifications/Ombi.Notifications.csproj b/src/Ombi.Notifications/Ombi.Notifications.csproj
index 6b497c23e..41fd3ae17 100644
--- a/src/Ombi.Notifications/Ombi.Notifications.csproj
+++ b/src/Ombi.Notifications/Ombi.Notifications.csproj
@@ -6,7 +6,7 @@
3.0.0.0
- 8.0
+ latest
Debug;Release;NonUiBuild
diff --git a/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj b/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj
index fd23ee60b..d8e698d0e 100644
--- a/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj
+++ b/src/Ombi.Schedule.Tests/Ombi.Schedule.Tests.csproj
@@ -19,6 +19,7 @@
+
diff --git a/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs b/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs
index da128794c..8540f0037 100644
--- a/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs
+++ b/src/Ombi.Schedule.Tests/PlexContentSyncTests.cs
@@ -47,7 +47,7 @@ namespace Ombi.Schedule.Tests
}
};
var contentToAdd = new HashSet();
- var contentProcessed = new Dictionary();
+ var contentProcessed = new Dictionary();
_mocker.Setup(x =>
x.GetFirstContentByCustom(It.IsAny>>()))
.Returns(Task.FromResult(new PlexServerContent()));
@@ -76,18 +76,18 @@ namespace Ombi.Schedule.Tests
Id = "imdb://tt0322259"
}
},
- ratingKey = 1
+ ratingKey = "1"
},
}
};
var contentToAdd = new HashSet();
- var contentProcessed = new Dictionary();
+ var contentProcessed = new Dictionary();
await _subject.MovieLoop(new PlexServers(), content, contentToAdd, contentProcessed);
var first = contentToAdd.First();
Assert.That(first.ImdbId, Is.EqualTo("tt0322259"));
- _mocker.Verify(x => x.GetMetadata(It.IsAny(), It.IsAny(),It.IsAny()), Times.Never);
+ _mocker.Verify(x => x.GetMetadata(It.IsAny(), It.IsAny(),It.IsAny()), Times.Never);
}
[Test]
@@ -99,7 +99,7 @@ namespace Ombi.Schedule.Tests
{
new Metadata
{
- ratingKey = 11,
+ ratingKey = "11",
title = "test1",
year = 2021,
type = "movie",
@@ -107,8 +107,8 @@ namespace Ombi.Schedule.Tests
}
};
var contentToAdd = new HashSet();
- var contentProcessed = new Dictionary();
- _mocker.Setup(x => x.GetMetadata(It.IsAny(), It.IsAny(), It.IsAny()))
+ var contentProcessed = new Dictionary();
+ _mocker.Setup(x => x.GetMetadata(It.IsAny(), It.IsAny(), It.IsAny()))
.Returns(Task.FromResult(new PlexMetadata
{
MediaContainer = new Mediacontainer
@@ -117,7 +117,7 @@ namespace Ombi.Schedule.Tests
{
new Metadata
{
- ratingKey = 11,
+ ratingKey = "11",
title = "test1",
year = 2021,
type = "movie",
@@ -138,7 +138,7 @@ namespace Ombi.Schedule.Tests
var first = contentToAdd.First();
Assert.That(first.ImdbId, Is.EqualTo("tt0322259"));
- _mocker.Verify(x => x.GetMetadata(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once);
+ _mocker.Verify(x => x.GetMetadata(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once);
}
[Test]
@@ -150,7 +150,7 @@ namespace Ombi.Schedule.Tests
{
new Metadata
{
- ratingKey = 11,
+ ratingKey = "11",
title = "test1",
year = 2021,
type = "movie",
@@ -165,7 +165,7 @@ namespace Ombi.Schedule.Tests
}
};
var contentToAdd = new HashSet();
- var contentProcessed = new Dictionary();
+ var contentProcessed = new Dictionary();
_mocker.Setup(x =>
x.GetFirstContentByCustom(It.IsAny>>()))
.Returns(Task.FromResult(new PlexServerContent
@@ -188,7 +188,7 @@ namespace Ombi.Schedule.Tests
{
new Metadata
{
- ratingKey = 11,
+ ratingKey = "11",
title = "test1",
year = 2021,
type = "movie",
@@ -203,7 +203,7 @@ namespace Ombi.Schedule.Tests
}
};
var contentToAdd = new HashSet();
- var contentProcessed = new Dictionary();
+ var contentProcessed = new Dictionary();
_mocker.Setup(x =>
x.GetFirstContentByCustom(It.IsAny>>()))
.Returns(Task.FromResult(new PlexServerContent
diff --git a/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs b/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs
new file mode 100644
index 000000000..b4759e280
--- /dev/null
+++ b/src/Ombi.Schedule.Tests/PlexWatchlistImportTests.cs
@@ -0,0 +1,375 @@
+using Moq;
+using Moq.AutoMock;
+using NUnit.Framework;
+using Ombi.Api.Plex;
+using Ombi.Api.Plex.Models;
+using Ombi.Core.Engine;
+using Ombi.Core.Engine.Interfaces;
+using Ombi.Core.Models.Requests;
+using Ombi.Core.Settings;
+using Ombi.Core.Settings.Models.External;
+using Ombi.Schedule.Jobs.Plex;
+using Ombi.Store.Entities;
+using Ombi.Test.Common;
+using Quartz;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Ombi.Schedule.Tests
+{
+ [TestFixture]
+ public class PlexWatchlistImportTests
+ {
+
+ private PlexWatchlistImport _subject;
+ private AutoMocker _mocker;
+ private Mock _context;
+
+ [SetUp]
+ public void Setup()
+ {
+ _mocker = new AutoMocker();
+ var um = MockHelper.MockUserManager(new List { new OmbiUser { Id = "abc", UserType = UserType.PlexUser, MediaServerToken = "abc", UserName = "abc", NormalizedUserName = "ABC" } });
+ _mocker.Use(um);
+ _context = _mocker.GetMock();
+ _context.Setup(x => x.CancellationToken).Returns(CancellationToken.None);
+ _subject = _mocker.CreateInstance();
+ }
+
+ [Test]
+ public async Task TerminatesWhenPlexIsNotEnabled()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = false, EnableWatchlistImport = true });
+ await _subject.Execute(null);
+ _mocker.Verify(x => x.RequestMovie(It.IsAny()), Times.Never);
+ _mocker.Verify(x => x.GetWatchlist(It.IsAny(), It.IsAny()), Times.Never);
+ _mocker.Verify(x => x.RequestMovie(It.IsAny()), Times.Never);
+ }
+ [Test]
+ public async Task TerminatesWhenWatchlistIsNotEnabled()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = false });
+ await _subject.Execute(null);
+ _mocker.Verify(x => x.RequestMovie(It.IsAny()), Times.Never);
+ _mocker.Verify(x => x.GetWatchlist(It.IsAny(), It.IsAny()), Times.Never);
+ _mocker.Verify(x => x.RequestMovie(It.IsAny()), Times.Never);
+ }
+
+ [Test]
+ public async Task EmptyWatchList()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true });
+ _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny())).ReturnsAsync(new PlexWatchlistContainer());
+ await _subject.Execute(_context.Object);
+ _mocker.Verify(x => x.RequestMovie(It.IsAny()), Times.Never);
+ _mocker.Verify(x => x.GetWatchlist(It.IsAny(), It.IsAny()), Times.Once);
+ _mocker.Verify(x => x.RequestMovie(It.IsAny()), Times.Never);
+ }
+
+ [Test]
+ public async Task NoPlexUsersWithToken()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true });
+ var um = MockHelper.MockUserManager(new List
+ {
+ new OmbiUser { Id = "abc", UserType = UserType.EmbyUser, MediaServerToken = "abc", UserName = "abc", NormalizedUserName = "ABC" },
+ new OmbiUser { Id = "abc", UserType = UserType.LocalUser, MediaServerToken = "abc", UserName = "abc", NormalizedUserName = "ABC" },
+ new OmbiUser { Id = "abc", UserType = UserType.SystemUser, MediaServerToken = "abc", UserName = "abc", NormalizedUserName = "ABC" },
+ new OmbiUser { Id = "abc", UserType = UserType.JellyfinUser, MediaServerToken = "abc", UserName = "abc", NormalizedUserName = "ABC" },
+ new OmbiUser { Id = "abc", UserType = UserType.EmbyConnectUser, MediaServerToken = "abc", UserName = "abc", NormalizedUserName = "ABC" },
+ new OmbiUser { Id = "abc", UserType = UserType.PlexUser, UserName = "abc", NormalizedUserName = "ABC" },
+ });
+ _mocker.Use(um);
+ _subject = _mocker.CreateInstance();
+
+ await _subject.Execute(_context.Object);
+ _mocker.Verify(x => x.GetWatchlist(It.IsAny(), It.IsAny()), Times.Never);
+ _mocker.Verify(x => x.RequestMovie(It.IsAny()), Times.Never);
+ }
+
+
+ [Test]
+ public async Task MovieRequestFromWatchList_NoGuid()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true });
+ _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny())).ReturnsAsync(new PlexWatchlistContainer
+ {
+ MediaContainer = new PlexWatchlist
+ {
+ Metadata = new List
+ {
+ new Metadata
+ {
+ type = "movie",
+ ratingKey = "abc"
+ }
+ }
+ }
+ });
+ _mocker.Setup>(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny()))
+ .ReturnsAsync(new PlexWatchlistMetadataContainer
+ {
+ MediaContainer = new PlexWatchlistMetadata
+ {
+ Metadata = new WatchlistMetadata[]
+ {
+ new WatchlistMetadata
+ {
+ Guid = new List
+ {
+ new PlexGuids
+ {
+ Id = "tmdb://123"
+ }
+ }
+ }
+ }
+
+ }
+ });
+ _mocker.Setup>(x => x.RequestMovie(It.IsAny()))
+ .ReturnsAsync(new RequestEngineResult { RequestId = 1 });
+ await _subject.Execute(_context.Object);
+ _mocker.Verify(x => x.RequestMovie(It.Is(x => x.TheMovieDbId == 123)), Times.Once);
+ _mocker.Verify(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny()), Times.Once);
+ _mocker.Verify(x => x.SetUser(It.Is(x => x.Id == "abc")), Times.Once);
+ }
+
+
+ [Test]
+ public async Task TvRequestFromWatchList_NoGuid()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true });
+ _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny())).ReturnsAsync(new PlexWatchlistContainer
+ {
+ MediaContainer = new PlexWatchlist
+ {
+ Metadata = new List
+ {
+ new Metadata
+ {
+ type = "show",
+ ratingKey = "abc"
+ }
+ }
+ }
+ });
+ _mocker.Setup>(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny()))
+ .ReturnsAsync(new PlexWatchlistMetadataContainer
+ {
+ MediaContainer = new PlexWatchlistMetadata
+ {
+ Metadata = new WatchlistMetadata[]
+ {
+ new WatchlistMetadata
+ {
+ Guid = new List
+ {
+ new PlexGuids
+ {
+ Id = "tmdb://123"
+ }
+ }
+ }
+ }
+
+ }
+ });
+ _mocker.Setup>(x => x.RequestTvShow(It.IsAny()))
+ .ReturnsAsync(new RequestEngineResult { RequestId = 1 });
+ await _subject.Execute(_context.Object);
+ _mocker.Verify(x => x.RequestTvShow(It.Is(x => x.TheMovieDbId == 123)), Times.Once);
+ _mocker.Verify(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny()), Times.Once);
+ _mocker.Verify(x => x.SetUser(It.Is(x => x.Id == "abc")), Times.Once);
+ }
+
+ [Test]
+ public async Task MovieRequestFromWatchList_AlreadyRequested()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true });
+ _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny())).ReturnsAsync(new PlexWatchlistContainer
+ {
+ MediaContainer = new PlexWatchlist
+ {
+ Metadata = new List
+ {
+ new Metadata
+ {
+ type = "movie",
+ ratingKey = "abc"
+ }
+ }
+ }
+ });
+ _mocker.Setup>(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny()))
+ .ReturnsAsync(new PlexWatchlistMetadataContainer
+ {
+ MediaContainer = new PlexWatchlistMetadata
+ {
+ Metadata = new WatchlistMetadata[]
+ {
+ new WatchlistMetadata
+ {
+ Guid = new List
+ {
+ new PlexGuids
+ {
+ Id = "tmdb://123"
+ }
+ }
+ }
+ }
+
+ }
+ });
+ _mocker.Setup>(x => x.RequestMovie(It.IsAny()))
+ .ReturnsAsync(new RequestEngineResult { ErrorCode = ErrorCode.AlreadyRequested, ErrorMessage = "Requested" });
+ await _subject.Execute(_context.Object);
+ _mocker.Verify(x => x.RequestMovie(It.Is(x => x.TheMovieDbId == 123)), Times.Once);
+ _mocker.Verify(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny()), Times.Once);
+ _mocker.Verify(x => x.SetUser(It.Is(x => x.Id == "abc")), Times.Once);
+ }
+
+ [Test]
+ public async Task TvRequestFromWatchList_AlreadyRequested()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true });
+ _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny())).ReturnsAsync(new PlexWatchlistContainer
+ {
+ MediaContainer = new PlexWatchlist
+ {
+ Metadata = new List
+ {
+ new Metadata
+ {
+ type = "show",
+ ratingKey = "abc"
+ }
+ }
+ }
+ });
+ _mocker.Setup>(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny()))
+ .ReturnsAsync(new PlexWatchlistMetadataContainer
+ {
+ MediaContainer = new PlexWatchlistMetadata
+ {
+ Metadata = new WatchlistMetadata[]
+ {
+ new WatchlistMetadata
+ {
+ Guid = new List
+ {
+ new PlexGuids
+ {
+ Id = "tmdb://123"
+ }
+ }
+ }
+ }
+
+ }
+ });
+ _mocker.Setup>(x => x.RequestTvShow(It.IsAny()))
+ .ReturnsAsync(new RequestEngineResult { ErrorCode = ErrorCode.AlreadyRequested, ErrorMessage = "Requested" });
+ await _subject.Execute(_context.Object);
+ _mocker.Verify(x => x.RequestTvShow(It.Is(x => x.TheMovieDbId == 123)), Times.Once);
+ _mocker.Verify(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny()), Times.Once);
+ _mocker.Verify(x => x.SetUser(It.Is(x => x.Id == "abc")), Times.Once);
+ }
+
+ [Test]
+ public async Task MovieRequestFromWatchList_NoTmdbGuid()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true });
+ _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny())).ReturnsAsync(new PlexWatchlistContainer
+ {
+ MediaContainer = new PlexWatchlist
+ {
+ Metadata = new List
+ {
+ new Metadata
+ {
+ type = "movie",
+ ratingKey = "abc"
+ }
+ }
+ }
+ });
+ _mocker.Setup>(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny()))
+ .ReturnsAsync(new PlexWatchlistMetadataContainer
+ {
+ MediaContainer = new PlexWatchlistMetadata
+ {
+ Metadata = new WatchlistMetadata[]
+ {
+ new WatchlistMetadata
+ {
+ Guid = new List
+ {
+ new PlexGuids
+ {
+ Id = "imdb://123"
+ }
+ }
+ }
+ }
+
+ }
+ });
+ _mocker.Setup>(x => x.RequestMovie(It.IsAny()))
+ .ReturnsAsync(new RequestEngineResult { RequestId = 1 });
+ await _subject.Execute(_context.Object);
+ _mocker.Verify(x => x.RequestMovie(It.IsAny()), Times.Never);
+ _mocker.Verify(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny()), Times.Once);
+ _mocker.Verify(x => x.SetUser(It.Is(x => x.Id == "abc")), Times.Never);
+ }
+
+ [Test]
+ public async Task TvRequestFromWatchList_NoTmdbGuid()
+ {
+ _mocker.Setup, Task>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true, EnableWatchlistImport = true });
+ _mocker.Setup>(x => x.GetWatchlist(It.IsAny(), It.IsAny())).ReturnsAsync(new PlexWatchlistContainer
+ {
+ MediaContainer = new PlexWatchlist
+ {
+ Metadata = new List
+ {
+ new Metadata
+ {
+ type = "movie",
+ ratingKey = "abc"
+ }
+ }
+ }
+ });
+ _mocker.Setup>(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny()))
+ .ReturnsAsync(new PlexWatchlistMetadataContainer
+ {
+ MediaContainer = new PlexWatchlistMetadata
+ {
+ Metadata = new WatchlistMetadata[]
+ {
+ new WatchlistMetadata
+ {
+ Guid = new List
+ {
+ new PlexGuids
+ {
+ Id = "imdb://123"
+ }
+ }
+ }
+ }
+
+ }
+ });
+ _mocker.Setup>(x => x.RequestTvShow(It.IsAny()))
+ .ReturnsAsync(new RequestEngineResult { RequestId = 1 });
+ await _subject.Execute(_context.Object);
+ _mocker.Verify(x => x.RequestTvShow(It.IsAny()), Times.Never);
+ _mocker.Verify(x => x.GetWatchlistMetadata("abc", It.IsAny(), It.IsAny