From ade5ee72b29aefdcffa01beeb7986e30f1382e33 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Wed, 2 Aug 2023 11:32:51 -0500 Subject: [PATCH] fix: Cutoff set properly when disabling upgrades The `qualityprofile` API still performs validation on `cutoff` even when `upgradeAllowed` is set to `false`. Because of this, we must still set `cutoff` even if the user didn't specify `upgrade_allowed` and `until_quality` in their configs. We do so by finding the first item in the Items list, regardless of what that is. This fixes the HTTP 400 we get when invoking the API with a `null` value for `cutoff`. --- .../QualityProfile/UpdatedQualityProfile.cs | 10 ++++- .../Config/Services/ServiceConfiguration.cs | 2 +- .../UpdatedQualityProfileTest.cs | 37 ++++++++++--------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/Recyclarr.Cli/Pipelines/QualityProfile/UpdatedQualityProfile.cs b/src/Recyclarr.Cli/Pipelines/QualityProfile/UpdatedQualityProfile.cs index 5fd2955b..c54f5f1a 100644 --- a/src/Recyclarr.Cli/Pipelines/QualityProfile/UpdatedQualityProfile.cs +++ b/src/Recyclarr.Cli/Pipelines/QualityProfile/UpdatedQualityProfile.cs @@ -35,12 +35,18 @@ public record UpdatedQualityProfile { var config = ProfileConfig.Profile; + // The `qualityprofile` API will still validate `cutoff` even when `upgradeAllowed` is set to `false`. + // Because of this, we cannot set cutoff to null. We pick the first available if the user didn't specify one. + var cutoff = config.UpgradeAllowed is true + ? UpdatedQualities.Items.FindCutoff(config.UpgradeUntilQuality) + : UpdatedQualities.Items.First().Id; + return ProfileDto with { - Name = config.Name, + Name = config.Name, // Must keep this for NEW profile syncing. It will only assign if src is not null. UpgradeAllowed = config.UpgradeAllowed, MinFormatScore = config.MinFormatScore, - Cutoff = ProfileDto.Items.FindCutoff(config.UpgradeUntilQuality), + Cutoff = cutoff, CutoffFormatScore = config.UpgradeUntilScore, FormatItems = UpdatedScores.Select(x => x.Dto with {Score = x.NewScore}).ToList(), Items = UpdatedQualities.Items diff --git a/src/Recyclarr.TrashLib/Config/Services/ServiceConfiguration.cs b/src/Recyclarr.TrashLib/Config/Services/ServiceConfiguration.cs index e850dc48..d5a03c7f 100644 --- a/src/Recyclarr.TrashLib/Config/Services/ServiceConfiguration.cs +++ b/src/Recyclarr.TrashLib/Config/Services/ServiceConfiguration.cs @@ -62,7 +62,7 @@ public enum QualitySortAlgorithm public record QualityProfileConfig { public string Name { get; init; } = ""; - public bool? UpgradeAllowed => UpgradeUntilQuality is not null; + public bool UpgradeAllowed => UpgradeUntilQuality is not null; public string? UpgradeUntilQuality { get; init; } public int? UpgradeUntilScore { get; init; } public int? MinFormatScore { get; init; } diff --git a/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileTest.cs b/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileTest.cs index f9a26a68..4ca57352 100644 --- a/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileTest.cs +++ b/src/tests/Recyclarr.Cli.Tests/Pipelines/QualityProfile/UpdatedQualityProfileTest.cs @@ -57,14 +57,7 @@ public class UpdatedQualityProfileTest MinFormatScore = 100, CutoffFormatScore = 200, UpgradeAllowed = false, - Cutoff = 1, - Items = new List - { - NewQp.QualityDto(1, "Quality Item 1", true), - NewQp.QualityDto(2, "Quality Item 2", true), - NewQp.GroupDto(3, "Quality Item 3", true, - NewQp.QualityDto(4, "Quality Item 4", true)) - } + Cutoff = 1 }, ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig { @@ -73,6 +66,16 @@ public class UpdatedQualityProfileTest UpgradeUntilScore = 220, UpgradeUntilQuality = "Quality Item 3" }), + UpdatedQualities = new UpdatedQualities + { + Items = new List + { + NewQp.QualityDto(1, "Quality Item 1", true), + NewQp.QualityDto(2, "Quality Item 2", true), + NewQp.GroupDto(3, "Quality Item 3", true, + NewQp.QualityDto(4, "Quality Item 4", true)) + } + }, UpdateReason = QualityProfileUpdateReason.New }; @@ -89,10 +92,7 @@ public class UpdatedQualityProfileTest CutoffFormatScore = 220, UpgradeAllowed = true, Cutoff = 3, - - // Since we didn't process quality items, the assignment in BuildUpdatedDto() will not change the Items - // collection. - Items = profile.ProfileDto.Items + Items = profile.UpdatedQualities.Items }); } @@ -101,14 +101,15 @@ public class UpdatedQualityProfileTest { var profile = new UpdatedQualityProfile { - ProfileDto = new QualityProfileDto + ProfileDto = new QualityProfileDto {Name = ""}, + ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig {Name = "config_name"}), + UpdatedQualities = new UpdatedQualities { - Name = "" + Items = new[] + { + new ProfileItemDto() + } }, - ProfileConfig = new ProcessedQualityProfileData(new QualityProfileConfig - { - Name = "config_name" - }), UpdateReason = QualityProfileUpdateReason.New };