Fixed: Profiles with upgrades disabled incorrectly allowing upgrades in some cases

Closes #2649
pull/3313/head
Mark McDowall 3 years ago committed by Qstick
parent aa5869c498
commit 0592f35aee

@ -19,7 +19,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new QualityProfile
{
Cutoff = Quality.MP3_256.Id,
Items = Qualities.QualityFixture.GetDefaultQualities()
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
},
new List<QualityModel> { new QualityModel(Quality.MP3_192, new Revision(version: 2)) },
new List<CustomFormat>()).Should().BeTrue();
@ -32,7 +33,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new QualityProfile
{
Cutoff = Quality.MP3_256.Id,
Items = Qualities.QualityFixture.GetDefaultQualities()
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
},
new List<QualityModel> { new QualityModel(Quality.MP3_256, new Revision(version: 2)) },
new List<CustomFormat>()).Should().BeFalse();
@ -45,7 +47,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new QualityProfile
{
Cutoff = Quality.MP3_256.Id,
Items = Qualities.QualityFixture.GetDefaultQualities()
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
},
new List<QualityModel> { new QualityModel(Quality.MP3_320, new Revision(version: 2)) },
new List<CustomFormat>()).Should().BeFalse();
@ -58,7 +61,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new QualityProfile
{
Cutoff = Quality.MP3_320.Id,
Items = Qualities.QualityFixture.GetDefaultQualities()
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
},
new List<QualityModel> { new QualityModel(Quality.MP3_320, new Revision(version: 1)) },
new List<CustomFormat>(),
@ -72,7 +76,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new QualityProfile
{
Cutoff = Quality.MP3_320.Id,
Items = Qualities.QualityFixture.GetDefaultQualities()
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
},
new List<QualityModel> { new QualityModel(Quality.MP3_320, new Revision(version: 2)) },
new List<CustomFormat>(),
@ -86,6 +91,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
Cutoff = Quality.MP3_320.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
};
Subject.CutoffNotMet(

@ -99,7 +99,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public bool QualityCutoffNotMet(QualityProfile profile, QualityModel currentQuality, QualityModel newQuality = null)
{
var cutoffCompare = new QualityModelComparer(profile).Compare(currentQuality.Quality.Id, profile.Cutoff);
var cutoff = profile.UpgradeAllowed ? profile.Cutoff : profile.FirstAllowedQuality().Id;
var cutoffCompare = new QualityModelComparer(profile).Compare(currentQuality.Quality.Id, cutoff);
if (cutoffCompare < 0)
{

@ -21,6 +21,20 @@ namespace NzbDrone.Core.Profiles.Qualities
public List<ProfileFormatItem> FormatItems { get; set; }
public List<QualityProfileQualityItem> Items { get; set; }
public Quality FirstAllowedQuality()
{
var firstAllowed = Items.First(q => q.Allowed);
if (firstAllowed.Quality != null)
{
return firstAllowed.Quality;
}
// Returning any item from the group will work,
// returning the first because it's the true first quality.
return firstAllowed.Items.First().Quality;
}
public Quality LastAllowedQuality()
{
var lastAllowed = Items.Last(q => q.Allowed);

Loading…
Cancel
Save