Validation, settings UI cleanup and different settings models, oh my

New: Download client UI matches other settings
Fixed: Prevent drone factory folder from being set to invalid paths/root path for series
Fixed: Switching pages in settings will not hide changes
Fixed: Test download clients
Fixed: Settings are validated before saving
This commit is contained in:
Mark McDowall
2014-02-16 01:56:12 -08:00
parent 606d78f5e1
commit 77b83b521e
57 changed files with 667 additions and 484 deletions
@@ -0,0 +1,19 @@
using FluentValidation.Validators;
using NzbDrone.Common;
namespace NzbDrone.Core.Validation
{
public class FolderValidator : PropertyValidator
{
public FolderValidator()
: base("Invalid Path")
{
}
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return false;
return context.PropertyValue.ToString().IsPathValid();
}
}
}
@@ -0,0 +1,29 @@
using System;
using FluentValidation.Validators;
using NzbDrone.Common;
using NzbDrone.Core.Configuration;
namespace NzbDrone.Core.Validation.Paths
{
public class DroneFactoryValidator : PropertyValidator
{
private readonly IConfigService _configService;
public DroneFactoryValidator(IConfigService configService)
: base("Path is already used for drone factory")
{
_configService = configService;
}
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return false;
var droneFactory = _configService.DownloadedEpisodesFolder;
if (String.IsNullOrWhiteSpace(droneFactory)) return true;
return !droneFactory.PathEquals(context.PropertyValue.ToString());
}
}
}
@@ -0,0 +1,23 @@
using FluentValidation.Validators;
using NzbDrone.Common.Disk;
namespace NzbDrone.Core.Validation.Paths
{
public class PathExistsValidator : PropertyValidator
{
private readonly IDiskProvider _diskProvider;
public PathExistsValidator(IDiskProvider diskProvider)
: base("Path does not exist")
{
_diskProvider = diskProvider;
}
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return false;
return (_diskProvider.FolderExists(context.PropertyValue.ToString()));
}
}
}
@@ -0,0 +1,28 @@
using FluentValidation;
using FluentValidation.Validators;
using NzbDrone.Common;
namespace NzbDrone.Core.Validation.Paths
{
public static class PathValidation
{
public static IRuleBuilderOptions<T, string> IsValidPath<T>(this IRuleBuilder<T, string> ruleBuilder)
{
return ruleBuilder.SetValidator(new PathValidator());
}
}
public class PathValidator : PropertyValidator
{
public PathValidator()
: base("Invalid Path")
{
}
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return false;
return context.PropertyValue.ToString().IsPathValid();
}
}
}
@@ -0,0 +1,24 @@
using FluentValidation.Validators;
using NzbDrone.Common;
using NzbDrone.Core.RootFolders;
namespace NzbDrone.Core.Validation.Paths
{
public class RootFolderValidator : PropertyValidator
{
private readonly IRootFolderService _rootFolderService;
public RootFolderValidator(IRootFolderService rootFolderService)
: base("Path is already configured as a root folder")
{
_rootFolderService = rootFolderService;
}
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return true;
return (!_rootFolderService.All().Exists(r => r.Path.PathEquals(context.PropertyValue.ToString())));
}
}
}