From 67995a5cf6c0695961fc657bbce7a50b40e89552 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 16 Apr 2013 20:52:43 -0700 Subject: [PATCH] fixed AllowedReleaseGroupSpecification --- .../AllowedReleaseGroupSpecificationFixture.cs | 13 ++++++++++--- NzbDrone.Core/Configuration/ConfigService.cs | 6 ++++++ NzbDrone.Core/Configuration/IConfigService.cs | 1 + .../AllowedReleaseGroupSpecification.cs | 18 ++++-------------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/NzbDrone.Core.Test/DecisionEngineTests/AllowedReleaseGroupSpecificationFixture.cs b/NzbDrone.Core.Test/DecisionEngineTests/AllowedReleaseGroupSpecificationFixture.cs index 4f66e74cc..40f39f18f 100644 --- a/NzbDrone.Core.Test/DecisionEngineTests/AllowedReleaseGroupSpecificationFixture.cs +++ b/NzbDrone.Core.Test/DecisionEngineTests/AllowedReleaseGroupSpecificationFixture.cs @@ -1,5 +1,6 @@ using FluentAssertions; using NUnit.Framework; +using NzbDrone.Core.Configuration; using NzbDrone.Core.DecisionEngine.Specifications; using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Test.Framework; @@ -7,7 +8,6 @@ using NzbDrone.Core.Test.Framework; namespace NzbDrone.Core.Test.DecisionEngineTests { [TestFixture] - public class AllowedReleaseGroupSpecificationFixture : CoreTest { private RemoteEpisode _parseResult; @@ -27,6 +27,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void should_be_true_when_allowedReleaseGroups_is_empty() { + Subject.IsSatisfiedBy(_parseResult).Should().BeTrue(); } @@ -36,15 +37,21 @@ namespace NzbDrone.Core.Test.DecisionEngineTests Subject.IsSatisfiedBy(_parseResult).Should().BeTrue(); } - [Test] - public void should_be_true_when_allowedReleaseGroups_contains_nzbs_releaseGroup() + [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(); } } diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index b5a71e004..927c2cebe 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -479,6 +479,12 @@ 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 c430297e1..0742bd8f5 100644 --- a/NzbDrone.Core/Configuration/IConfigService.cs +++ b/NzbDrone.Core/Configuration/IConfigService.cs @@ -78,6 +78,7 @@ 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 index 6ce96c527..f3ac9c384 100644 --- a/NzbDrone.Core/DecisionEngine/Specifications/AllowedReleaseGroupSpecification.cs +++ b/NzbDrone.Core/DecisionEngine/Specifications/AllowedReleaseGroupSpecification.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using NLog; using NzbDrone.Core.Configuration; using NzbDrone.Core.Model; @@ -33,25 +34,14 @@ namespace NzbDrone.Core.DecisionEngine.Specifications //Todo: Make this use NzbRestrictions - How should whitelist be used? Will it override blacklist or vice-versa? - //var allowed = _configService.AllowedReleaseGroups; - const string allowed = ""; + var allowed = _configService.AllowedReleaseGroups; if (string.IsNullOrWhiteSpace(allowed)) return true; - var releaseGroup = subject.Report.ReleaseGroup; + var reportReleaseGroup = subject.Report.ReleaseGroup.ToLower(); - foreach (var group in allowed.Trim(',', ' ').Split(',')) - { - if (releaseGroup.Equals(group.Trim(' '), StringComparison.CurrentCultureIgnoreCase)) - { - _logger.Trace("Item: {0}'s release group is wanted: {1}", subject, releaseGroup); - return true; - } - } - - _logger.Trace("Item: {0}'s release group is not wanted: {1}", subject, releaseGroup); - return false; + return allowed.ToLower().Split(',').Any(allowedGroup => allowedGroup.Trim() == reportReleaseGroup); } } }