1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Fixed: Release Push api broken when no indexer id is specified

This commit is contained in:
Taloth Saldono 2021-08-11 13:47:03 +02:00
parent 0d03dba6ea
commit 20306a38e1
2 changed files with 48 additions and 5 deletions

View File

@ -3,6 +3,7 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.IndexerSearch.Definitions;
@ -33,8 +34,13 @@ public void Setup()
};
Mocker
.GetMock<IIndexerRepository>()
.GetMock<IIndexerFactory>()
.Setup(m => m.Get(It.IsAny<int>()))
.Throws(new ModelNotFoundException(typeof(IndexerDefinition), -1));
Mocker
.GetMock<IIndexerFactory>()
.Setup(m => m.Get(1))
.Returns(_fakeIndexerDefinition);
_specification = Mocker.Resolve<IndexerTagSpecification>();
@ -106,5 +112,25 @@ public void indexer_with_tags_series_with_different_tags_should_return_false()
_specification.IsSatisfiedBy(_parseResultMulti, new SingleEpisodeSearchCriteria { MonitoredEpisodesOnly = true }).Accepted.Should().BeFalse();
}
[Test]
public void release_without_indexerid_should_return_true()
{
_fakeIndexerDefinition.Tags = new HashSet<int> { 456 };
_fakeSeries.Tags = new HashSet<int> { 123, 789 };
_fakeRelease.IndexerId = 0;
_specification.IsSatisfiedBy(_parseResultMulti, new SingleEpisodeSearchCriteria { MonitoredEpisodesOnly = true }).Accepted.Should().BeTrue();
}
[Test]
public void release_with_invalid_indexerid_should_return_true()
{
_fakeIndexerDefinition.Tags = new HashSet<int> { 456 };
_fakeSeries.Tags = new HashSet<int> { 123, 789 };
_fakeRelease.IndexerId = 2;
_specification.IsSatisfiedBy(_parseResultMulti, new SingleEpisodeSearchCriteria { MonitoredEpisodesOnly = true }).Accepted.Should().BeTrue();
}
}
}

View File

@ -1,6 +1,7 @@
using System.Linq;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser.Model;
@ -10,12 +11,12 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.RssSync
public class IndexerTagSpecification : IDecisionEngineSpecification
{
private readonly Logger _logger;
private readonly IIndexerRepository _indexerRepository;
private readonly IIndexerFactory _indexerFactory;
public IndexerTagSpecification(Logger logger, IIndexerRepository indexerRepository)
public IndexerTagSpecification(Logger logger, IIndexerFactory indexerFactory)
{
_logger = logger;
_indexerRepository = indexerRepository;
_indexerFactory = indexerFactory;
}
public SpecificationPriority Priority => SpecificationPriority.Default;
@ -23,8 +24,24 @@ public IndexerTagSpecification(Logger logger, IIndexerRepository indexerReposito
public virtual Decision IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria)
{
if (subject.Release == null || subject.Series?.Tags == null || subject.Release.IndexerId == 0)
{
return Decision.Accept();
}
IndexerDefinition indexer;
try
{
indexer = _indexerFactory.Get(subject.Release.IndexerId);
}
catch (ModelNotFoundException)
{
_logger.Debug("Indexer with id {0} does not exist, skipping indexer tags check", subject.Release.IndexerId);
return Decision.Accept();
}
// If indexer has tags, check that at least one of them is present on the series
var indexerTags = _indexerRepository.Get(subject.Release.IndexerId).Tags;
var indexerTags = indexer.Tags;
if (indexerTags.Any() && indexerTags.Intersect(subject.Series.Tags).Empty())
{