mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 04:49:33 -07:00
Merge pull request #4591 from Ombi-app/watchlist-list
Do not allow already available movies to be imported via the watchlist
This commit is contained in:
commit
ec773f171a
4 changed files with 68 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
||||||
using MockQueryable.Moq;
|
using MockQueryable.Moq;
|
||||||
using Moq;
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using Ombi.Core.Engine;
|
||||||
using Ombi.Core.Rule.Rules.Request;
|
using Ombi.Core.Rule.Rules.Request;
|
||||||
using Ombi.Store.Entities;
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
|
@ -176,6 +177,47 @@ namespace Ombi.Core.Tests.Rule.Request
|
||||||
Assert.That(result.Success, Is.True);
|
Assert.That(result.Success, Is.True);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task RequestMovie_IsSuccessful()
|
||||||
|
{
|
||||||
|
SetupMockData();
|
||||||
|
|
||||||
|
var req = new MovieRequests
|
||||||
|
{
|
||||||
|
RequestType = RequestType.Movie,
|
||||||
|
TheMovieDbId = 123,
|
||||||
|
Id = 1,
|
||||||
|
};
|
||||||
|
var result = await Rule.Execute(req);
|
||||||
|
|
||||||
|
|
||||||
|
Assert.That(result.Success, Is.True);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task RequestMovie_IsAlreadyAvailable()
|
||||||
|
{
|
||||||
|
var content = new List<PlexServerContent> {
|
||||||
|
new PlexServerContent
|
||||||
|
{
|
||||||
|
TheMovieDbId = 123.ToString(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
PlexContentRepo.Setup(x => x.GetAll()).Returns(content.AsQueryable().BuildMock().Object);
|
||||||
|
|
||||||
|
var req = new MovieRequests
|
||||||
|
{
|
||||||
|
RequestType = RequestType.Movie,
|
||||||
|
TheMovieDbId = 123,
|
||||||
|
Id = 1,
|
||||||
|
};
|
||||||
|
var result = await Rule.Execute(req);
|
||||||
|
|
||||||
|
|
||||||
|
Assert.That(result.Success, Is.False);
|
||||||
|
Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.AlreadyRequested));
|
||||||
|
}
|
||||||
|
|
||||||
private void SetupMockData()
|
private void SetupMockData()
|
||||||
{
|
{
|
||||||
var childRequests = new List<PlexServerContent>
|
var childRequests = new List<PlexServerContent>
|
||||||
|
|
|
@ -54,6 +54,15 @@ namespace Ombi.Core.Rule.Rules.Request
|
||||||
// looks like we have a match on the TVDbID
|
// looks like we have a match on the TVDbID
|
||||||
return CheckExistingContent(tvRequest, anyMovieDbMatches);
|
return CheckExistingContent(tvRequest, anyMovieDbMatches);
|
||||||
}
|
}
|
||||||
|
if (obj.RequestType == RequestType.Movie)
|
||||||
|
{
|
||||||
|
var movie = (MovieRequests)obj;
|
||||||
|
var exists = _plexContent.GetAll().Where(x => x.Type == MediaType.Movie).Any(x => x.TheMovieDbId == movie.Id.ToString() || x.TheMovieDbId == movie.TheMovieDbId.ToString());
|
||||||
|
if (exists)
|
||||||
|
{
|
||||||
|
return Fail(ErrorCode.AlreadyRequested, "This movie is already available." );
|
||||||
|
}
|
||||||
|
}
|
||||||
return Success();
|
return Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -267,7 +267,7 @@ namespace Ombi.Schedule.Tests
|
||||||
_mocker.Verify<IPlexApi>(x => x.GetWatchlistMetadata("abc", It.IsAny<string>(), It.IsAny<CancellationToken>()), Times.Once);
|
_mocker.Verify<IPlexApi>(x => x.GetWatchlistMetadata("abc", It.IsAny<string>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||||
_mocker.Verify<IMovieRequestEngine>(x => x.SetUser(It.Is<OmbiUser>(x => x.Id == "abc")), Times.Once);
|
_mocker.Verify<IMovieRequestEngine>(x => x.SetUser(It.Is<OmbiUser>(x => x.Id == "abc")), Times.Once);
|
||||||
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.GetAll(), Times.Once);
|
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.GetAll(), Times.Once);
|
||||||
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.Add(It.IsAny<PlexWatchlistHistory>()), Times.Never);
|
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.Add(It.IsAny<PlexWatchlistHistory>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -316,7 +316,7 @@ namespace Ombi.Schedule.Tests
|
||||||
_mocker.Verify<IPlexApi>(x => x.GetWatchlistMetadata("abc", It.IsAny<string>(), It.IsAny<CancellationToken>()), Times.Once);
|
_mocker.Verify<IPlexApi>(x => x.GetWatchlistMetadata("abc", It.IsAny<string>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||||
_mocker.Verify<ITvRequestEngine>(x => x.SetUser(It.Is<OmbiUser>(x => x.Id == "abc")), Times.Once);
|
_mocker.Verify<ITvRequestEngine>(x => x.SetUser(It.Is<OmbiUser>(x => x.Id == "abc")), Times.Once);
|
||||||
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.GetAll(), Times.Once);
|
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.GetAll(), Times.Once);
|
||||||
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.Add(It.IsAny<PlexWatchlistHistory>()), Times.Never);
|
_mocker.Verify<IExternalRepository<PlexWatchlistHistory>>(x => x.Add(It.IsAny<PlexWatchlistHistory>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -124,24 +124,19 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
if (response.ErrorCode == ErrorCode.AlreadyRequested)
|
if (response.ErrorCode == ErrorCode.AlreadyRequested)
|
||||||
{
|
{
|
||||||
_logger.LogDebug($"Movie already requested for user '{user.UserName}'");
|
_logger.LogDebug($"Movie already requested for user '{user.UserName}'");
|
||||||
|
await AddToHistory(theMovieDbId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"Error adding title from PlexWatchlist for user '{user.UserName}'. Message: '{response.ErrorMessage}'");
|
_logger.LogInformation($"Error adding title from PlexWatchlist for user '{user.UserName}'. Message: '{response.ErrorMessage}'");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Add to the watchlist history
|
await AddToHistory(theMovieDbId);
|
||||||
var history = new PlexWatchlistHistory
|
|
||||||
{
|
|
||||||
TmdbId = theMovieDbId.ToString()
|
|
||||||
};
|
|
||||||
await _watchlistRepo.Add(history);
|
|
||||||
|
|
||||||
_logger.LogInformation($"Added title from PlexWatchlist for user '{user.UserName}'. {response.Message}");
|
_logger.LogInformation($"Added title from PlexWatchlist for user '{user.UserName}'. {response.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task ProcessShow(int theMovieDbId, OmbiUser user)
|
private async Task ProcessShow(int theMovieDbId, OmbiUser user)
|
||||||
{
|
{
|
||||||
_tvRequestEngine.SetUser(user);
|
_tvRequestEngine.SetUser(user);
|
||||||
|
@ -151,21 +146,27 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
if (response.ErrorCode == ErrorCode.AlreadyRequested)
|
if (response.ErrorCode == ErrorCode.AlreadyRequested)
|
||||||
{
|
{
|
||||||
_logger.LogDebug($"Show already requested for user '{user.UserName}'");
|
_logger.LogDebug($"Show already requested for user '{user.UserName}'");
|
||||||
|
await AddToHistory(theMovieDbId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogInformation($"Error adding title from PlexWatchlist for user '{user.UserName}'. Message: '{response.ErrorMessage}'");
|
_logger.LogInformation($"Error adding title from PlexWatchlist for user '{user.UserName}'. Message: '{response.ErrorMessage}'");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Add to the watchlist history
|
await AddToHistory(theMovieDbId);
|
||||||
var history = new PlexWatchlistHistory
|
|
||||||
{
|
|
||||||
TmdbId = theMovieDbId.ToString()
|
|
||||||
};
|
|
||||||
await _watchlistRepo.Add(history);
|
|
||||||
_logger.LogInformation($"Added title from PlexWatchlist for user '{user.UserName}'. {response.Message}");
|
_logger.LogInformation($"Added title from PlexWatchlist for user '{user.UserName}'. {response.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private async Task AddToHistory(int theMovieDbId)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Add to the watchlist history
|
||||||
|
var history = new PlexWatchlistHistory
|
||||||
|
{
|
||||||
|
TmdbId = theMovieDbId.ToString()
|
||||||
|
};
|
||||||
|
await _watchlistRepo.Add(history);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<ProviderId> GetProviderIds(string authToken, Metadata movie, CancellationToken cancellationToken)
|
private async Task<ProviderId> GetProviderIds(string authToken, Metadata movie, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue