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`.
pull/201/head
Robert Dailey 10 months ago
parent 6bb7980827
commit ade5ee72b2

@ -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

@ -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; }

@ -57,14 +57,7 @@ public class UpdatedQualityProfileTest
MinFormatScore = 100,
CutoffFormatScore = 200,
UpgradeAllowed = false,
Cutoff = 1,
Items = new List<ProfileItemDto>
{
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<ProfileItemDto>
{
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
};

Loading…
Cancel
Save