From d6b379df64d206944b227ef53ca29db8a1cea5bc Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 19 Jan 2023 04:52:04 +0200 Subject: [PATCH] Fixed: Validation inheritance --- .../Indexers/Definitions/AnimeBytes.cs | 4 +-- .../Definitions/Avistaz/AvistazSettings.cs | 4 +-- .../Indexers/Definitions/BeyondHD.cs | 4 +-- .../Indexers/Definitions/BinSearch.cs | 2 +- .../BroadcastheNet/BroadcastheNetSettings.cs | 8 ++---- .../Definitions/FileList/FileListSettings.cs | 2 +- .../Definitions/Gazelle/GazelleSettings.cs | 14 +++++++--- .../Indexers/Definitions/GazelleGames.cs | 4 +-- .../Definitions/HDBits/HDBitsSettings.cs | 4 +-- .../Headphones/HeadphonesSettings.cs | 4 +-- .../Indexers/Definitions/MyAnonamouse.cs | 4 +-- .../Definitions/Newznab/NewznabSettings.cs | 4 +-- .../Indexers/Definitions/NzbIndex.cs | 6 +++-- .../Indexers/Definitions/Orpheus.cs | 2 +- .../PassThePopcorn/PassThePopcornSettings.cs | 8 ++---- .../Indexers/Definitions/PreToMe.cs | 4 +-- .../Definitions/Rarbg/RarbgSettings.cs | 2 -- .../Indexers/Definitions/Redacted.cs | 4 +-- .../Indexers/Definitions/SceneHD.cs | 4 +-- .../Definitions/SpeedApp/SpeedAppBase.cs | 2 +- .../TorrentPotato/TorrentPotatoSettings.cs | 16 +++++++++-- .../Indexers/Definitions/TorrentSyndikat.cs | 4 +-- .../Definitions/Torznab/TorznabSettings.cs | 8 ++---- .../Definitions/UNIT3D/Unit3dSettings.cs | 8 ++---- .../Definitions/Xthor/XthorSettings.cs | 6 ++++- .../Xthor/XthorSettingsValidator.cs | 8 ------ .../Indexers/IndexerBaseSettings.cs | 2 +- .../Indexers/IndexerTorrentBaseSettings.cs | 21 ++++++++++----- .../Settings/CookieTorrentBaseSettings.cs | 22 +++++++-------- .../Settings/NoAuthTorrentBaseSettings.cs | 9 ++++--- .../Settings/UserPassTorrentBaseSettings.cs | 27 ++++++++++--------- 31 files changed, 115 insertions(+), 106 deletions(-) delete mode 100644 src/NzbDrone.Core/Indexers/Definitions/Xthor/XthorSettingsValidator.cs diff --git a/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs b/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs index a6b12642e..d3f0c2410 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/AnimeBytes.cs @@ -521,7 +521,7 @@ namespace NzbDrone.Core.Indexers.Definitions public Action, DateTime?> CookiesUpdater { get; set; } } - public class AnimeBytesSettingsValidator : AbstractValidator + public class AnimeBytesSettingsValidator : NoAuthSettingsValidator { public AnimeBytesSettingsValidator() { @@ -535,7 +535,7 @@ namespace NzbDrone.Core.Indexers.Definitions public class AnimeBytesSettings : NoAuthTorrentBaseSettings { - private static readonly AnimeBytesSettingsValidator Validator = new AnimeBytesSettingsValidator(); + private static readonly AnimeBytesSettingsValidator Validator = new (); public AnimeBytesSettings() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazSettings.cs index 03f118853..b2740c64a 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Avistaz/AvistazSettings.cs @@ -5,7 +5,7 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions.Avistaz { - public class AvistazSettingsValidator : AbstractValidator + public class AvistazSettingsValidator : NoAuthSettingsValidator { public AvistazSettingsValidator() { @@ -17,7 +17,7 @@ namespace NzbDrone.Core.Indexers.Definitions.Avistaz public class AvistazSettings : NoAuthTorrentBaseSettings { - private static readonly AvistazSettingsValidator Validator = new AvistazSettingsValidator(); + private static readonly AvistazSettingsValidator Validator = new (); public AvistazSettings() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/BeyondHD.cs b/src/NzbDrone.Core/Indexers/Definitions/BeyondHD.cs index d700996d4..2f1acc9a3 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/BeyondHD.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/BeyondHD.cs @@ -246,7 +246,7 @@ namespace NzbDrone.Core.Indexers.Definitions public Action, DateTime?> CookiesUpdater { get; set; } } - public class BeyondHDSettingsValidator : AbstractValidator + public class BeyondHDSettingsValidator : NoAuthSettingsValidator { public BeyondHDSettingsValidator() { @@ -257,7 +257,7 @@ namespace NzbDrone.Core.Indexers.Definitions public class BeyondHDSettings : NoAuthTorrentBaseSettings { - private static readonly BeyondHDSettingsValidator Validator = new BeyondHDSettingsValidator(); + private static readonly BeyondHDSettingsValidator Validator = new (); public BeyondHDSettings() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/BinSearch.cs b/src/NzbDrone.Core/Indexers/Definitions/BinSearch.cs index dd51ae064..2fe150edc 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/BinSearch.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/BinSearch.cs @@ -219,7 +219,7 @@ namespace NzbDrone.Core.Indexers.Definitions public string BaseUrl { get; set; } [FieldDefinition(2)] - public IndexerBaseSettings BaseSettings { get; set; } = new IndexerBaseSettings(); + public IndexerBaseSettings BaseSettings { get; set; } = new (); public NzbDroneValidationResult Validate() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNetSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNetSettings.cs index 965f04a7f..7e95c01d5 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNetSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/BroadcastheNet/BroadcastheNetSettings.cs @@ -5,7 +5,7 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.BroadcastheNet { - public class BroadcastheNetSettingsValidator : AbstractValidator + public class BroadcastheNetSettingsValidator : NoAuthSettingsValidator { public BroadcastheNetSettingsValidator() { @@ -15,11 +15,7 @@ namespace NzbDrone.Core.Indexers.BroadcastheNet public class BroadcastheNetSettings : NoAuthTorrentBaseSettings { - private static readonly BroadcastheNetSettingsValidator Validator = new BroadcastheNetSettingsValidator(); - - public BroadcastheNetSettings() - { - } + private static readonly BroadcastheNetSettingsValidator Validator = new (); [FieldDefinition(2, Label = "API Key", Privacy = PrivacyLevel.ApiKey)] public string ApiKey { get; set; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListSettings.cs index 29a8626c7..7dbd86160 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/FileList/FileListSettings.cs @@ -5,7 +5,7 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.FileList { - public class FileListSettingsValidator : AbstractValidator + public class FileListSettingsValidator : NoAuthSettingsValidator { public FileListSettingsValidator() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleSettings.cs index 8f3dc85ea..d3d87e8a7 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Gazelle/GazelleSettings.cs @@ -1,20 +1,26 @@ -using FluentValidation; using NzbDrone.Core.Annotations; using NzbDrone.Core.Indexers.Settings; using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Gazelle { + public class GazelleSettingsValidator : UserPassBaseSettingsValidator + { + } + public class GazelleSettings : UserPassTorrentBaseSettings { - public GazelleSettings() - { - } + private static readonly GazelleSettingsValidator Validator = new (); public string AuthKey; public string PassKey; [FieldDefinition(4, Type = FieldType.Checkbox, Label = "Use Freeleech Token", HelpText = "Use freeleech tokens when available")] public bool UseFreeleechToken { get; set; } + + public override NzbDroneValidationResult Validate() + { + return new NzbDroneValidationResult(Validator.Validate(this)); + } } } diff --git a/src/NzbDrone.Core/Indexers/Definitions/GazelleGames.cs b/src/NzbDrone.Core/Indexers/Definitions/GazelleGames.cs index 19afcbfd1..4d3224a1a 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/GazelleGames.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/GazelleGames.cs @@ -431,7 +431,7 @@ namespace NzbDrone.Core.Indexers.Definitions public Action, DateTime?> CookiesUpdater { get; set; } } - public class GazelleGamesSettingsValidator : AbstractValidator + public class GazelleGamesSettingsValidator : NoAuthSettingsValidator { public GazelleGamesSettingsValidator() { @@ -441,7 +441,7 @@ namespace NzbDrone.Core.Indexers.Definitions public class GazelleGamesSettings : NoAuthTorrentBaseSettings { - private static readonly GazelleGamesSettingsValidator Validator = new GazelleGamesSettingsValidator(); + private static readonly GazelleGamesSettingsValidator Validator = new (); public GazelleGamesSettings() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsSettings.cs index 386613626..4a1aff654 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/HDBits/HDBitsSettings.cs @@ -6,7 +6,7 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.HDBits { - public class HDBitsSettingsValidator : AbstractValidator + public class HDBitsSettingsValidator : NoAuthSettingsValidator { public HDBitsSettingsValidator() { @@ -16,7 +16,7 @@ namespace NzbDrone.Core.Indexers.HDBits public class HDBitsSettings : NoAuthTorrentBaseSettings { - private static readonly HDBitsSettingsValidator Validator = new HDBitsSettingsValidator(); + private static readonly HDBitsSettingsValidator Validator = new (); public HDBitsSettings() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesSettings.cs index 0f854f715..ff1770cdb 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Headphones/HeadphonesSettings.cs @@ -16,7 +16,7 @@ namespace NzbDrone.Core.Indexers.Headphones public class HeadphonesSettings : IIndexerSettings { - private static readonly HeadphonesSettingsValidator Validator = new HeadphonesSettingsValidator(); + private static readonly HeadphonesSettingsValidator Validator = new (); public HeadphonesSettings() { @@ -38,7 +38,7 @@ namespace NzbDrone.Core.Indexers.Headphones public string Password { get; set; } [FieldDefinition(4)] - public IndexerBaseSettings BaseSettings { get; set; } = new IndexerBaseSettings(); + public IndexerBaseSettings BaseSettings { get; set; } = new (); public virtual NzbDroneValidationResult Validate() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/MyAnonamouse.cs b/src/NzbDrone.Core/Indexers/Definitions/MyAnonamouse.cs index 7a099b6b5..abb3948c6 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/MyAnonamouse.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/MyAnonamouse.cs @@ -480,7 +480,7 @@ namespace NzbDrone.Core.Indexers.Definitions public Action, DateTime?> CookiesUpdater { get; set; } } - public class MyAnonamouseSettingsValidator : AbstractValidator + public class MyAnonamouseSettingsValidator : NoAuthSettingsValidator { public MyAnonamouseSettingsValidator() { @@ -490,7 +490,7 @@ namespace NzbDrone.Core.Indexers.Definitions public class MyAnonamouseSettings : NoAuthTorrentBaseSettings { - private static readonly MyAnonamouseSettingsValidator Validator = new MyAnonamouseSettingsValidator(); + private static readonly MyAnonamouseSettingsValidator Validator = new (); public MyAnonamouseSettings() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs index ceab10935..6551b2b30 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs @@ -54,7 +54,7 @@ namespace NzbDrone.Core.Indexers.Newznab public class NewznabSettings : IIndexerSettings { - private static readonly NewznabSettingsValidator Validator = new NewznabSettingsValidator(); + private static readonly NewznabSettingsValidator Validator = new (); public NewznabSettings() { @@ -78,7 +78,7 @@ namespace NzbDrone.Core.Indexers.Newznab public string VipExpiration { get; set; } [FieldDefinition(7)] - public IndexerBaseSettings BaseSettings { get; set; } = new IndexerBaseSettings(); + public IndexerBaseSettings BaseSettings { get; set; } = new (); public List Categories { get; set; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/NzbIndex.cs b/src/NzbDrone.Core/Indexers/Definitions/NzbIndex.cs index bc007588f..a9594650e 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/NzbIndex.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/NzbIndex.cs @@ -1168,7 +1168,7 @@ namespace NzbDrone.Core.Indexers.Definitions public class NzbIndexSettings : IIndexerSettings { - private static readonly NzbIndexSettingsValidator Validator = new NzbIndexSettingsValidator(); + private static readonly NzbIndexSettingsValidator Validator = new (); public NzbIndexSettings() { @@ -1182,7 +1182,9 @@ namespace NzbDrone.Core.Indexers.Definitions public string ApiKey { get; set; } [FieldDefinition(3)] - public IndexerBaseSettings BaseSettings { get; set; } = new IndexerBaseSettings(); public NzbDroneValidationResult Validate() + public IndexerBaseSettings BaseSettings { get; set; } = new (); + + public NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Orpheus.cs b/src/NzbDrone.Core/Indexers/Definitions/Orpheus.cs index 5f107c310..dfc53a4d5 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Orpheus.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Orpheus.cs @@ -385,7 +385,7 @@ namespace NzbDrone.Core.Indexers.Definitions } } - public class OrpheusSettingsValidator : AbstractValidator + public class OrpheusSettingsValidator : NoAuthSettingsValidator { public OrpheusSettingsValidator() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcornSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcornSettings.cs index 8e7eabafc..e5542e008 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcornSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/PassThePopcorn/PassThePopcornSettings.cs @@ -5,7 +5,7 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.PassThePopcorn { - public class PassThePopcornSettingsValidator : AbstractValidator + public class PassThePopcornSettingsValidator : NoAuthSettingsValidator { public PassThePopcornSettingsValidator() { @@ -16,11 +16,7 @@ namespace NzbDrone.Core.Indexers.PassThePopcorn public class PassThePopcornSettings : NoAuthTorrentBaseSettings { - private static readonly PassThePopcornSettingsValidator Validator = new PassThePopcornSettingsValidator(); - - public PassThePopcornSettings() - { - } + private static readonly PassThePopcornSettingsValidator Validator = new (); [FieldDefinition(2, Label = "API User", HelpText = "These settings are found in your PassThePopcorn security settings (Edit Profile > Security).", Privacy = PrivacyLevel.UserName)] public string APIUser { get; set; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/PreToMe.cs b/src/NzbDrone.Core/Indexers/Definitions/PreToMe.cs index ec0c22cf6..763861a27 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/PreToMe.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/PreToMe.cs @@ -380,7 +380,7 @@ namespace NzbDrone.Core.Indexers.Definitions public Action, DateTime?> CookiesUpdater { get; set; } } - public class PreToMeSettingsValidator : AbstractValidator + public class PreToMeSettingsValidator : NoAuthSettingsValidator { public PreToMeSettingsValidator() { @@ -392,7 +392,7 @@ namespace NzbDrone.Core.Indexers.Definitions public class PreToMeSettings : NoAuthTorrentBaseSettings { - private static readonly PreToMeSettingsValidator Validator = new PreToMeSettingsValidator(); + private static readonly PreToMeSettingsValidator Validator = new (); public PreToMeSettings() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgSettings.cs index 45c091e6d..359aa187e 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Rarbg/RarbgSettings.cs @@ -1,7 +1,5 @@ -using FluentValidation; using NzbDrone.Core.Annotations; using NzbDrone.Core.Indexers.Settings; -using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Rarbg { diff --git a/src/NzbDrone.Core/Indexers/Definitions/Redacted.cs b/src/NzbDrone.Core/Indexers/Definitions/Redacted.cs index 6fe62739e..e00708195 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Redacted.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Redacted.cs @@ -326,7 +326,7 @@ namespace NzbDrone.Core.Indexers.Definitions } } - public class RedactedSettingsValidator : AbstractValidator + public class RedactedSettingsValidator : NoAuthSettingsValidator { public RedactedSettingsValidator() { @@ -336,7 +336,7 @@ namespace NzbDrone.Core.Indexers.Definitions public class RedactedSettings : NoAuthTorrentBaseSettings { - private static readonly RedactedSettingsValidator Validator = new RedactedSettingsValidator(); + private static readonly RedactedSettingsValidator Validator = new (); public RedactedSettings() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/SceneHD.cs b/src/NzbDrone.Core/Indexers/Definitions/SceneHD.cs index 28c479133..4a67b60ad 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/SceneHD.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/SceneHD.cs @@ -233,7 +233,7 @@ namespace NzbDrone.Core.Indexers.Definitions public Action, DateTime?> CookiesUpdater { get; set; } } - public class SceneHDSettingsValidator : AbstractValidator + public class SceneHDSettingsValidator : NoAuthSettingsValidator { public SceneHDSettingsValidator() { @@ -243,7 +243,7 @@ namespace NzbDrone.Core.Indexers.Definitions public class SceneHDSettings : NoAuthTorrentBaseSettings { - private static readonly SceneHDSettingsValidator Validator = new SceneHDSettingsValidator(); + private static readonly SceneHDSettingsValidator Validator = new (); public SceneHDSettings() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/SpeedApp/SpeedAppBase.cs b/src/NzbDrone.Core/Indexers/Definitions/SpeedApp/SpeedAppBase.cs index a27542bf1..1fed8e6fe 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/SpeedApp/SpeedAppBase.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/SpeedApp/SpeedAppBase.cs @@ -332,7 +332,7 @@ namespace NzbDrone.Core.Indexers.Definitions } } - public class SpeedAppSettingsValidator : AbstractValidator + public class SpeedAppSettingsValidator : NoAuthSettingsValidator { public SpeedAppSettingsValidator() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/TorrentPotato/TorrentPotatoSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/TorrentPotato/TorrentPotatoSettings.cs index e7bf2f8dc..3cf3ae35d 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/TorrentPotato/TorrentPotatoSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/TorrentPotato/TorrentPotatoSettings.cs @@ -5,16 +5,28 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.TorrentPotato { - public class TorrentPotatoSettings : NoAuthTorrentBaseSettings + public class TorrentPotatoSettingsValidator : NoAuthSettingsValidator { - public TorrentPotatoSettings() + public TorrentPotatoSettingsValidator() { + RuleFor(c => c.User).NotEmpty(); + RuleFor(c => c.Passkey).NotEmpty(); } + } + + public class TorrentPotatoSettings : NoAuthTorrentBaseSettings + { + private static readonly TorrentPotatoSettingsValidator Validator = new (); [FieldDefinition(2, Label = "Username", HelpText = "Indexer Username", Privacy = PrivacyLevel.UserName)] public string User { get; set; } [FieldDefinition(3, Label = "Passkey", HelpText = "Indexer Password", Privacy = PrivacyLevel.Password, Type = FieldType.Password)] public string Passkey { get; set; } + + public override NzbDroneValidationResult Validate() + { + return new NzbDroneValidationResult(Validator.Validate(this)); + } } } diff --git a/src/NzbDrone.Core/Indexers/Definitions/TorrentSyndikat.cs b/src/NzbDrone.Core/Indexers/Definitions/TorrentSyndikat.cs index 05585779b..e2b899f34 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/TorrentSyndikat.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/TorrentSyndikat.cs @@ -323,7 +323,7 @@ namespace NzbDrone.Core.Indexers.Definitions public Action, DateTime?> CookiesUpdater { get; set; } } - public class TorrentSyndikatSettingsValidator : AbstractValidator + public class TorrentSyndikatSettingsValidator : NoAuthSettingsValidator { public TorrentSyndikatSettingsValidator() { @@ -333,7 +333,7 @@ namespace NzbDrone.Core.Indexers.Definitions public class TorrentSyndikatSettings : NoAuthTorrentBaseSettings { - private static readonly TorrentSyndikatSettingsValidator Validator = new TorrentSyndikatSettingsValidator(); + private static readonly TorrentSyndikatSettingsValidator Validator = new (); public TorrentSyndikatSettings() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabSettings.cs index 4f4547fd6..4374c1256 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabSettings.cs @@ -41,14 +41,10 @@ namespace NzbDrone.Core.Indexers.Torznab public class TorznabSettings : NewznabSettings, ITorrentIndexerSettings { - private static readonly TorznabSettingsValidator Validator = new TorznabSettingsValidator(); - - public TorznabSettings() - { - } + private static readonly TorznabSettingsValidator Validator = new (); [FieldDefinition(3)] - public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new IndexerTorrentBaseSettings(); + public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new (); public override NzbDroneValidationResult Validate() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/UNIT3D/Unit3dSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/UNIT3D/Unit3dSettings.cs index d15f409ef..eac5ccf22 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/UNIT3D/Unit3dSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/UNIT3D/Unit3dSettings.cs @@ -5,7 +5,7 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions.UNIT3D { - public class Unit3dSettingsValidator : AbstractValidator + public class Unit3dSettingsValidator : NoAuthSettingsValidator { public Unit3dSettingsValidator() { @@ -15,11 +15,7 @@ namespace NzbDrone.Core.Indexers.Definitions.UNIT3D public class Unit3dSettings : NoAuthTorrentBaseSettings { - private static readonly Unit3dSettingsValidator Validator = new Unit3dSettingsValidator(); - - public Unit3dSettings() - { - } + private static readonly Unit3dSettingsValidator Validator = new (); [FieldDefinition(2, Label = "API Key", HelpText = "Site API Key generated in My Security", Privacy = PrivacyLevel.ApiKey)] public string ApiKey { get; set; } diff --git a/src/NzbDrone.Core/Indexers/Definitions/Xthor/XthorSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Xthor/XthorSettings.cs index 0ec5a5e16..bd7003383 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Xthor/XthorSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/Xthor/XthorSettings.cs @@ -4,9 +4,13 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Definitions.Xthor { + public class XthorSettingsValidator : NoAuthSettingsValidator + { + } + public class XthorSettings : NoAuthTorrentBaseSettings { - private static readonly XthorSettingsValidator Validator = new XthorSettingsValidator(); + private static readonly XthorSettingsValidator Validator = new (); public XthorSettings() { diff --git a/src/NzbDrone.Core/Indexers/Definitions/Xthor/XthorSettingsValidator.cs b/src/NzbDrone.Core/Indexers/Definitions/Xthor/XthorSettingsValidator.cs deleted file mode 100644 index d0bd64afc..000000000 --- a/src/NzbDrone.Core/Indexers/Definitions/Xthor/XthorSettingsValidator.cs +++ /dev/null @@ -1,8 +0,0 @@ -using FluentValidation; - -namespace NzbDrone.Core.Indexers.Definitions.Xthor -{ - public class XthorSettingsValidator : AbstractValidator - { - } -} diff --git a/src/NzbDrone.Core/Indexers/IndexerBaseSettings.cs b/src/NzbDrone.Core/Indexers/IndexerBaseSettings.cs index 600d4d7d9..a6a0c9451 100644 --- a/src/NzbDrone.Core/Indexers/IndexerBaseSettings.cs +++ b/src/NzbDrone.Core/Indexers/IndexerBaseSettings.cs @@ -17,7 +17,7 @@ namespace NzbDrone.Core.Indexers public class IndexerBaseSettings { - private static readonly IndexerCommonSettingsValidator Validator = new IndexerCommonSettingsValidator(); + private static readonly IndexerCommonSettingsValidator Validator = new (); [FieldDefinition(1, Type = FieldType.Number, Label = "Query Limit", HelpText = "The number of queries within a rolling 24 hour period Prowlarr will allow to the site", Advanced = true)] public int? QueryLimit { get; set; } diff --git a/src/NzbDrone.Core/Indexers/IndexerTorrentBaseSettings.cs b/src/NzbDrone.Core/Indexers/IndexerTorrentBaseSettings.cs index cdcd43c03..72f733ffd 100644 --- a/src/NzbDrone.Core/Indexers/IndexerTorrentBaseSettings.cs +++ b/src/NzbDrone.Core/Indexers/IndexerTorrentBaseSettings.cs @@ -1,6 +1,6 @@ +using System; using FluentValidation; using NzbDrone.Core.Annotations; -using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers { @@ -10,17 +10,20 @@ namespace NzbDrone.Core.Indexers { RuleFor(c => c.SeedRatio).GreaterThan(0.0) .When(c => c.SeedRatio.HasValue) - .AsWarning().WithMessage("Should be greater than zero"); + .WithMessage("Should be greater than zero"); RuleFor(c => c.SeedTime).GreaterThan(0) .When(c => c.SeedTime.HasValue) - .AsWarning().WithMessage("Should be greater than zero"); + .WithMessage("Should be greater than zero"); + + RuleFor(c => c.PackSeedTime).GreaterThan(0) + .When(c => c.PackSeedTime.HasValue) + .WithMessage("Should be greater than zero"); if (seedRatioMinimum != 0.0) { RuleFor(c => c.SeedRatio).GreaterThanOrEqualTo(seedRatioMinimum) .When(c => c.SeedRatio > 0.0) - .AsWarning() .WithMessage($"Under {seedRatioMinimum} leads to H&R"); } @@ -28,15 +31,21 @@ namespace NzbDrone.Core.Indexers { RuleFor(c => c.SeedTime).GreaterThanOrEqualTo(seedTimeMinimum) .When(c => c.SeedTime > 0) - .AsWarning() .WithMessage($"Under {seedTimeMinimum} leads to H&R"); } + + if (seasonPackSeedTimeMinimum != 0) + { + RuleFor(c => c.PackSeedTime).GreaterThanOrEqualTo(seasonPackSeedTimeMinimum) + .When(c => c.PackSeedTime > 0) + .WithMessage($"Under {seasonPackSeedTimeMinimum} leads to H&R"); + } } } public class IndexerTorrentBaseSettings { - private static readonly IndexerTorrentSettingsValidator Validator = new IndexerTorrentSettingsValidator(); + private static readonly IndexerTorrentSettingsValidator Validator = new (); [FieldDefinition(1, Type = FieldType.Textbox, Label = "Seed Ratio", HelpText = "The ratio a torrent should reach before stopping, empty is app's default", Advanced = true)] public double? SeedRatio { get; set; } diff --git a/src/NzbDrone.Core/Indexers/Settings/CookieTorrentBaseSettings.cs b/src/NzbDrone.Core/Indexers/Settings/CookieTorrentBaseSettings.cs index 81cef47ba..a4970a17e 100644 --- a/src/NzbDrone.Core/Indexers/Settings/CookieTorrentBaseSettings.cs +++ b/src/NzbDrone.Core/Indexers/Settings/CookieTorrentBaseSettings.cs @@ -4,19 +4,19 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Settings { - public class CookieTorrentBaseSettings : ITorrentIndexerSettings + public class CookieBaseSettingsValidator : AbstractValidator { - public class CookieBaseSettingsValidator : AbstractValidator + public CookieBaseSettingsValidator() { - public CookieBaseSettingsValidator() - { - RuleFor(c => c.Cookie).NotEmpty(); - RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator()); - RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator()); - } + RuleFor(c => c.Cookie).NotEmpty(); + RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator()); + RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator()); } + } - private static readonly CookieBaseSettingsValidator Validator = new CookieBaseSettingsValidator(); + public class CookieTorrentBaseSettings : ITorrentIndexerSettings + { + private static readonly CookieBaseSettingsValidator Validator = new (); public CookieTorrentBaseSettings() { @@ -30,10 +30,10 @@ namespace NzbDrone.Core.Indexers.Settings public string Cookie { get; set; } [FieldDefinition(10)] - public IndexerBaseSettings BaseSettings { get; set; } = new IndexerBaseSettings(); + public IndexerBaseSettings BaseSettings { get; set; } = new (); [FieldDefinition(11)] - public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new IndexerTorrentBaseSettings(); + public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new (); public virtual NzbDroneValidationResult Validate() { diff --git a/src/NzbDrone.Core/Indexers/Settings/NoAuthTorrentBaseSettings.cs b/src/NzbDrone.Core/Indexers/Settings/NoAuthTorrentBaseSettings.cs index b9fd2688f..14eefa481 100644 --- a/src/NzbDrone.Core/Indexers/Settings/NoAuthTorrentBaseSettings.cs +++ b/src/NzbDrone.Core/Indexers/Settings/NoAuthTorrentBaseSettings.cs @@ -4,7 +4,8 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Settings { - public class NoAuthSettingsValidator : AbstractValidator + public class NoAuthSettingsValidator : AbstractValidator + where T : NoAuthTorrentBaseSettings { public NoAuthSettingsValidator() { @@ -15,16 +16,16 @@ namespace NzbDrone.Core.Indexers.Settings public class NoAuthTorrentBaseSettings : ITorrentIndexerSettings { - private static readonly NoAuthSettingsValidator Validator = new NoAuthSettingsValidator(); + private static readonly NoAuthSettingsValidator Validator = new (); [FieldDefinition(1, Label = "Base Url", Type = FieldType.Select, SelectOptionsProviderAction = "getUrls", HelpText = "Select which baseurl Prowlarr will use for requests to the site")] public string BaseUrl { get; set; } [FieldDefinition(10)] - public IndexerBaseSettings BaseSettings { get; set; } = new IndexerBaseSettings(); + public IndexerBaseSettings BaseSettings { get; set; } = new (); [FieldDefinition(11)] - public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new IndexerTorrentBaseSettings(); + public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new (); public virtual NzbDroneValidationResult Validate() { diff --git a/src/NzbDrone.Core/Indexers/Settings/UserPassTorrentBaseSettings.cs b/src/NzbDrone.Core/Indexers/Settings/UserPassTorrentBaseSettings.cs index e8c7f2709..8992fa6f7 100644 --- a/src/NzbDrone.Core/Indexers/Settings/UserPassTorrentBaseSettings.cs +++ b/src/NzbDrone.Core/Indexers/Settings/UserPassTorrentBaseSettings.cs @@ -4,20 +4,21 @@ using NzbDrone.Core.Validation; namespace NzbDrone.Core.Indexers.Settings { - public class UserPassTorrentBaseSettings : ITorrentIndexerSettings + public class UserPassBaseSettingsValidator : AbstractValidator + where T : UserPassTorrentBaseSettings { - public class UserPassBaseSettingsValidator : AbstractValidator + public UserPassBaseSettingsValidator() { - public UserPassBaseSettingsValidator() - { - RuleFor(c => c.Username).NotEmpty(); - RuleFor(c => c.Password).NotEmpty(); - RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator()); - RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator()); - } + RuleFor(c => c.Username).NotEmpty(); + RuleFor(c => c.Password).NotEmpty(); + RuleFor(x => x.BaseSettings).SetValidator(new IndexerCommonSettingsValidator()); + RuleFor(x => x.TorrentBaseSettings).SetValidator(new IndexerTorrentSettingsValidator()); } + } - private static readonly UserPassBaseSettingsValidator Validator = new UserPassBaseSettingsValidator(); + public class UserPassTorrentBaseSettings : ITorrentIndexerSettings + { + private static readonly UserPassBaseSettingsValidator Validator = new (); public UserPassTorrentBaseSettings() { @@ -35,12 +36,12 @@ namespace NzbDrone.Core.Indexers.Settings public string Password { get; set; } [FieldDefinition(10)] - public IndexerBaseSettings BaseSettings { get; set; } = new IndexerBaseSettings(); + public IndexerBaseSettings BaseSettings { get; set; } = new (); [FieldDefinition(11)] - public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new IndexerTorrentBaseSettings(); + public IndexerTorrentBaseSettings TorrentBaseSettings { get; set; } = new (); - public NzbDroneValidationResult Validate() + public virtual NzbDroneValidationResult Validate() { return new NzbDroneValidationResult(Validator.Validate(this)); }