Fixes 1794 (cherry picked from commit fd4fb88ce1efa8f673c74f04cd632a3f607565c4)pull/2561/head
parent
b88adfd171
commit
3e26424797
@ -0,0 +1,44 @@
|
||||
using FluentValidation.Validators;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Core.Validation.Paths
|
||||
{
|
||||
public class RecycleBinValidator : PropertyValidator
|
||||
{
|
||||
private readonly IConfigService _configService;
|
||||
|
||||
public RecycleBinValidator(IConfigService configService)
|
||||
: base("Path is {relationship} configured recycle bin folder")
|
||||
{
|
||||
_configService = configService;
|
||||
}
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
var recycleBin = _configService.RecycleBin;
|
||||
var folder = context.PropertyValue.ToString();
|
||||
|
||||
if (context.PropertyValue == null || recycleBin.IsNullOrWhiteSpace())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (recycleBin.PathEquals(folder))
|
||||
{
|
||||
context.MessageFormatter.AppendArgument("relationship", "set to");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (recycleBin.IsParentPath(folder))
|
||||
{
|
||||
context.MessageFormatter.AppendArgument("relationship", "child of");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using System.Linq;
|
||||
using FluentValidation.Validators;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
|
||||
namespace NzbDrone.Core.Validation.Paths
|
||||
{
|
||||
public class RootFolderAncestorValidator : PropertyValidator
|
||||
{
|
||||
private readonly IRootFolderService _rootFolderService;
|
||||
|
||||
public RootFolderAncestorValidator(IRootFolderService rootFolderService)
|
||||
: base("Path is an ancestor of an existing root folder")
|
||||
{
|
||||
_rootFolderService = rootFolderService;
|
||||
}
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
if (context.PropertyValue == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return !_rootFolderService.All().Any(s => context.PropertyValue.ToString().IsParentPath(s.Path));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue