mirror of
https://github.com/Radarr/Radarr.git
synced 2025-04-24 06:27:08 -04:00
New: Root folder exists validation for import lists
Also moved the AppendArgument to avoid cases like `Invalid Path: '{path}'`.
This commit is contained in:
parent
cd401f72f5
commit
bb44fbc362
4 changed files with 38 additions and 13 deletions
|
@ -19,14 +19,9 @@ namespace NzbDrone.Core.Validation.Paths
|
|||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
if (context.PropertyValue == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
context.MessageFormatter.AppendArgument("path", context.PropertyValue?.ToString());
|
||||
|
||||
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||
|
||||
return context.PropertyValue.ToString().IsPathValid(PathValidationType.CurrentOs);
|
||||
return context.PropertyValue != null && context.PropertyValue.ToString().IsPathValid(PathValidationType.CurrentOs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
using FluentValidation.Validators;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
|
||||
namespace NzbDrone.Core.Validation.Paths
|
||||
{
|
||||
public class RootFolderExistsValidator : PropertyValidator
|
||||
{
|
||||
private readonly IRootFolderService _rootFolderService;
|
||||
|
||||
public RootFolderExistsValidator(IRootFolderService rootFolderService)
|
||||
{
|
||||
_rootFolderService = rootFolderService;
|
||||
}
|
||||
|
||||
protected override string GetDefaultMessageTemplate() => "Root folder '{path}' does not exist";
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
context.MessageFormatter.AppendArgument("path", context.PropertyValue?.ToString());
|
||||
|
||||
return context.PropertyValue == null || _rootFolderService.All().Exists(r => r.Path.PathEquals(context.PropertyValue.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,13 +17,13 @@ namespace NzbDrone.Core.Validation.Paths
|
|||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
context.MessageFormatter.AppendArgument("path", context.PropertyValue?.ToString());
|
||||
|
||||
if (context.PropertyValue == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||
|
||||
return !_rootFolderService.All().Exists(r => r.Path.PathEquals(context.PropertyValue.ToString()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,13 +12,18 @@ namespace Radarr.Api.V3.ImportLists
|
|||
public static readonly ImportListResourceMapper ResourceMapper = new ();
|
||||
public static readonly ImportListBulkResourceMapper BulkResourceMapper = new ();
|
||||
|
||||
public ImportListController(IImportListFactory importListFactory, QualityProfileExistsValidator qualityProfileExistsValidator)
|
||||
public ImportListController(IImportListFactory importListFactory, RootFolderExistsValidator rootFolderExistsValidator, QualityProfileExistsValidator qualityProfileExistsValidator)
|
||||
: base(importListFactory, "importlist", ResourceMapper, BulkResourceMapper)
|
||||
{
|
||||
SharedValidator.RuleFor(c => c.RootFolderPath).IsValidPath();
|
||||
SharedValidator.RuleFor(c => c.MinimumAvailability).NotNull();
|
||||
SharedValidator.RuleFor(c => c.QualityProfileId).ValidId();
|
||||
SharedValidator.RuleFor(c => c.QualityProfileId).SetValidator(qualityProfileExistsValidator);
|
||||
|
||||
SharedValidator.RuleFor(c => c.RootFolderPath).Cascade(CascadeMode.Stop)
|
||||
.IsValidPath()
|
||||
.SetValidator(rootFolderExistsValidator);
|
||||
|
||||
SharedValidator.RuleFor(c => c.QualityProfileId).Cascade(CascadeMode.Stop)
|
||||
.ValidId()
|
||||
.SetValidator(qualityProfileExistsValidator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue