Fixed: RSS Sync Interval validation

pull/2/head
Mark McDowall 9 years ago
parent 2d3c3bbb0c
commit de754169fb

@ -1,4 +1,5 @@
using FluentValidation; using FluentValidation;
using NzbDrone.Api.Validation;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
namespace NzbDrone.Api.Config namespace NzbDrone.Api.Config
@ -16,8 +17,7 @@ namespace NzbDrone.Api.Config
.GreaterThanOrEqualTo(0); .GreaterThanOrEqualTo(0);
SharedValidator.RuleFor(c => c.RssSyncInterval) SharedValidator.RuleFor(c => c.RssSyncInterval)
.InclusiveBetween(10, 120) .IsValidRssSyncInterval();
.When(c => c.RssSyncInterval > 0);
} }
} }
} }

@ -238,6 +238,7 @@
<Compile Include="TinyIoCNancyBootstrapper.cs" /> <Compile Include="TinyIoCNancyBootstrapper.cs" />
<Compile Include="Update\UpdateModule.cs" /> <Compile Include="Update\UpdateModule.cs" />
<Compile Include="Update\UpdateResource.cs" /> <Compile Include="Update\UpdateResource.cs" />
<Compile Include="Validation\RssSyncIntervalValidator.cs" />
<Compile Include="Validation\EmptyCollectionValidator.cs" /> <Compile Include="Validation\EmptyCollectionValidator.cs" />
<Compile Include="Validation\RuleBuilderExtensions.cs" /> <Compile Include="Validation\RuleBuilderExtensions.cs" />
<Compile Include="Wanted\CutoffModule.cs" /> <Compile Include="Wanted\CutoffModule.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;
}
}
}

@ -31,5 +31,10 @@ namespace NzbDrone.Api.Validation
{ {
return ruleBuilder.SetValidator(new EmptyCollectionValidator<TProp>()); return ruleBuilder.SetValidator(new EmptyCollectionValidator<TProp>());
} }
public static IRuleBuilderOptions<T, int> IsValidRssSyncInterval<T>(this IRuleBuilder<T, int> ruleBuilder)
{
return ruleBuilder.SetValidator(new RssSyncIntervalValidator());
}
} }
} }

@ -120,6 +120,11 @@ namespace NzbDrone.Core.Jobs
return 10; return 10;
} }
if (interval < 0)
{
return 0;
}
return interval; return interval;
} }

@ -34,7 +34,7 @@
</div> </div>
<div class="col-sm-2 col-sm-pull-1"> <div class="col-sm-2 col-sm-pull-1">
<input type="number" name="rssSyncInterval" class="form-control"/> <input type="number" name="rssSyncInterval" class="form-control" min="0" max="120"/>
</div> </div>
</div> </div>
</fieldset> </fieldset>

Loading…
Cancel
Save