1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fixed: RSS Sync Interval validation

This commit is contained in:
Mark McDowall 2015-12-19 18:02:38 -08:00
parent 2d3c3bbb0c
commit de754169fb
6 changed files with 48 additions and 3 deletions

View File

@ -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();
}
}
}

View File

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

View File

@ -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;
}
}
}

View File

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

View File

@ -120,6 +120,11 @@ private int GetRssSyncInterval()
return 10;
}
if (interval < 0)
{
return 0;
}
return interval;
}

View File

@ -34,7 +34,7 @@
</div>
<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>
</fieldset>