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.RemoveCompletedDownloads = resource.RemoveCompletedDownloads;
|
||||||
definition.RemoveFailedDownloads = resource.RemoveFailedDownloads;
|
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.EnableInteractiveSearch = resource.EnableSearch;
|
||||||
definition.Priority = resource.Priority;
|
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;
|
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.SupportsOnRename = resource.SupportsOnRename;
|
||||||
definition.Tags = resource.Tags;
|
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)
|
private int CreateProvider(TProviderResource providerResource)
|
||||||
{
|
{
|
||||||
var providerDefinition = GetDefinition(providerResource, false);
|
var providerDefinition = GetDefinition(providerResource, true, false, false);
|
||||||
|
|
||||||
if (providerDefinition.Enable)
|
if (providerDefinition.Enable)
|
||||||
{
|
{
|
||||||
|
@ -88,18 +88,18 @@ namespace NzbDrone.Api
|
||||||
|
|
||||||
private void UpdateProvider(TProviderResource providerResource)
|
private void UpdateProvider(TProviderResource providerResource)
|
||||||
{
|
{
|
||||||
var providerDefinition = GetDefinition(providerResource, false);
|
var providerDefinition = GetDefinition(providerResource, true, false, false);
|
||||||
|
|
||||||
_providerFactory.Update(providerDefinition);
|
_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();
|
var definition = new TProviderDefinition();
|
||||||
|
|
||||||
MapToModel(definition, providerResource);
|
MapToModel(definition, providerResource);
|
||||||
|
|
||||||
if (validate)
|
if (validate && (definition.Enable || forceValidate))
|
||||||
{
|
{
|
||||||
Validate(definition, includeWarnings);
|
Validate(definition, includeWarnings);
|
||||||
}
|
}
|
||||||
|
@ -170,19 +170,16 @@ namespace NzbDrone.Api
|
||||||
|
|
||||||
private object Test(TProviderResource providerResource)
|
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, true, true);
|
||||||
var providerDefinition = GetDefinition(providerResource, true, false);
|
|
||||||
|
|
||||||
Validate(providerDefinition, true);
|
|
||||||
Test(providerDefinition, true);
|
Test(providerDefinition, true);
|
||||||
|
|
||||||
return "{}";
|
return "{}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private object RequestAction(string action, TProviderResource providerResource)
|
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());
|
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;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Validate(TProviderDefinition definition, bool includeWarnings)
|
private void Validate(TProviderDefinition definition, bool includeWarnings)
|
||||||
{
|
{
|
||||||
var validationResult = definition.Settings.Validate();
|
var validationResult = definition.Settings.Validate();
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ namespace NzbDrone.Common.Disk
|
||||||
"/boot",
|
"/boot",
|
||||||
"/lib",
|
"/lib",
|
||||||
"/sbin",
|
"/sbin",
|
||||||
"/proc"
|
"/proc",
|
||||||
|
"/usr/bin"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,5 @@ namespace Sonarr.Api.V3.DownloadClient
|
||||||
: base(downloadClientFactory, "downloadclient", ResourceMapper)
|
: 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.QualityProfileId).SetValidator(profileExistsValidator);
|
||||||
SharedValidator.RuleFor(c => c.LanguageProfileId).SetValidator(languageProfileExistsValidator);
|
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)
|
: 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)
|
: 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)
|
: 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)
|
private int CreateProvider(TProviderResource providerResource)
|
||||||
{
|
{
|
||||||
var providerDefinition = GetDefinition(providerResource, false);
|
var providerDefinition = GetDefinition(providerResource, true, false, false);
|
||||||
|
|
||||||
if (providerDefinition.Enable)
|
if (providerDefinition.Enable)
|
||||||
{
|
{
|
||||||
|
@ -84,7 +84,7 @@ namespace Sonarr.Api.V3
|
||||||
|
|
||||||
private void UpdateProvider(TProviderResource providerResource)
|
private void UpdateProvider(TProviderResource providerResource)
|
||||||
{
|
{
|
||||||
var providerDefinition = GetDefinition(providerResource, false);
|
var providerDefinition = GetDefinition(providerResource, true, false, false);
|
||||||
var forceSave = Request.GetBooleanQueryParameter("forceSave");
|
var forceSave = Request.GetBooleanQueryParameter("forceSave");
|
||||||
|
|
||||||
// Only test existing definitions if it is enabled and forceSave isn't set.
|
// Only test existing definitions if it is enabled and forceSave isn't set.
|
||||||
|
@ -96,11 +96,11 @@ namespace Sonarr.Api.V3
|
||||||
_providerFactory.Update(providerDefinition);
|
_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);
|
var definition = _resourceMapper.ToModel(providerResource);
|
||||||
|
|
||||||
if (validate)
|
if (validate && (definition.Enable || forceValidate))
|
||||||
{
|
{
|
||||||
Validate(definition, includeWarnings);
|
Validate(definition, includeWarnings);
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ namespace Sonarr.Api.V3
|
||||||
|
|
||||||
private object Test(TProviderResource providerResource)
|
private object Test(TProviderResource providerResource)
|
||||||
{
|
{
|
||||||
var providerDefinition = GetDefinition(providerResource, true);
|
var providerDefinition = GetDefinition(providerResource, true, true, true);
|
||||||
|
|
||||||
Test(providerDefinition, true);
|
Test(providerDefinition, true);
|
||||||
|
|
||||||
|
@ -155,12 +155,15 @@ namespace Sonarr.Api.V3
|
||||||
|
|
||||||
foreach (var definition in providerDefinitions)
|
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
|
result.Add(new ProviderTestAllResult
|
||||||
{
|
{
|
||||||
Id = definition.Id,
|
Id = definition.Id,
|
||||||
ValidationFailures = validationResult.Errors.ToList()
|
ValidationFailures = validationFailures
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +172,7 @@ namespace Sonarr.Api.V3
|
||||||
|
|
||||||
private object RequestAction(string action, TProviderResource providerResource)
|
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());
|
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;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Validate(TProviderDefinition definition, bool includeWarnings)
|
private void Validate(TProviderDefinition definition, bool includeWarnings)
|
||||||
{
|
{
|
||||||
var validationResult = definition.Settings.Validate();
|
var validationResult = definition.Settings.Validate();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue