mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
New: Improve validation messages
(cherry picked from commit a117001de673e80abd90d54a34a7c86292b3a649)
This commit is contained in:
parent
aa794bddab
commit
933c23ce57
@ -6,7 +6,7 @@ namespace NzbDrone.Core.Validation
|
|||||||
{
|
{
|
||||||
public class FolderValidator : PropertyValidator
|
public class FolderValidator : PropertyValidator
|
||||||
{
|
{
|
||||||
protected override string GetDefaultMessageTemplate() => "Invalid Path";
|
protected override string GetDefaultMessageTemplate() => "Invalid Path: '{path}'";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -15,6 +15,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||||
|
|
||||||
return context.PropertyValue.ToString().IsPathValid(PathValidationType.CurrentOs);
|
return context.PropertyValue.ToString().IsPathValid(PathValidationType.CurrentOs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ public FileExistsValidator(IDiskProvider diskProvider)
|
|||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetDefaultMessageTemplate() => "File does not exist";
|
protected override string GetDefaultMessageTemplate() => "File '{file}' does not exist";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -21,6 +21,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.MessageFormatter.AppendArgument("file", context.PropertyValue.ToString());
|
||||||
|
|
||||||
return _diskProvider.FileExists(context.PropertyValue.ToString());
|
return _diskProvider.FileExists(context.PropertyValue.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public FolderWritableValidator(IDiskProvider diskProvider)
|
|||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetDefaultMessageTemplate() => $"Folder is not writable by user {Environment.UserName}";
|
protected override string GetDefaultMessageTemplate() => "Folder '{path}' is not writable by user '{user}'";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -22,6 +22,9 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||||
|
context.MessageFormatter.AppendArgument("user", Environment.UserName);
|
||||||
|
|
||||||
return _diskProvider.FolderWritable(context.PropertyValue.ToString());
|
return _diskProvider.FolderWritable(context.PropertyValue.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public MovieAncestorValidator(IMovieService movieService)
|
|||||||
_movieService = movieService;
|
_movieService = movieService;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetDefaultMessageTemplate() => "Path is an ancestor of an existing movie";
|
protected override string GetDefaultMessageTemplate() => "Path '{path}' is an ancestor of an existing movie";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -23,6 +23,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||||
|
|
||||||
return !_movieService.AllMoviePaths().Any(s => context.PropertyValue.ToString().IsParentPath(s.Value));
|
return !_movieService.AllMoviePaths().Any(s => context.PropertyValue.ToString().IsParentPath(s.Value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public MoviePathValidator(IMovieService moviesService)
|
|||||||
_moviesService = moviesService;
|
_moviesService = moviesService;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetDefaultMessageTemplate() => "Path is already configured for an existing movie: {moviePath}";
|
protected override string GetDefaultMessageTemplate() => "Path '{path}' is already configured for an existing movie";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -26,7 +26,7 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
dynamic instance = context.ParentContext.InstanceToValidate;
|
dynamic instance = context.ParentContext.InstanceToValidate;
|
||||||
var instanceId = (int)instance.Id;
|
var instanceId = (int)instance.Id;
|
||||||
|
|
||||||
context.MessageFormatter.AppendArgument("moviePath", context.PropertyValue.ToString());
|
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||||
|
|
||||||
return !_moviesService.AllMoviePaths().Any(s => s.Value.PathEquals(context.PropertyValue.ToString()) && s.Key != instanceId);
|
return !_moviesService.AllMoviePaths().Any(s => s.Value.PathEquals(context.PropertyValue.ToString()) && s.Key != instanceId);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ public PathExistsValidator(IDiskProvider diskProvider)
|
|||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetDefaultMessageTemplate() => "Path does not exist";
|
protected override string GetDefaultMessageTemplate() => "Path '{path}' does not exist";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -21,6 +21,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||||
|
|
||||||
return _diskProvider.FolderExists(context.PropertyValue.ToString());
|
return _diskProvider.FolderExists(context.PropertyValue.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public static IRuleBuilderOptions<T, string> IsValidPath<T>(this IRuleBuilder<T,
|
|||||||
|
|
||||||
public class PathValidator : PropertyValidator
|
public class PathValidator : PropertyValidator
|
||||||
{
|
{
|
||||||
protected override string GetDefaultMessageTemplate() => "Invalid Path";
|
protected override string GetDefaultMessageTemplate() => "Invalid Path: '{path}'";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -24,6 +24,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||||
|
|
||||||
return context.PropertyValue.ToString().IsPathValid(PathValidationType.CurrentOs);
|
return context.PropertyValue.ToString().IsPathValid(PathValidationType.CurrentOs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,18 +13,20 @@ public RecycleBinValidator(IConfigService configService)
|
|||||||
_configService = configService;
|
_configService = configService;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetDefaultMessageTemplate() => "Path is {relationship} configured recycle bin folder";
|
protected override string GetDefaultMessageTemplate() => "Path '{path}' is {relationship} configured recycle bin folder";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
var recycleBin = _configService.RecycleBin;
|
var recycleBin = _configService.RecycleBin;
|
||||||
var folder = context.PropertyValue.ToString();
|
|
||||||
|
|
||||||
if (context.PropertyValue == null || recycleBin.IsNullOrWhiteSpace())
|
if (context.PropertyValue == null || recycleBin.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var folder = context.PropertyValue.ToString();
|
||||||
|
context.MessageFormatter.AppendArgument("path", folder);
|
||||||
|
|
||||||
if (recycleBin.PathEquals(folder))
|
if (recycleBin.PathEquals(folder))
|
||||||
{
|
{
|
||||||
context.MessageFormatter.AppendArgument("relationship", "set to");
|
context.MessageFormatter.AppendArgument("relationship", "set to");
|
||||||
|
@ -14,7 +14,7 @@ public RootFolderAncestorValidator(IRootFolderService rootFolderService)
|
|||||||
_rootFolderService = rootFolderService;
|
_rootFolderService = rootFolderService;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetDefaultMessageTemplate() => "Path is an ancestor of an existing root folder";
|
protected override string GetDefaultMessageTemplate() => "Path '{path}' is an ancestor of an existing root folder";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -23,6 +23,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||||
|
|
||||||
return !_rootFolderService.All().Any(s => context.PropertyValue.ToString().IsParentPath(s.Path));
|
return !_rootFolderService.All().Any(s => context.PropertyValue.ToString().IsParentPath(s.Path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public RootFolderValidator(IRootFolderService rootFolderService)
|
|||||||
_rootFolderService = rootFolderService;
|
_rootFolderService = rootFolderService;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetDefaultMessageTemplate() => "Path is already configured as a root folder";
|
protected override string GetDefaultMessageTemplate() => "Path '{path}' is already configured as a root folder";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -22,6 +22,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||||
|
|
||||||
return !_rootFolderService.All().Exists(r => r.Path.PathEquals(context.PropertyValue.ToString()));
|
return !_rootFolderService.All().Exists(r => r.Path.PathEquals(context.PropertyValue.ToString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public StartupFolderValidator(IAppFolderInfo appFolderInfo)
|
|||||||
_appFolderInfo = appFolderInfo;
|
_appFolderInfo = appFolderInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetDefaultMessageTemplate() => "Path cannot be {relationship} the start up folder";
|
protected override string GetDefaultMessageTemplate() => "Path '{path}' cannot be {relationship} the start up folder";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -24,6 +24,7 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
|
|
||||||
var startupFolder = _appFolderInfo.StartUpFolder;
|
var startupFolder = _appFolderInfo.StartUpFolder;
|
||||||
var folder = context.PropertyValue.ToString();
|
var folder = context.PropertyValue.ToString();
|
||||||
|
context.MessageFormatter.AppendArgument("path", folder);
|
||||||
|
|
||||||
if (startupFolder.PathEquals(folder))
|
if (startupFolder.PathEquals(folder))
|
||||||
{
|
{
|
||||||
|
@ -6,11 +6,12 @@ namespace NzbDrone.Core.Validation.Paths
|
|||||||
{
|
{
|
||||||
public class SystemFolderValidator : PropertyValidator
|
public class SystemFolderValidator : PropertyValidator
|
||||||
{
|
{
|
||||||
protected override string GetDefaultMessageTemplate() => "Is {relationship} system folder {systemFolder}";
|
protected override string GetDefaultMessageTemplate() => "Path '{path}' is {relationship} system folder {systemFolder}";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
var folder = context.PropertyValue.ToString();
|
var folder = context.PropertyValue.ToString();
|
||||||
|
context.MessageFormatter.AppendArgument("path", folder);
|
||||||
|
|
||||||
foreach (var systemFolder in SystemFolders.GetSystemFolders())
|
foreach (var systemFolder in SystemFolders.GetSystemFolders())
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ public static IRuleBuilderOptions<T, string> IsValidUrl<T>(this IRuleBuilder<T,
|
|||||||
|
|
||||||
public class UrlValidator : PropertyValidator
|
public class UrlValidator : PropertyValidator
|
||||||
{
|
{
|
||||||
protected override string GetDefaultMessageTemplate() => "Invalid Url";
|
protected override string GetDefaultMessageTemplate() => "Invalid Url: '{url}'";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -23,6 +23,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.MessageFormatter.AppendArgument("url", context.PropertyValue.ToString());
|
||||||
|
|
||||||
return context.PropertyValue.ToString().IsValidUrl();
|
return context.PropertyValue.ToString().IsValidUrl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public MovieFolderAsRootFolderValidator(IBuildFileNames fileNameBuilder)
|
|||||||
_fileNameBuilder = fileNameBuilder;
|
_fileNameBuilder = fileNameBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetDefaultMessageTemplate() => "Root folder path contains movie folder";
|
protected override string GetDefaultMessageTemplate() => "Root folder path '{rootFolderPath}' contains movie folder '{movieFolder}'";
|
||||||
|
|
||||||
protected override bool IsValid(PropertyValidatorContext context)
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
{
|
{
|
||||||
@ -24,9 +24,7 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var movieResource = context.InstanceToValidate as MovieResource;
|
if (context.InstanceToValidate is not MovieResource movieResource)
|
||||||
|
|
||||||
if (movieResource == null)
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -42,6 +40,9 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||||||
var movie = movieResource.ToModel();
|
var movie = movieResource.ToModel();
|
||||||
var movieFolder = _fileNameBuilder.GetMovieFolder(movie);
|
var movieFolder = _fileNameBuilder.GetMovieFolder(movie);
|
||||||
|
|
||||||
|
context.MessageFormatter.AppendArgument("rootFolderPath", rootFolderPath);
|
||||||
|
context.MessageFormatter.AppendArgument("movieFolder", movieFolder);
|
||||||
|
|
||||||
if (movieFolder == rootFolder)
|
if (movieFolder == rootFolder)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user