mirror of
https://github.com/Radarr/Radarr.git
synced 2025-04-24 06:27:08 -04:00
Fixed: Don't allow quality profile to be created without all qualities
(cherry picked from commit 32e1ae2f64827272d351991838200884876e52b4)
This commit is contained in:
parent
27da524391
commit
2a2667a2ec
2 changed files with 46 additions and 0 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue