From de754169fb511bdb8ed4a676d11b4865bf75aadd Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 19 Dec 2015 18:02:38 -0800 Subject: [PATCH] Fixed: RSS Sync Interval validation --- .../Config/IndexerConfigModule.cs | 4 +-- src/NzbDrone.Api/NzbDrone.Api.csproj | 1 + .../Validation/RssSyncIntervalValidator.cs | 34 +++++++++++++++++++ .../Validation/RuleBuilderExtensions.cs | 5 +++ src/NzbDrone.Core/Jobs/TaskManager.cs | 5 +++ .../Options/IndexerOptionsViewTemplate.hbs | 2 +- 6 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/NzbDrone.Api/Validation/RssSyncIntervalValidator.cs diff --git a/src/NzbDrone.Api/Config/IndexerConfigModule.cs b/src/NzbDrone.Api/Config/IndexerConfigModule.cs index 1f7ff674c..02f03f958 100644 --- a/src/NzbDrone.Api/Config/IndexerConfigModule.cs +++ b/src/NzbDrone.Api/Config/IndexerConfigModule.cs @@ -1,4 +1,5 @@ using FluentValidation; +using NzbDrone.Api.Validation; using NzbDrone.Core.Configuration; namespace NzbDrone.Api.Config @@ -16,8 +17,7 @@ public IndexerConfigModule(IConfigService configService) .GreaterThanOrEqualTo(0); SharedValidator.RuleFor(c => c.RssSyncInterval) - .InclusiveBetween(10, 120) - .When(c => c.RssSyncInterval > 0); + .IsValidRssSyncInterval(); } } } \ No newline at end of file diff --git a/src/NzbDrone.Api/NzbDrone.Api.csproj b/src/NzbDrone.Api/NzbDrone.Api.csproj index 1b1c0b95e..9689ddf41 100644 --- a/src/NzbDrone.Api/NzbDrone.Api.csproj +++ b/src/NzbDrone.Api/NzbDrone.Api.csproj @@ -238,6 +238,7 @@ + diff --git a/src/NzbDrone.Api/Validation/RssSyncIntervalValidator.cs b/src/NzbDrone.Api/Validation/RssSyncIntervalValidator.cs new file mode 100644 index 000000000..8a3f2d54c --- /dev/null +++ b/src/NzbDrone.Api/Validation/RssSyncIntervalValidator.cs @@ -0,0 +1,34 @@ +using FluentValidation.Validators; + +namespace NzbDrone.Api.Validation +{ + public class RssSyncIntervalValidator : PropertyValidator + { + public RssSyncIntervalValidator() + : base("Must be between 10 and 120 or 0 to disable") + { + } + + protected override bool IsValid(PropertyValidatorContext context) + { + if (context.PropertyValue == null) + { + return true; + } + + var value = (int)context.PropertyValue; + + if (value == 0) + { + return true; + } + + if (value >= 10 && value <= 120) + { + return true; + } + + return false; + } + } +} diff --git a/src/NzbDrone.Api/Validation/RuleBuilderExtensions.cs b/src/NzbDrone.Api/Validation/RuleBuilderExtensions.cs index 45cd0e1c6..01a3a4f75 100644 --- a/src/NzbDrone.Api/Validation/RuleBuilderExtensions.cs +++ b/src/NzbDrone.Api/Validation/RuleBuilderExtensions.cs @@ -31,5 +31,10 @@ public static IRuleBuilderOptions> EmptyCollection()); } + + public static IRuleBuilderOptions IsValidRssSyncInterval(this IRuleBuilder ruleBuilder) + { + return ruleBuilder.SetValidator(new RssSyncIntervalValidator()); + } } } diff --git a/src/NzbDrone.Core/Jobs/TaskManager.cs b/src/NzbDrone.Core/Jobs/TaskManager.cs index 0a7d71870..3ad7b909a 100644 --- a/src/NzbDrone.Core/Jobs/TaskManager.cs +++ b/src/NzbDrone.Core/Jobs/TaskManager.cs @@ -120,6 +120,11 @@ private int GetRssSyncInterval() return 10; } + if (interval < 0) + { + return 0; + } + return interval; } diff --git a/src/UI/Settings/Indexers/Options/IndexerOptionsViewTemplate.hbs b/src/UI/Settings/Indexers/Options/IndexerOptionsViewTemplate.hbs index c1321d574..056d12648 100644 --- a/src/UI/Settings/Indexers/Options/IndexerOptionsViewTemplate.hbs +++ b/src/UI/Settings/Indexers/Options/IndexerOptionsViewTemplate.hbs @@ -34,7 +34,7 @@
- +