mirror of
https://github.com/Prowlarr/Prowlarr
synced 2026-04-16 09:50:49 +02:00
New: Improve validation messages
(cherry picked from commit a117001de673e80abd90d54a34a7c86292b3a649)
This commit is contained in:
parent
ade961fad5
commit
0a8e4eb092
8 changed files with 23 additions and 8 deletions
|
|
@ -6,7 +6,7 @@ namespace NzbDrone.Core.Validation
|
|||
{
|
||||
public class FolderValidator : PropertyValidator
|
||||
{
|
||||
protected override string GetDefaultMessageTemplate() => "Invalid Path";
|
||||
protected override string GetDefaultMessageTemplate() => "Invalid Path: '{path}'";
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
|
|
@ -15,6 +15,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||
return false;
|
||||
}
|
||||
|
||||
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||
|
||||
return context.PropertyValue.ToString().IsPathValid(PathValidationType.CurrentOs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public FileExistsValidator(IDiskProvider 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)
|
||||
{
|
||||
|
|
@ -21,6 +21,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||
return false;
|
||||
}
|
||||
|
||||
context.MessageFormatter.AppendArgument("file", context.PropertyValue.ToString());
|
||||
|
||||
return _diskProvider.FileExists(context.PropertyValue.ToString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public FolderWritableValidator(IDiskProvider 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)
|
||||
{
|
||||
|
|
@ -22,6 +22,9 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||
return false;
|
||||
}
|
||||
|
||||
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||
context.MessageFormatter.AppendArgument("user", Environment.UserName);
|
||||
|
||||
return _diskProvider.FolderWritable(context.PropertyValue.ToString());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public PathExistsValidator(IDiskProvider 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)
|
||||
{
|
||||
|
|
@ -21,6 +21,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||
return false;
|
||||
}
|
||||
|
||||
context.MessageFormatter.AppendArgument("path", 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
|
||||
{
|
||||
protected override string GetDefaultMessageTemplate() => "Invalid Path";
|
||||
protected override string GetDefaultMessageTemplate() => "Invalid Path: '{path}'";
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
|
|
@ -24,6 +24,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||
return false;
|
||||
}
|
||||
|
||||
context.MessageFormatter.AppendArgument("path", context.PropertyValue.ToString());
|
||||
|
||||
return context.PropertyValue.ToString().IsPathValid(PathValidationType.CurrentOs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public StartupFolderValidator(IAppFolderInfo 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)
|
||||
{
|
||||
|
|
@ -24,6 +24,7 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||
|
||||
var startupFolder = _appFolderInfo.StartUpFolder;
|
||||
var folder = context.PropertyValue.ToString();
|
||||
context.MessageFormatter.AppendArgument("path", folder);
|
||||
|
||||
if (startupFolder.PathEquals(folder))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ namespace NzbDrone.Core.Validation.Paths
|
|||
{
|
||||
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)
|
||||
{
|
||||
var folder = context.PropertyValue.ToString();
|
||||
context.MessageFormatter.AppendArgument("path", folder);
|
||||
|
||||
foreach (var systemFolder in SystemFolders.GetSystemFolders())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public static IRuleBuilderOptions<T, string> IsValidUrl<T>(this IRuleBuilder<T,
|
|||
|
||||
public class UrlValidator : PropertyValidator
|
||||
{
|
||||
protected override string GetDefaultMessageTemplate() => "Invalid Url";
|
||||
protected override string GetDefaultMessageTemplate() => "Invalid Url: '{url}'";
|
||||
|
||||
protected override bool IsValid(PropertyValidatorContext context)
|
||||
{
|
||||
|
|
@ -23,6 +23,8 @@ protected override bool IsValid(PropertyValidatorContext context)
|
|||
return false;
|
||||
}
|
||||
|
||||
context.MessageFormatter.AppendArgument("url", context.PropertyValue.ToString());
|
||||
|
||||
return context.PropertyValue.ToString().IsValidUrl();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue