Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: Add Validations for Recycle Bin Folder
- Loading branch information
Showing
6 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/NzbDrone.Core/Validation/Paths/RootFolderAncestorValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters