1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2026-04-24 22:36:19 -04:00

Fixed: Prevent setting series folder to drone factory, root folder or another series' folder

This commit is contained in:
Mark McDowall
2014-04-04 08:18:07 -07:00
parent ff865f56d0
commit 0951e0c74b
5 changed files with 76 additions and 3 deletions
@@ -0,0 +1,30 @@
using FluentValidation.Validators;
using NzbDrone.Common;
using NzbDrone.Core.Tv;
using Omu.ValueInjecter;
namespace NzbDrone.Core.Validation.Paths
{
public class SeriesPathValidator : PropertyValidator
{
private readonly ISeriesService _seriesService;
public SeriesPathValidator(ISeriesService seriesService)
: base("Path is already configured for another series")
{
_seriesService = seriesService;
}
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null) return true;
var series = new Series();
series.InjectFrom(context.ParentContext.InstanceToValidate);
if (series.Id == 0) return true;
return (!_seriesService.GetAllSeries().Exists(s => s.Path.PathEquals(context.PropertyValue.ToString()) && s.Id != series.Id));
}
}
}