From a40ad82fa72844208d5944c46bed4f98f2662460 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 20 Sep 2013 00:49:36 -0700 Subject: [PATCH] DownloadAllowed logic moved, using proper validation --- NzbDrone.Api/Indexers/ReleaseModule.cs | 10 +++------- NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs | 6 +++--- NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs | 1 + NzbDrone.Core/Download/DownloadService.cs | 5 +++++ NzbDrone.Core/Parser/Model/RemoteEpisode.cs | 4 +--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/NzbDrone.Api/Indexers/ReleaseModule.cs b/NzbDrone.Api/Indexers/ReleaseModule.cs index f9f6e88cd..96f2aebc6 100644 --- a/NzbDrone.Api/Indexers/ReleaseModule.cs +++ b/NzbDrone.Api/Indexers/ReleaseModule.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using FluentValidation; using Nancy; using NzbDrone.Api.Mapping; using NzbDrone.Api.REST; @@ -38,18 +39,14 @@ namespace NzbDrone.Api.Indexers _parsingService = parsingService; GetResourceAll = GetReleases; Post["/"] = x=> DownloadRelease(this.Bind()); + + PostValidator.RuleFor(s => s.DownloadAllowed); } private Response DownloadRelease(ReleaseResource release) { var remoteEpisode = _parsingService.Map(release.InjectTo(), 0); remoteEpisode.Release = release.InjectTo(); - - if (remoteEpisode.Series == null || remoteEpisode.Episodes == null || !remoteEpisode.Episodes.Any()) - { - throw new BadRequestException(release); - } - _downloadService.DownloadReport(remoteEpisode); return release.AsResponse(); @@ -92,7 +89,6 @@ namespace NzbDrone.Api.Indexers release.InjectFrom(downloadDecision.RemoteEpisode.ParsedEpisodeInfo); release.InjectFrom(downloadDecision); release.Rejections = downloadDecision.Rejections.ToList(); - release.DownloadAllowed = downloadDecision.RemoteEpisode.Series != null; result.Add(release); } diff --git a/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs b/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs index b3b840491..411a31f41 100644 --- a/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs +++ b/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs @@ -1,4 +1,7 @@ +using System.Collections; +using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Text.RegularExpressions; using NzbDrone.Common.EnsureThat.Resources; using NzbDrone.Common.EnvironmentInfo; @@ -73,7 +76,6 @@ namespace NzbDrone.Common.EnsureThat return param; } - [DebuggerStepThrough] public static Param IsRelativePath(this Param param) { @@ -94,8 +96,6 @@ namespace NzbDrone.Common.EnsureThat return param; } - - [DebuggerStepThrough] public static Param IsValidPath(this Param param) { diff --git a/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index f2b1404cf..c03e22d27 100644 --- a/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -74,6 +74,7 @@ namespace NzbDrone.Core.DecisionEngine } else { + remoteEpisode.DownloadAllowed = false; decision = new DownloadDecision(remoteEpisode, "Unknown Series"); } } diff --git a/NzbDrone.Core/Download/DownloadService.cs b/NzbDrone.Core/Download/DownloadService.cs index 963f279e6..e57cad094 100644 --- a/NzbDrone.Core/Download/DownloadService.cs +++ b/NzbDrone.Core/Download/DownloadService.cs @@ -1,4 +1,5 @@ using NLog; +using NzbDrone.Common.EnsureThat; using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Parser.Model; @@ -27,6 +28,10 @@ namespace NzbDrone.Core.Download public void DownloadReport(RemoteEpisode remoteEpisode) { + Ensure.That(() => remoteEpisode.Series).IsNotNull(); + Ensure.That(() => remoteEpisode.Episodes).IsNotNull(); + Ensure.That(() => remoteEpisode.Episodes).HasItems(); + var downloadTitle = remoteEpisode.Release.Title; var downloadClient = _downloadClientProvider.GetDownloadClient(); diff --git a/NzbDrone.Core/Parser/Model/RemoteEpisode.cs b/NzbDrone.Core/Parser/Model/RemoteEpisode.cs index ac394d0d8..f87f71c8e 100644 --- a/NzbDrone.Core/Parser/Model/RemoteEpisode.cs +++ b/NzbDrone.Core/Parser/Model/RemoteEpisode.cs @@ -8,12 +8,10 @@ namespace NzbDrone.Core.Parser.Model public class RemoteEpisode { public ReleaseInfo Release { get; set; } - public ParsedEpisodeInfo ParsedEpisodeInfo { get; set; } - public Series Series { get; set; } - public List Episodes { get; set; } + public Boolean DownloadAllowed { get; set; } public bool IsRecentEpisode() {