Fixed: Don't allow quality profile to be created without all qualities

(cherry picked from commit 32e1ae2f64827272d351991838200884876e52b4)
pull/9179/head
Mark McDowall 1 year ago committed by Bogdan
parent 27da524391
commit 2a2667a2ec

@ -17,6 +17,8 @@ namespace Radarr.Api.V3.Profiles.Quality
ruleBuilder.SetValidator(new ItemGroupIdValidator<T>());
ruleBuilder.SetValidator(new UniqueIdValidator<T>());
ruleBuilder.SetValidator(new UniqueQualityIdValidator<T>());
ruleBuilder.SetValidator(new AllQualitiesValidator<T>());
return ruleBuilder.SetValidator(new ItemGroupNameValidator<T>());
}
}
@ -151,4 +153,46 @@ namespace Radarr.Api.V3.Profiles.Quality
return true;
}
}
public class AllQualitiesValidator<T> : PropertyValidator
{
protected override string GetDefaultMessageTemplate() => "Must contain all qualities";
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue is not IList<QualityProfileQualityItemResource> items)
{
return false;
}
var qualityIds = new HashSet<int>();
foreach (var item in items)
{
if (item.Id > 0)
{
foreach (var quality in item.Items)
{
qualityIds.Add(quality.Quality.Id);
}
}
else
{
qualityIds.Add(item.Quality.Id);
}
}
var allQualityIds = NzbDrone.Core.Qualities.Quality.All;
foreach (var quality in allQualityIds)
{
if (!qualityIds.Contains(quality.Id))
{
return false;
}
}
return true;
}
}
}

@ -27,6 +27,7 @@ namespace Radarr.Api.V3.Profiles.Quality
// TODO: Need to validate the Items to ensure groups have names and at no item has no name, no items and no quality
SharedValidator.RuleFor(c => c.Cutoff).ValidCutoff();
SharedValidator.RuleFor(c => c.Items).ValidItems();
SharedValidator.RuleFor(c => c.FormatItems).Must(items =>
{
var all = _formatService.All().Select(f => f.Id).ToList();
@ -34,6 +35,7 @@ namespace Radarr.Api.V3.Profiles.Quality
return all.Except(ids).Empty();
}).WithMessage("All Custom Formats and no extra ones need to be present inside your Profile! Try refreshing your browser.");
SharedValidator.RuleFor(c => c).Custom((profile, context) =>
{
if (profile.FormatItems.Where(x => x.Score > 0).Sum(x => x.Score) < profile.MinFormatScore &&

Loading…
Cancel
Save