Fixed: Validation for nested settings not running

Prevents #1243
pull/1245/head v0.4.11.2143
Qstick 2 years ago
parent dfe132cda2
commit 57dcd861a9

@ -1,22 +1,14 @@
using System.Collections.Generic;
using FluentValidation;
using FluentValidation.Results;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Indexers.Settings;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Indexers.Cardigann
{
public class CardigannSettingsValidator : AbstractValidator<CardigannSettings>
{
public CardigannSettingsValidator()
{
}
}
public class CardigannSettings : NoAuthTorrentBaseSettings
{
private static readonly CardigannSettingsValidator Validator = new CardigannSettingsValidator();
public CardigannSettings()
{
ExtraFieldData = new Dictionary<string, object>();
@ -26,10 +18,5 @@ namespace NzbDrone.Core.Indexers.Cardigann
public string DefinitionFile { get; set; }
public Dictionary<string, object> ExtraFieldData { get; set; }
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
}
}

@ -10,6 +10,7 @@ namespace NzbDrone.Core.Indexers.Headphones
{
RuleFor(c => c.Username).NotEmpty();
RuleFor(c => c.Password).NotEmpty();
RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator());
}
}

@ -35,6 +35,7 @@ namespace NzbDrone.Core.Indexers.Newznab
public NewznabSettingsValidator()
{
RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator());
RuleFor(c => c.BaseUrl).ValidRootUrl();
RuleFor(c => c.ApiPath).ValidUrlBase("/api");
RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey);

@ -29,6 +29,8 @@ namespace NzbDrone.Core.Indexers.Torznab
public TorznabSettingsValidator()
{
RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator());
RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator());
RuleFor(c => c.BaseUrl).ValidRootUrl();
RuleFor(c => c.ApiPath).ValidUrlBase("/api");
RuleFor(c => c.ApiKey).NotEmpty().When(ShouldHaveApiKey);

@ -1,5 +1,7 @@
using FluentValidation;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Indexers
{
@ -7,6 +9,9 @@ namespace NzbDrone.Core.Indexers
{
public IndexerCommonSettingsValidator()
{
RuleFor(c => c.QueryLimit).GreaterThan(0).When(c => c.QueryLimit.HasValue).WithMessage("Should be greater than zero");
RuleFor(c => c.GrabLimit).GreaterThan(0).When(c => c.GrabLimit.HasValue).WithMessage("Should be greater than zero");
}
}

@ -11,6 +11,8 @@ namespace NzbDrone.Core.Indexers.Settings
public CookieBaseSettingsValidator()
{
RuleFor(c => c.Cookie).NotEmpty();
RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator());
RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator());
}
}

@ -6,6 +6,11 @@ namespace NzbDrone.Core.Indexers.Settings
{
public class NoAuthSettingsValidator : AbstractValidator<NoAuthTorrentBaseSettings>
{
public NoAuthSettingsValidator()
{
RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator());
RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator());
}
}
public class NoAuthTorrentBaseSettings : ITorrentIndexerSettings

@ -12,6 +12,8 @@ namespace NzbDrone.Core.Indexers.Settings
{
RuleFor(c => c.Username).NotEmpty();
RuleFor(c => c.Password).NotEmpty();
RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator());
RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator());
}
}

Loading…
Cancel
Save