mirror of
https://github.com/lidarr/Lidarr
synced 2025-01-03 05:25:10 +00:00
Skip duplicate import list exclusions
(cherry picked from commit 9af2f137f41867a29d544fad77551672a79f24b6) Closes #5003
This commit is contained in:
parent
809db4022e
commit
04e0d3f22e
3 changed files with 14 additions and 4 deletions
|
@ -20,7 +20,11 @@ public ImportListExclusionController(IImportListExclusionService importListExclu
|
||||||
{
|
{
|
||||||
_importListExclusionService = importListExclusionService;
|
_importListExclusionService = importListExclusionService;
|
||||||
|
|
||||||
SharedValidator.RuleFor(c => c.ForeignId).NotEmpty().SetValidator(guidValidator).SetValidator(importListExclusionExistsValidator);
|
SharedValidator.RuleFor(c => c.ForeignId).Cascade(CascadeMode.Stop)
|
||||||
|
.NotEmpty()
|
||||||
|
.SetValidator(guidValidator)
|
||||||
|
.SetValidator(importListExclusionExistsValidator);
|
||||||
|
|
||||||
SharedValidator.RuleFor(c => c.ArtistName).NotEmpty();
|
SharedValidator.RuleFor(c => c.ArtistName).NotEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using FluentValidation.Validators;
|
using FluentValidation.Validators;
|
||||||
|
using NzbDrone.Core.ImportLists.Exclusions;
|
||||||
|
|
||||||
namespace NzbDrone.Core.ImportLists.Exclusions
|
namespace Lidarr.Api.V1.ImportLists
|
||||||
{
|
{
|
||||||
public class ImportListExclusionExistsValidator : PropertyValidator
|
public class ImportListExclusionExistsValidator : PropertyValidator
|
||||||
{
|
{
|
||||||
|
@ -20,7 +21,12 @@ protected override bool IsValid(PropertyValidatorContext context)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !_importListExclusionService.All().Exists(s => s.ForeignId == context.PropertyValue.ToString());
|
if (context.InstanceToValidate is not ImportListExclusionResource listExclusionResource)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !_importListExclusionService.All().Exists(v => v.ForeignId == context.PropertyValue.ToString() && v.Id != listExclusionResource.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@ protected override bool IsValid(PropertyValidatorContext context)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Guid.TryParse(context.PropertyValue.ToString(), out var guidOutput);
|
return Guid.TryParse(context.PropertyValue.ToString(), out _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue