Skip duplicate import list exclusions

(cherry picked from commit 9af2f137f41867a29d544fad77551672a79f24b6)

Closes #5003
pull/5018/head
Bogdan 3 months ago
parent 809db4022e
commit 04e0d3f22e

@ -20,7 +20,11 @@ namespace Lidarr.Api.V1.ImportLists
{
_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();
}

@ -1,6 +1,7 @@
using FluentValidation.Validators;
using NzbDrone.Core.ImportLists.Exclusions;
namespace NzbDrone.Core.ImportLists.Exclusions
namespace Lidarr.Api.V1.ImportLists
{
public class ImportListExclusionExistsValidator : PropertyValidator
{
@ -20,7 +21,12 @@ namespace NzbDrone.Core.ImportLists.Exclusions
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 @@ namespace NzbDrone.Core.Validation
return false;
}
return Guid.TryParse(context.PropertyValue.ToString(), out var guidOutput);
return Guid.TryParse(context.PropertyValue.ToString(), out _);
}
}
}

Loading…
Cancel
Save