mirror of
https://github.com/Prowlarr/Prowlarr
synced 2026-05-08 21:14:30 +02:00
New: Add Download Client validation for indexers
This commit is contained in:
parent
768ce14afb
commit
6169fc2fa3
2 changed files with 29 additions and 1 deletions
|
|
@ -0,0 +1,22 @@
|
|||
using FluentValidation.Validators;
|
||||
using NzbDrone.Core.Download;
|
||||
|
||||
namespace NzbDrone.Core.Validation
|
||||
{
|
||||
public class DownloadClientExistsValidator : PropertyValidator
|
||||
{
|
||||
private readonly IDownloadClientFactory _downloadClientFactory;
|
||||
|
||||
public DownloadClientExistsValidator(IDownloadClientFactory downloadClientFactory)
|
||||
{
|
||||
_downloadClientFactory = downloadClientFactory;
|
||||
}
|
||||
|
||||
protected override string GetDefaultMessageTemplate() => "Download Client does not exist";
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
return context?.PropertyValue == null || _downloadClientFactory.Exists((int)context.PropertyValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,12 +7,18 @@ namespace Prowlarr.Api.V1.Indexers
|
|||
[V1ApiController]
|
||||
public class IndexerController : ProviderControllerBase<IndexerResource, IndexerBulkResource, IIndexer, IndexerDefinition>
|
||||
{
|
||||
public IndexerController(IndexerFactory indexerFactory, IndexerResourceMapper resourceMapper, IndexerBulkResourceMapper bulkResourceMapper, AppProfileExistsValidator appProfileExistsValidator)
|
||||
public IndexerController(IndexerFactory indexerFactory,
|
||||
IndexerResourceMapper resourceMapper,
|
||||
IndexerBulkResourceMapper bulkResourceMapper,
|
||||
AppProfileExistsValidator appProfileExistsValidator,
|
||||
DownloadClientExistsValidator downloadClientExistsValidator)
|
||||
: base(indexerFactory, "indexer", resourceMapper, bulkResourceMapper)
|
||||
{
|
||||
Http.Validation.RuleBuilderExtensions.ValidId(SharedValidator.RuleFor(s => s.AppProfileId));
|
||||
Http.Validation.RuleBuilderExtensions.ValidId(SharedValidator.RuleFor(s => s.DownloadClientId));
|
||||
|
||||
SharedValidator.RuleFor(c => c.AppProfileId).SetValidator(appProfileExistsValidator);
|
||||
SharedValidator.RuleFor(c => c.DownloadClientId).SetValidator(downloadClientExistsValidator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue