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

Fixes #7040

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
Qstick 2022-03-06 17:47:59 -06:00
parent 75b2414e29
commit 356013a84e
3 changed files with 70 additions and 7 deletions

View File

@ -80,7 +80,13 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_return_true_if_current_episode_is_less_than_cutoff()
{
GivenProfile(new Profile { Cutoff = Quality.Bluray1080p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() });
GivenProfile(new Profile
{
Cutoff = Quality.Bluray1080p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
});
GivenFileQuality(new QualityModel(Quality.DVD, new Revision(version: 2)));
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}
@ -88,7 +94,13 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_return_false_if_current_episode_is_equal_to_cutoff()
{
GivenProfile(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() });
GivenProfile(new Profile
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
});
GivenFileQuality(new QualityModel(Quality.HDTV720p, new Revision(version: 2)));
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
}
@ -96,7 +108,13 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_return_false_if_current_episode_is_greater_than_cutoff()
{
GivenProfile(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() });
GivenProfile(new Profile
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
});
GivenFileQuality(new QualityModel(Quality.Bluray1080p, new Revision(version: 2)));
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
}
@ -104,7 +122,13 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_return_true_when_new_episode_is_proper_but_existing_is_not()
{
GivenProfile(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() });
GivenProfile(new Profile
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
});
GivenFileQuality(new QualityModel(Quality.HDTV720p, new Revision(version: 1)));
GivenNewQuality(new QualityModel(Quality.HDTV720p, new Revision(version: 2)));
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
@ -113,7 +137,13 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_return_false_if_cutoff_is_met_and_quality_is_higher()
{
GivenProfile(new Profile { Cutoff = Quality.HDTV720p.Id, Items = Qualities.QualityFixture.GetDefaultQualities() });
GivenProfile(new Profile
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
});
GivenFileQuality(new QualityModel(Quality.HDTV720p, new Revision(version: 2)));
GivenNewQuality(new QualityModel(Quality.Bluray1080p, new Revision(version: 2)));
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
@ -127,7 +157,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
MinFormatScore = 0,
FormatItems = CustomFormatsFixture.GetSampleFormatItems("My Format")
FormatItems = CustomFormatsFixture.GetSampleFormatItems("My Format"),
UpgradeAllowed = true
});
GivenFileQuality(new QualityModel(Quality.HDTV720p));
@ -148,6 +179,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
Cutoff = Quality.HDTV1080p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
});
GivenFileQuality(new QualityModel(Quality.WEBDL1080p, new Revision(version: 1)));
@ -155,5 +187,21 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeTrue();
}
[Test]
public void should_return_false_if_quality_profile_does_not_allow_upgrades_but_cutoff_is_set_to_highest_quality()
{
GivenProfile(new Profile
{
Cutoff = Quality.RAWHD.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = false
});
GivenFileQuality(new QualityModel(Quality.WEBDL1080p));
GivenNewQuality(new QualityModel(Quality.Bluray1080p));
Subject.IsSatisfiedBy(_remoteMovie, null).Accepted.Should().BeFalse();
}
}
}

View File

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

View File

@ -23,6 +23,20 @@ namespace NzbDrone.Core.Profiles
public Language Language { get; set; }
public bool UpgradeAllowed { get; set; }
public Quality FirststAllowedQuality()
{
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);