mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-25 07:12:40 +00:00
Fixed: Don't allow quality profile to be created without all qualities
(cherry picked from commit 32e1ae2f64827272d351991838200884876e52b4)
This commit is contained in:
parent
0037a56c2b
commit
5d3ff26703
2 changed files with 46 additions and 0 deletions
|
@ -17,6 +17,8 @@ public static IRuleBuilderOptions<T, IList<QualityProfileQualityItemResource>> V
|
||||||
ruleBuilder.SetValidator(new ItemGroupIdValidator<T>());
|
ruleBuilder.SetValidator(new ItemGroupIdValidator<T>());
|
||||||
ruleBuilder.SetValidator(new UniqueIdValidator<T>());
|
ruleBuilder.SetValidator(new UniqueIdValidator<T>());
|
||||||
ruleBuilder.SetValidator(new UniqueQualityIdValidator<T>());
|
ruleBuilder.SetValidator(new UniqueQualityIdValidator<T>());
|
||||||
|
ruleBuilder.SetValidator(new AllQualitiesValidator<T>());
|
||||||
|
|
||||||
return ruleBuilder.SetValidator(new ItemGroupNameValidator<T>());
|
return ruleBuilder.SetValidator(new ItemGroupNameValidator<T>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,4 +153,46 @@ protected override bool IsValid(PropertyValidatorContext context)
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ public QualityProfileController(IQualityProfileService qualityProfileService, IC
|
||||||
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||||||
SharedValidator.RuleFor(c => c.Cutoff).ValidCutoff();
|
SharedValidator.RuleFor(c => c.Cutoff).ValidCutoff();
|
||||||
SharedValidator.RuleFor(c => c.Items).ValidItems();
|
SharedValidator.RuleFor(c => c.Items).ValidItems();
|
||||||
|
|
||||||
SharedValidator.RuleFor(c => c.FormatItems).Must(items =>
|
SharedValidator.RuleFor(c => c.FormatItems).Must(items =>
|
||||||
{
|
{
|
||||||
var all = _formatService.All().Select(f => f.Id).ToList();
|
var all = _formatService.All().Select(f => f.Id).ToList();
|
||||||
|
@ -31,6 +32,7 @@ public QualityProfileController(IQualityProfileService qualityProfileService, IC
|
||||||
|
|
||||||
return all.Except(ids).Empty();
|
return all.Except(ids).Empty();
|
||||||
}).WithMessage("All Custom Formats and no extra ones need to be present inside your Profile! Try refreshing your browser.");
|
}).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) =>
|
SharedValidator.RuleFor(c => c).Custom((profile, context) =>
|
||||||
{
|
{
|
||||||
if (profile.FormatItems.Where(x => x.Score > 0).Sum(x => x.Score) < profile.MinFormatScore &&
|
if (profile.FormatItems.Where(x => x.Score > 0).Sum(x => x.Score) < profile.MinFormatScore &&
|
||||||
|
|
Loading…
Reference in a new issue