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

Closes #4898
This commit is contained in:
Mark McDowall 2022-02-16 17:55:14 -08:00
parent b3d90d903a
commit 210768d7d6
4 changed files with 126 additions and 24 deletions

View File

@ -22,12 +22,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new QualityProfile
{
Cutoff = Quality.Bluray1080p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities()
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
},
new LanguageProfile
{
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
Cutoff = Language.English
Cutoff = Language.English,
UpgradeAllowed = true
},
new QualityModel(Quality.DVD, new Revision(version: 2)),
Language.English,
@ -41,12 +43,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new QualityProfile
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities()
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
},
new LanguageProfile
{
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
Cutoff = Language.English
Cutoff = Language.English,
UpgradeAllowed = true
},
new QualityModel(Quality.HDTV720p, new Revision(version: 2)),
Language.English,
@ -60,12 +64,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new QualityProfile
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities()
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
},
new LanguageProfile
{
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
Cutoff = Language.English
Cutoff = Language.English,
UpgradeAllowed = true
},
new QualityModel(Quality.Bluray1080p, new Revision(version: 2)),
Language.English,
@ -79,12 +85,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new QualityProfile
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities()
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
},
new LanguageProfile
{
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
Cutoff = Language.English
Cutoff = Language.English,
UpgradeAllowed = true
},
new QualityModel(Quality.HDTV720p, new Revision(version: 1)),
Language.English,
@ -100,12 +108,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new QualityProfile
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities()
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
},
new LanguageProfile
{
Languages = LanguageFixture.GetDefaultLanguages(Language.English),
Cutoff = Language.English
Cutoff = Language.English,
UpgradeAllowed = true
},
new QualityModel(Quality.HDTV720p, new Revision(version: 2)),
Language.English,
@ -121,13 +131,15 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
};
LanguageProfile _langProfile = new LanguageProfile
{
Cutoff = Language.Spanish,
Languages = LanguageFixture.GetDefaultLanguages()
};
Languages = LanguageFixture.GetDefaultLanguages(),
UpgradeAllowed = true
};
Subject.CutoffNotMet(_profile,
_langProfile,
@ -145,12 +157,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
};
LanguageProfile _langProfile = new LanguageProfile
{
Cutoff = Language.Spanish,
Languages = LanguageFixture.GetDefaultLanguages()
Languages = LanguageFixture.GetDefaultLanguages(),
UpgradeAllowed = true
};
Subject.CutoffNotMet(
@ -170,12 +184,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
};
LanguageProfile _langProfile = new LanguageProfile
{
Cutoff = Language.Spanish,
Languages = LanguageFixture.GetDefaultLanguages()
Languages = LanguageFixture.GetDefaultLanguages(),
UpgradeAllowed = true
};
Subject.CutoffNotMet(
@ -195,12 +211,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
};
LanguageProfile _langProfile = new LanguageProfile
{
Cutoff = Language.Spanish,
Languages = LanguageFixture.GetDefaultLanguages()
Languages = LanguageFixture.GetDefaultLanguages(),
UpgradeAllowed = true
};
Subject.CutoffNotMet(
@ -220,12 +238,14 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
};
LanguageProfile _langProfile = new LanguageProfile
{
Cutoff = Language.Spanish,
Languages = LanguageFixture.GetDefaultLanguages()
Languages = LanguageFixture.GetDefaultLanguages(),
UpgradeAllowed = true
};
Subject.CutoffNotMet(
@ -243,13 +263,15 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
Cutoff = Quality.HDTV720p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
};
UpgradeAllowed = true
};
LanguageProfile _langProfile = new LanguageProfile
{
Cutoff = Language.Spanish,
Languages = LanguageFixture.GetDefaultLanguages()
};
Languages = LanguageFixture.GetDefaultLanguages(),
UpgradeAllowed = true
};
Subject.CutoffNotMet(
_profile,
@ -268,13 +290,15 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
{
Cutoff = Quality.HDTV1080p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
};
UpgradeAllowed = true
};
LanguageProfile _langProfile = new LanguageProfile
{
Cutoff = Language.English,
Languages = LanguageFixture.GetDefaultLanguages()
};
Languages = LanguageFixture.GetDefaultLanguages(),
UpgradeAllowed = true
};
Subject.CutoffNotMet(
_profile,
@ -285,5 +309,59 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
new QualityModel(Quality.WEBDL1080p, new Revision(version: 2)),
NoPreferredWordScore).Should().BeTrue();
}
[Test]
public void should_return_false_if_language_profile_does_not_allow_upgrades_but_cutoff_is_set_to_highest_language_and_quality_cutoff_is_met()
{
QualityProfile _profile = new QualityProfile
{
Cutoff = Quality.WEBDL1080p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = true
};
LanguageProfile _langProfile = new LanguageProfile
{
Cutoff = Language.Arabic,
Languages = LanguageFixture.GetDefaultLanguages(Language.Spanish, Language.English, Language.Arabic),
UpgradeAllowed = false
};
Subject.CutoffNotMet(
_profile,
_langProfile,
new QualityModel(Quality.WEBDL1080p),
Language.English,
NoPreferredWordScore,
new QualityModel(Quality.Bluray1080p),
NoPreferredWordScore).Should().BeFalse();
}
[Test]
public void should_return_false_if_quality_profile_does_not_allow_upgrades_but_cutoff_is_set_to_highest_quality_and_language_cutoff_is_met()
{
QualityProfile _profile = new QualityProfile
{
Cutoff = Quality.WEBDL1080p.Id,
Items = Qualities.QualityFixture.GetDefaultQualities(),
UpgradeAllowed = false
};
LanguageProfile _langProfile = new LanguageProfile
{
Cutoff = Language.English,
Languages = LanguageFixture.GetDefaultLanguages(Language.Spanish, Language.English, Language.Arabic),
UpgradeAllowed = true
};
Subject.CutoffNotMet(
_profile,
_langProfile,
new QualityModel(Quality.WEBDL1080p),
Language.English,
NoPreferredWordScore,
new QualityModel(Quality.Bluray1080p),
NoPreferredWordScore).Should().BeFalse();
}
}
}

View File

@ -98,7 +98,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.FirststAllowedQuality().Id;
var cutoffCompare = new QualityModelComparer(profile).Compare(currentQuality.Quality.Id, cutoff);
if (cutoffCompare < 0)
{
@ -115,7 +116,11 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public bool LanguageCutoffNotMet(LanguageProfile languageProfile, Language currentLanguage)
{
var languageCompare = new LanguageComparer(languageProfile).Compare(currentLanguage, languageProfile.Cutoff);
var cutoff = languageProfile.UpgradeAllowed
? languageProfile.Cutoff
: languageProfile.FirstAllowedLanguage();
var languageCompare = new LanguageComparer(languageProfile).Compare(currentLanguage, cutoff);
return languageCompare < 0;
}

View File

@ -12,6 +12,11 @@ namespace NzbDrone.Core.Profiles.Languages
public bool UpgradeAllowed { get; set; }
public Language Cutoff { get; set; }
public Language FirstAllowedLanguage()
{
return Languages.First(q => q.Allowed).Language;
}
public Language LastAllowedLanguage()
{
return Languages.Last(q => q.Allowed).Language;

View File

@ -12,6 +12,20 @@ namespace NzbDrone.Core.Profiles.Qualities
public int Cutoff { get; set; }
public List<QualityProfileQualityItem> Items { 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);