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:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user