diff --git a/NzbDrone.Core.Test/DecisionEngineTests/AllowedReleaseGroupSpecificationFixture.cs b/NzbDrone.Core.Test/DecisionEngineTests/AllowedReleaseGroupSpecificationFixture.cs deleted file mode 100644 index 40f39f18f..000000000 --- a/NzbDrone.Core.Test/DecisionEngineTests/AllowedReleaseGroupSpecificationFixture.cs +++ /dev/null @@ -1,58 +0,0 @@ -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Core.Configuration; -using NzbDrone.Core.DecisionEngine.Specifications; -using NzbDrone.Core.Parser.Model; -using NzbDrone.Core.Test.Framework; - -namespace NzbDrone.Core.Test.DecisionEngineTests -{ - [TestFixture] - public class AllowedReleaseGroupSpecificationFixture : CoreTest - { - private RemoteEpisode _parseResult; - - [SetUp] - public void Setup() - { - _parseResult = new RemoteEpisode - { - Report = new ReportInfo - { - ReleaseGroup = "2HD" - } - }; - } - - [Test] - public void should_be_true_when_allowedReleaseGroups_is_empty() - { - - Subject.IsSatisfiedBy(_parseResult).Should().BeTrue(); - } - - [Test] - public void should_be_true_when_allowedReleaseGroups_is_nzbs_releaseGroup() - { - Subject.IsSatisfiedBy(_parseResult).Should().BeTrue(); - } - - [TestCase("2HD")] - [TestCase("2hd")] - [TestCase("other, 2hd, next")] - [TestCase("other,2hd,next")] - [TestCase("other,2hd,next,")] - public void should_be_true_when_allowedReleaseGroups_contains_nzbs_releaseGroup(string allowedList) - { - Mocker.GetMock().SetupGet(c => c.AllowedReleaseGroups).Returns(allowedList); - Subject.IsSatisfiedBy(_parseResult).Should().BeTrue(); - } - - [Test] - public void should_be_false_when_allowedReleaseGroups_does_not_contain_nzbs_releaseGroup() - { - Mocker.GetMock().SetupGet(c => c.AllowedReleaseGroups).Returns("other"); - Subject.IsSatisfiedBy(_parseResult).Should().BeFalse(); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core.Test/DecisionEngineTests/NotRestrictedNzbSpecificationFixture.cs b/NzbDrone.Core.Test/DecisionEngineTests/NotRestrictedNzbSpecificationFixture.cs new file mode 100644 index 000000000..ed1de251d --- /dev/null +++ b/NzbDrone.Core.Test/DecisionEngineTests/NotRestrictedNzbSpecificationFixture.cs @@ -0,0 +1,51 @@ +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.DecisionEngine.Specifications; +using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.DecisionEngineTests +{ + [TestFixture] + public class NotRestrictedNzbSpecificationFixture : CoreTest + { + private RemoteEpisode _parseResult; + + [SetUp] + public void Setup() + { + _parseResult = new RemoteEpisode + { + Report = new ReportInfo + { + Title = "Dexter.S08E01.EDITED.WEBRip.x264-KYR" + } + }; + } + + [Test] + public void should_be_true_when_restrictions_are_empty() + { + Subject.IsSatisfiedBy(_parseResult).Should().BeTrue(); + } + + [TestCase("KYR")] + [TestCase("EDITED")] + [TestCase("2HD\nKYR")] + public void should_be_false_when_nzb_contains_a_restricted_term(string restrictions) + { + Mocker.GetMock().SetupGet(c => c.NzbRestrictions).Returns(restrictions); + Subject.IsSatisfiedBy(_parseResult).Should().BeFalse(); + } + + [TestCase("NotReal")] + [TestCase("LoL")] + [TestCase("Hello\nWorld")] + public void should_be_true_when_nzb_does_not_contain_a_restricted_term(string restrictions) + { + Mocker.GetMock().SetupGet(c => c.NzbRestrictions).Returns(restrictions); + Subject.IsSatisfiedBy(_parseResult).Should().BeTrue(); + } + } +} \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 8a6550da1..a80ac6958 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -124,6 +124,7 @@ + @@ -167,7 +168,6 @@ - diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index c9e608999..a6b6623d4 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -277,12 +277,6 @@ namespace NzbDrone.Core.Configuration set { SetValue("NzbRestrictions", value); } } - public string AllowedReleaseGroups - { - get { return GetValue("AllowedReleaseGroups", String.Empty); } - set { SetValue("AllowedReleaseGroups", value); } - } - private string GetValue(string key) { return GetValue(key, String.Empty); diff --git a/NzbDrone.Core/Configuration/IConfigService.cs b/NzbDrone.Core/Configuration/IConfigService.cs index cf2fe7c33..0ee48c889 100644 --- a/NzbDrone.Core/Configuration/IConfigService.cs +++ b/NzbDrone.Core/Configuration/IConfigService.cs @@ -43,7 +43,6 @@ namespace NzbDrone.Core.Configuration PriorityType NzbgetBacklogTvPriority { get; set; } PriorityType NzbgetRecentTvPriority { get; set; } string NzbRestrictions { get; set; } - string AllowedReleaseGroups { get; set; } string GetValue(string key, object defaultValue, bool persist = false); void SetValue(string key, string value); void SaveValues(Dictionary configValues); diff --git a/NzbDrone.Core/DecisionEngine/Specifications/AllowedReleaseGroupSpecification.cs b/NzbDrone.Core/DecisionEngine/Specifications/AllowedReleaseGroupSpecification.cs deleted file mode 100644 index f3ac9c384..000000000 --- a/NzbDrone.Core/DecisionEngine/Specifications/AllowedReleaseGroupSpecification.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Linq; -using NLog; -using NzbDrone.Core.Configuration; -using NzbDrone.Core.Model; -using NzbDrone.Core.Parser; -using NzbDrone.Core.Parser.Model; - -namespace NzbDrone.Core.DecisionEngine.Specifications -{ - public class AllowedReleaseGroupSpecification : IDecisionEngineSpecification - { - private readonly IConfigService _configService; - private readonly Logger _logger; - - public AllowedReleaseGroupSpecification(IConfigService configService, Logger logger) - { - _configService = configService; - _logger = logger; - } - - - public string RejectionReason - { - get - { - return "Release group is blacklisted."; - } - } - - public virtual bool IsSatisfiedBy(RemoteEpisode subject) - { - _logger.Trace("Beginning release group check for: {0}", subject); - - //Todo: Make this use NzbRestrictions - How should whitelist be used? Will it override blacklist or vice-versa? - - var allowed = _configService.AllowedReleaseGroups; - - if (string.IsNullOrWhiteSpace(allowed)) - return true; - - var reportReleaseGroup = subject.Report.ReleaseGroup.ToLower(); - - return allowed.ToLower().Split(',').Any(allowedGroup => allowedGroup.Trim() == reportReleaseGroup); - } - } -} diff --git a/NzbDrone.Core/DecisionEngine/Specifications/NotRestrictedNzbSpecification.cs b/NzbDrone.Core/DecisionEngine/Specifications/NotRestrictedNzbSpecification.cs new file mode 100644 index 000000000..ad6bcdaa5 --- /dev/null +++ b/NzbDrone.Core/DecisionEngine/Specifications/NotRestrictedNzbSpecification.cs @@ -0,0 +1,57 @@ +using System; +using System.Linq; +using NLog; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.Model; +using NzbDrone.Core.Parser; +using NzbDrone.Core.Parser.Model; + +namespace NzbDrone.Core.DecisionEngine.Specifications +{ + public class NotRestrictedNzbSpecification : IDecisionEngineSpecification + { + private readonly IConfigService _configService; + private readonly Logger _logger; + + public NotRestrictedNzbSpecification(IConfigService configService, Logger logger) + { + _configService = configService; + _logger = logger; + } + + public string RejectionReason + { + get + { + return "Contrains restricted term."; + } + } + + public virtual bool IsSatisfiedBy(RemoteEpisode subject) + { + _logger.Trace("Checking if Nzb contains any restrictions: {0}", subject); + + var restrictionsString = _configService.NzbRestrictions; + + if (String.IsNullOrWhiteSpace(restrictionsString)) + { + _logger.Trace("No restrictions configured, allowing: {0}", subject); + return true; + } + + var restrictions = restrictionsString.Split('\n'); + + foreach (var restriction in restrictions) + { + if (subject.Report.Title.Contains(restriction)) + { + _logger.Trace("{0} is restricted: {1}", subject, restriction); + return false; + } + } + + _logger.Trace("No restrictions apply, allowing: {0}", subject); + return true; + } + } +} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index b82ef3973..fbaf13913 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -227,12 +227,12 @@ + -