From 9bb394f420ef220adb896a478f176ea4d40b411e Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 28 Mar 2022 20:04:10 -0500 Subject: [PATCH] Fixed: Validation when testing indexers, import lists, connections and download clients Co-Authored-By: Mark McDowall --- src/NzbDrone.Common/Disk/SystemFolders.cs | 5 +++-- .../DownloadClient/DownloadClientController.cs | 10 ---------- .../ImportLists/ImportListController.cs | 10 ---------- src/Radarr.Api.V3/Indexers/IndexerController.cs | 10 ---------- src/Radarr.Api.V3/Metadata/MetadataController.cs | 10 ---------- .../Notifications/NotificationController.cs | 10 ---------- src/Radarr.Api.V3/ProviderControllerBase.cs | 14 +++++++------- 7 files changed, 10 insertions(+), 59 deletions(-) diff --git a/src/NzbDrone.Common/Disk/SystemFolders.cs b/src/NzbDrone.Common/Disk/SystemFolders.cs index c108e3d02..1c81ab1e0 100644 --- a/src/NzbDrone.Common/Disk/SystemFolders.cs +++ b/src/NzbDrone.Common/Disk/SystemFolders.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using NzbDrone.Common.EnvironmentInfo; @@ -24,7 +24,8 @@ namespace NzbDrone.Common.Disk "/boot", "/lib", "/sbin", - "/proc" + "/proc", + "/usr/bin" }; } } diff --git a/src/Radarr.Api.V3/DownloadClient/DownloadClientController.cs b/src/Radarr.Api.V3/DownloadClient/DownloadClientController.cs index 13a1082c0..a1f602a80 100644 --- a/src/Radarr.Api.V3/DownloadClient/DownloadClientController.cs +++ b/src/Radarr.Api.V3/DownloadClient/DownloadClientController.cs @@ -12,15 +12,5 @@ namespace Radarr.Api.V3.DownloadClient : base(downloadClientFactory, "downloadclient", ResourceMapper) { } - - protected override void Validate(DownloadClientDefinition definition, bool includeWarnings) - { - if (!definition.Enable) - { - return; - } - - base.Validate(definition, includeWarnings); - } } } diff --git a/src/Radarr.Api.V3/ImportLists/ImportListController.cs b/src/Radarr.Api.V3/ImportLists/ImportListController.cs index 2ba4d8613..2b035eeb4 100644 --- a/src/Radarr.Api.V3/ImportLists/ImportListController.cs +++ b/src/Radarr.Api.V3/ImportLists/ImportListController.cs @@ -20,15 +20,5 @@ namespace Radarr.Api.V3.ImportLists SharedValidator.RuleFor(c => c.QualityProfileId).ValidId(); SharedValidator.RuleFor(c => c.QualityProfileId).SetValidator(profileExistsValidator); } - - protected override void Validate(ImportListDefinition definition, bool includeWarnings) - { - if (!definition.Enable) - { - return; - } - - base.Validate(definition, includeWarnings); - } } } diff --git a/src/Radarr.Api.V3/Indexers/IndexerController.cs b/src/Radarr.Api.V3/Indexers/IndexerController.cs index 0eeaee4bc..2347d36a6 100644 --- a/src/Radarr.Api.V3/Indexers/IndexerController.cs +++ b/src/Radarr.Api.V3/Indexers/IndexerController.cs @@ -12,15 +12,5 @@ namespace Radarr.Api.V3.Indexers : base(indexerFactory, "indexer", ResourceMapper) { } - - protected override void Validate(IndexerDefinition definition, bool includeWarnings) - { - if (!definition.Enable) - { - return; - } - - base.Validate(definition, includeWarnings); - } } } diff --git a/src/Radarr.Api.V3/Metadata/MetadataController.cs b/src/Radarr.Api.V3/Metadata/MetadataController.cs index db86d30bf..8342f5a6b 100644 --- a/src/Radarr.Api.V3/Metadata/MetadataController.cs +++ b/src/Radarr.Api.V3/Metadata/MetadataController.cs @@ -12,15 +12,5 @@ namespace Radarr.Api.V3.Metadata : base(metadataFactory, "metadata", ResourceMapper) { } - - protected override void Validate(MetadataDefinition definition, bool includeWarnings) - { - if (!definition.Enable) - { - return; - } - - base.Validate(definition, includeWarnings); - } } } diff --git a/src/Radarr.Api.V3/Notifications/NotificationController.cs b/src/Radarr.Api.V3/Notifications/NotificationController.cs index e7810b69f..7cf5b3b2f 100644 --- a/src/Radarr.Api.V3/Notifications/NotificationController.cs +++ b/src/Radarr.Api.V3/Notifications/NotificationController.cs @@ -12,15 +12,5 @@ namespace Radarr.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); - } } } diff --git a/src/Radarr.Api.V3/ProviderControllerBase.cs b/src/Radarr.Api.V3/ProviderControllerBase.cs index 51955bbc8..2d506b6b6 100644 --- a/src/Radarr.Api.V3/ProviderControllerBase.cs +++ b/src/Radarr.Api.V3/ProviderControllerBase.cs @@ -61,7 +61,7 @@ namespace Radarr.Api.V3 [RestPostById] public ActionResult CreateProvider(TProviderResource providerResource) { - var providerDefinition = GetDefinition(providerResource, false); + var providerDefinition = GetDefinition(providerResource, true, false, false); if (providerDefinition.Enable) { @@ -76,7 +76,7 @@ namespace Radarr.Api.V3 [RestPutById] public ActionResult 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. @@ -90,11 +90,11 @@ namespace Radarr.Api.V3 return Accepted(providerResource.Id); } - 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); } @@ -135,7 +135,7 @@ namespace Radarr.Api.V3 [HttpPost("test")] public object Test([FromBody] TProviderResource providerResource) { - var providerDefinition = GetDefinition(providerResource, true); + var providerDefinition = GetDefinition(providerResource, true, true, true); Test(providerDefinition, true); @@ -168,7 +168,7 @@ namespace Radarr.Api.V3 [HttpPost("action/{name}")] public IActionResult RequestAction(string name, [FromBody] TProviderResource resource) { - var providerDefinition = GetDefinition(resource, true, false); + var providerDefinition = GetDefinition(resource, false, false, false); var query = Request.Query.ToDictionary(x => x.Key, x => x.Value.ToString()); @@ -177,7 +177,7 @@ namespace Radarr.Api.V3 return Content(data.ToJson(), "application/json"); } - protected virtual void Validate(TProviderDefinition definition, bool includeWarnings) + private void Validate(TProviderDefinition definition, bool includeWarnings) { var validationResult = definition.Settings.Validate();