From 57dcd861a9dc5178e6975d3ef1d534c1accb79a0 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 18 Dec 2022 23:20:46 -0600 Subject: [PATCH] Fixed: Validation for nested settings not running Prevents #1243 --- .../Definitions/Cardigann/CardigannSettings.cs | 15 +-------------- .../Definitions/Headphones/HeadphonesSettings.cs | 1 + .../Definitions/Newznab/NewznabSettings.cs | 1 + .../Definitions/Torznab/TorznabSettings.cs | 2 ++ src/NzbDrone.Core/Indexers/IndexerBaseSettings.cs | 5 +++++ .../Settings/CookieTorrentBaseSettings.cs | 2 ++ .../Settings/NoAuthTorrentBaseSettings.cs | 5 +++++ .../Settings/UserPassTorrentBaseSettings.cs | 2 ++ 8 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannSettings.cs index 9b1ef4e15..9a75ffd28 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Cardigann/CardigannSettings.cs @@ -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 - { - public CardigannSettingsValidator() - { - } - } - public class CardigannSettings : NoAuthTorrentBaseSettings { - private static readonly CardigannSettingsValidator Validator = new CardigannSettingsValidator(); - public CardigannSettings() { ExtraFieldData = new Dictionary(); @@ -26,10 +18,5 @@ namespace NzbDrone.Core.Indexers.Cardigann public string DefinitionFile { get; set; } public Dictionary ExtraFieldData { get; set; } - - public override NzbDroneValidationResult Validate() - { - return new NzbDroneValidationResult(Validator.Validate(this)); - } } } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesSettings.cs index f24062086..0f854f715 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesSettings.cs @@ -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()); } } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs index 7dc8c4d84..ceab10935 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs @@ -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); diff --git a/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabSettings.cs index c1ea89cc9..4f4547fd6 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabSettings.cs @@ -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); diff --git a/src/NzbDrone.Core/Indexers/IndexerBaseSettings.cs b/src/NzbDrone.Core/Indexers/IndexerBaseSettings.cs index c3e3019bd..600d4d7d9 100644 --- a/src/NzbDrone.Core/Indexers/IndexerBaseSettings.cs +++ b/src/NzbDrone.Core/Indexers/IndexerBaseSettings.cs @@ -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"); } } diff --git a/src/NzbDrone.Core/Indexers/Settings/CookieTorrentBaseSettings.cs b/src/NzbDrone.Core/Indexers/Settings/CookieTorrentBaseSettings.cs index b337c5339..81cef47ba 100644 --- a/src/NzbDrone.Core/Indexers/Settings/CookieTorrentBaseSettings.cs +++ b/src/NzbDrone.Core/Indexers/Settings/CookieTorrentBaseSettings.cs @@ -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()); } } diff --git a/src/NzbDrone.Core/Indexers/Settings/NoAuthTorrentBaseSettings.cs b/src/NzbDrone.Core/Indexers/Settings/NoAuthTorrentBaseSettings.cs index c2922551a..b9fd2688f 100644 --- a/src/NzbDrone.Core/Indexers/Settings/NoAuthTorrentBaseSettings.cs +++ b/src/NzbDrone.Core/Indexers/Settings/NoAuthTorrentBaseSettings.cs @@ -6,6 +6,11 @@ namespace NzbDrone.Core.Indexers.Settings { public class NoAuthSettingsValidator : AbstractValidator { + public NoAuthSettingsValidator() + { + RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator()); + RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator()); + } } public class NoAuthTorrentBaseSettings : ITorrentIndexerSettings diff --git a/src/NzbDrone.Core/Indexers/Settings/UserPassTorrentBaseSettings.cs b/src/NzbDrone.Core/Indexers/Settings/UserPassTorrentBaseSettings.cs index 07ef1f193..e8c7f2709 100644 --- a/src/NzbDrone.Core/Indexers/Settings/UserPassTorrentBaseSettings.cs +++ b/src/NzbDrone.Core/Indexers/Settings/UserPassTorrentBaseSettings.cs @@ -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()); } }