From fa9136c4d15481270d212efe70c8a3482cf861dc Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 28 Mar 2022 17:32:48 -0700 Subject: [PATCH] Fixed: Validation when testing indexers, import lists, connections and download clients --- .../DownloadClient/DownloadClientModule.cs | 6 ----- src/NzbDrone.Api/Indexers/IndexerModule.cs | 6 ----- src/NzbDrone.Api/Metadata/MetadataModule.cs | 6 ----- .../Notifications/NotificationModule.cs | 6 ----- src/NzbDrone.Api/ProviderModuleBase.cs | 17 ++++++-------- src/NzbDrone.Common/Disk/SystemFolders.cs | 3 ++- .../DownloadClient/DownloadClientModule.cs | 6 ----- .../ImportLists/ImportListModule.cs | 9 -------- src/Sonarr.Api.V3/Indexers/IndexerModule.cs | 6 ----- src/Sonarr.Api.V3/Metadata/MetadataModule.cs | 6 ----- .../Notifications/NotificationModule.cs | 6 ----- src/Sonarr.Api.V3/ProviderModuleBase.cs | 23 +++++++++++-------- 12 files changed, 22 insertions(+), 78 deletions(-) diff --git a/src/NzbDrone.Api/DownloadClient/DownloadClientModule.cs b/src/NzbDrone.Api/DownloadClient/DownloadClientModule.cs index 561ce58df..4a39bd65a 100644 --- a/src/NzbDrone.Api/DownloadClient/DownloadClientModule.cs +++ b/src/NzbDrone.Api/DownloadClient/DownloadClientModule.cs @@ -30,11 +30,5 @@ namespace NzbDrone.Api.DownloadClient definition.RemoveCompletedDownloads = resource.RemoveCompletedDownloads; definition.RemoveFailedDownloads = resource.RemoveFailedDownloads; } - - protected override void Validate(DownloadClientDefinition definition, bool includeWarnings) - { - if (!definition.Enable) return; - base.Validate(definition, includeWarnings); - } } } \ No newline at end of file diff --git a/src/NzbDrone.Api/Indexers/IndexerModule.cs b/src/NzbDrone.Api/Indexers/IndexerModule.cs index fff6bcc02..b5c84af6b 100644 --- a/src/NzbDrone.Api/Indexers/IndexerModule.cs +++ b/src/NzbDrone.Api/Indexers/IndexerModule.cs @@ -30,11 +30,5 @@ namespace NzbDrone.Api.Indexers definition.EnableInteractiveSearch = resource.EnableSearch; definition.Priority = resource.Priority; } - - protected override void Validate(IndexerDefinition definition, bool includeWarnings) - { - if (!definition.Enable) return; - base.Validate(definition, includeWarnings); - } } } diff --git a/src/NzbDrone.Api/Metadata/MetadataModule.cs b/src/NzbDrone.Api/Metadata/MetadataModule.cs index ab88ab044..cad91f896 100644 --- a/src/NzbDrone.Api/Metadata/MetadataModule.cs +++ b/src/NzbDrone.Api/Metadata/MetadataModule.cs @@ -22,11 +22,5 @@ namespace NzbDrone.Api.Metadata definition.Enable = resource.Enable; } - - protected override void Validate(MetadataDefinition definition, bool includeWarnings) - { - if (!definition.Enable) return; - base.Validate(definition, includeWarnings); - } } } \ No newline at end of file diff --git a/src/NzbDrone.Api/Notifications/NotificationModule.cs b/src/NzbDrone.Api/Notifications/NotificationModule.cs index 88f42a043..78b0304c2 100644 --- a/src/NzbDrone.Api/Notifications/NotificationModule.cs +++ b/src/NzbDrone.Api/Notifications/NotificationModule.cs @@ -38,11 +38,5 @@ namespace NzbDrone.Api.Notifications definition.SupportsOnRename = resource.SupportsOnRename; definition.Tags = resource.Tags; } - - protected override void Validate(NotificationDefinition definition, bool includeWarnings) - { - if (!definition.OnGrab && !definition.OnDownload) return; - base.Validate(definition, includeWarnings); - } } } \ No newline at end of file diff --git a/src/NzbDrone.Api/ProviderModuleBase.cs b/src/NzbDrone.Api/ProviderModuleBase.cs index 22489e4f7..313e1aeb9 100644 --- a/src/NzbDrone.Api/ProviderModuleBase.cs +++ b/src/NzbDrone.Api/ProviderModuleBase.cs @@ -74,7 +74,7 @@ namespace NzbDrone.Api private int CreateProvider(TProviderResource providerResource) { - var providerDefinition = GetDefinition(providerResource, false); + var providerDefinition = GetDefinition(providerResource, true, false, false); if (providerDefinition.Enable) { @@ -88,18 +88,18 @@ namespace NzbDrone.Api private void UpdateProvider(TProviderResource providerResource) { - var providerDefinition = GetDefinition(providerResource, false); + var providerDefinition = GetDefinition(providerResource, true, false, false); _providerFactory.Update(providerDefinition); } - private TProviderDefinition GetDefinition(TProviderResource providerResource, bool includeWarnings = false, bool validate = true) + private TProviderDefinition GetDefinition(TProviderResource providerResource, bool validate, bool includeWarnings, bool forceValidate) { var definition = new TProviderDefinition(); MapToModel(definition, providerResource); - if (validate) + if (validate && (definition.Enable || forceValidate)) { Validate(definition, includeWarnings); } @@ -170,19 +170,16 @@ namespace NzbDrone.Api private object Test(TProviderResource providerResource) { - // Don't validate when getting the definition so we can validate afterwards (avoids validation being skipped because the provider is disabled) - var providerDefinition = GetDefinition(providerResource, true, false); + var providerDefinition = GetDefinition(providerResource, true, true, true); - Validate(providerDefinition, true); Test(providerDefinition, true); return "{}"; } - private object RequestAction(string action, TProviderResource providerResource) { - var providerDefinition = GetDefinition(providerResource, true, false); + var providerDefinition = GetDefinition(providerResource, false, false, false); var query = ((IDictionary)Request.Query.ToDictionary()).ToDictionary(k => k.Key, k => k.Value.ToString()); @@ -192,7 +189,7 @@ namespace NzbDrone.Api return resp; } - protected virtual void Validate(TProviderDefinition definition, bool includeWarnings) + private void Validate(TProviderDefinition definition, bool includeWarnings) { var validationResult = definition.Settings.Validate(); diff --git a/src/NzbDrone.Common/Disk/SystemFolders.cs b/src/NzbDrone.Common/Disk/SystemFolders.cs index c108e3d02..2acedf237 100644 --- a/src/NzbDrone.Common/Disk/SystemFolders.cs +++ b/src/NzbDrone.Common/Disk/SystemFolders.cs @@ -24,7 +24,8 @@ namespace NzbDrone.Common.Disk "/boot", "/lib", "/sbin", - "/proc" + "/proc", + "/usr/bin" }; } } diff --git a/src/Sonarr.Api.V3/DownloadClient/DownloadClientModule.cs b/src/Sonarr.Api.V3/DownloadClient/DownloadClientModule.cs index 7db21fd69..be45700d5 100644 --- a/src/Sonarr.Api.V3/DownloadClient/DownloadClientModule.cs +++ b/src/Sonarr.Api.V3/DownloadClient/DownloadClientModule.cs @@ -10,11 +10,5 @@ namespace Sonarr.Api.V3.DownloadClient : base(downloadClientFactory, "downloadclient", ResourceMapper) { } - - protected override void Validate(DownloadClientDefinition definition, bool includeWarnings) - { - if (!definition.Enable) return; - base.Validate(definition, includeWarnings); - } } } \ No newline at end of file diff --git a/src/Sonarr.Api.V3/ImportLists/ImportListModule.cs b/src/Sonarr.Api.V3/ImportLists/ImportListModule.cs index 2b6146dca..aab081598 100644 --- a/src/Sonarr.Api.V3/ImportLists/ImportListModule.cs +++ b/src/Sonarr.Api.V3/ImportLists/ImportListModule.cs @@ -21,14 +21,5 @@ namespace Sonarr.Api.V3.ImportLists SharedValidator.RuleFor(c => c.QualityProfileId).SetValidator(profileExistsValidator); SharedValidator.RuleFor(c => c.LanguageProfileId).SetValidator(languageProfileExistsValidator); } - - protected override void Validate(ImportListDefinition definition, bool includeWarnings) - { - if (!definition.Enable) - { - return; - } - base.Validate(definition, includeWarnings); - } } } diff --git a/src/Sonarr.Api.V3/Indexers/IndexerModule.cs b/src/Sonarr.Api.V3/Indexers/IndexerModule.cs index be93f4537..ec32cfecc 100644 --- a/src/Sonarr.Api.V3/Indexers/IndexerModule.cs +++ b/src/Sonarr.Api.V3/Indexers/IndexerModule.cs @@ -10,11 +10,5 @@ namespace Sonarr.Api.V3.Indexers : base(indexerFactory, "indexer", ResourceMapper) { } - - protected override void Validate(IndexerDefinition definition, bool includeWarnings) - { - if (!definition.Enable) return; - base.Validate(definition, includeWarnings); - } } } \ No newline at end of file diff --git a/src/Sonarr.Api.V3/Metadata/MetadataModule.cs b/src/Sonarr.Api.V3/Metadata/MetadataModule.cs index 107588f57..9cc8e8988 100644 --- a/src/Sonarr.Api.V3/Metadata/MetadataModule.cs +++ b/src/Sonarr.Api.V3/Metadata/MetadataModule.cs @@ -10,11 +10,5 @@ namespace Sonarr.Api.V3.Metadata : base(metadataFactory, "metadata", ResourceMapper) { } - - protected override void Validate(MetadataDefinition definition, bool includeWarnings) - { - if (!definition.Enable) return; - base.Validate(definition, includeWarnings); - } } } \ No newline at end of file diff --git a/src/Sonarr.Api.V3/Notifications/NotificationModule.cs b/src/Sonarr.Api.V3/Notifications/NotificationModule.cs index 2b9a3541c..f2dde4aca 100644 --- a/src/Sonarr.Api.V3/Notifications/NotificationModule.cs +++ b/src/Sonarr.Api.V3/Notifications/NotificationModule.cs @@ -10,11 +10,5 @@ namespace Sonarr.Api.V3.Notifications : base(notificationFactory, "notification", ResourceMapper) { } - - protected override void Validate(NotificationDefinition definition, bool includeWarnings) - { - if (!definition.OnGrab && !definition.OnDownload) return; - base.Validate(definition, includeWarnings); - } } } \ No newline at end of file diff --git a/src/Sonarr.Api.V3/ProviderModuleBase.cs b/src/Sonarr.Api.V3/ProviderModuleBase.cs index a96faace1..e57bbe80d 100644 --- a/src/Sonarr.Api.V3/ProviderModuleBase.cs +++ b/src/Sonarr.Api.V3/ProviderModuleBase.cs @@ -70,7 +70,7 @@ namespace Sonarr.Api.V3 private int CreateProvider(TProviderResource providerResource) { - var providerDefinition = GetDefinition(providerResource, false); + var providerDefinition = GetDefinition(providerResource, true, false, false); if (providerDefinition.Enable) { @@ -84,7 +84,7 @@ namespace Sonarr.Api.V3 private void UpdateProvider(TProviderResource providerResource) { - var providerDefinition = GetDefinition(providerResource, false); + var providerDefinition = GetDefinition(providerResource, true, false, false); var forceSave = Request.GetBooleanQueryParameter("forceSave"); // Only test existing definitions if it is enabled and forceSave isn't set. @@ -96,11 +96,11 @@ namespace Sonarr.Api.V3 _providerFactory.Update(providerDefinition); } - private TProviderDefinition GetDefinition(TProviderResource providerResource, bool includeWarnings = false, bool validate = true) + private TProviderDefinition GetDefinition(TProviderResource providerResource, bool validate, bool includeWarnings, bool forceValidate) { var definition = _resourceMapper.ToModel(providerResource); - if (validate) + if (validate && (definition.Enable || forceValidate)) { Validate(definition, includeWarnings); } @@ -139,7 +139,7 @@ namespace Sonarr.Api.V3 private object Test(TProviderResource providerResource) { - var providerDefinition = GetDefinition(providerResource, true); + var providerDefinition = GetDefinition(providerResource, true, true, true); Test(providerDefinition, true); @@ -155,13 +155,16 @@ namespace Sonarr.Api.V3 foreach (var definition in providerDefinitions) { - var validationResult = _providerFactory.Test(definition); + var validationFailures = new List(); + + validationFailures.AddRange(definition.Settings.Validate().Errors); + validationFailures.AddRange(_providerFactory.Test(definition).Errors); result.Add(new ProviderTestAllResult { Id = definition.Id, - ValidationFailures = validationResult.Errors.ToList() - }); + ValidationFailures = validationFailures + }); } return ResponseWithCode(result, result.Any(c => !c.IsValid) ? HttpStatusCode.BadRequest : HttpStatusCode.OK); @@ -169,7 +172,7 @@ namespace Sonarr.Api.V3 private object RequestAction(string action, TProviderResource providerResource) { - var providerDefinition = GetDefinition(providerResource, true, false); + var providerDefinition = GetDefinition(providerResource, false, false, false); var query = ((IDictionary)Request.Query.ToDictionary()).ToDictionary(k => k.Key, k => k.Value.ToString()); @@ -179,7 +182,7 @@ namespace Sonarr.Api.V3 return resp; } - protected virtual void Validate(TProviderDefinition definition, bool includeWarnings) + private void Validate(TProviderDefinition definition, bool includeWarnings) { var validationResult = definition.Settings.Validate();