mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-11-24 11:43:07 +01:00
Fixed: Validation when testing indexers, import lists, connections and download clients
This commit is contained in:
parent
e7ca98489e
commit
fa9136c4d1
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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<string, object>)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();
|
||||
|
||||
|
@ -24,7 +24,8 @@ namespace NzbDrone.Common.Disk
|
||||
"/boot",
|
||||
"/lib",
|
||||
"/sbin",
|
||||
"/proc"
|
||||
"/proc",
|
||||
"/usr/bin"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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<ValidationFailure>();
|
||||
|
||||
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<string, object>)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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user