Skip to content

Commit 3c7e24f

Browse files
Add support for package deprecation reason 'unusable' (#7106)
* Add support for package deprecation reason 'unusable' * Fix deprecation reason precedence and wording * Another wording fix * Change 'Any version' to 'Latest' in alternate package version selector * rename string variable * change verbage * Toggle visibility of alternate package section along with custom message
1 parent 7432dd1 commit 3c7e24f

14 files changed

Lines changed: 143 additions & 79 deletions

File tree

src/Bootstrap/dist/css/bootstrap-theme.css

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
.page-manage-deprecation {
2-
.full-line {
3-
display: block;
4-
width: 100%;
2+
.full-line {
3+
display: block;
4+
width: 100%;
5+
}
6+
7+
.deprecation-section {
8+
margin-top: 40px;
9+
10+
.deprecation-section-header {
11+
margin-bottom: 15px;
512
}
613

7-
.deprecation-section {
8-
margin-top: 40px;
14+
.unbolded-label {
15+
label {
16+
font-weight: normal;
17+
}
18+
}
919

10-
.deprecation-section-header {
11-
margin-bottom: 15px;
12-
}
13-
14-
.unbolded-label {
15-
label {
16-
font-weight: normal;
17-
}
18-
}
19-
20-
.deprecation-subsection {
21-
margin: 25px;
22-
23-
.alternate-package-container {
24-
@media (max-width: @screen-sm-min) {
25-
margin-top: 40px;
26-
}
27-
}
28-
}
20+
.alternate-package-container {
21+
@media (max-width: @screen-sm-min) {
22+
margin-top: 40px;
23+
}
2924
}
25+
}
3026
}

src/NuGet.Services.Entities/PackageDeprecationStatus.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ public enum PackageDeprecationStatus
2626
/// </summary>
2727
Legacy = 2,
2828

29-
// Note: the below is commented out for future reference so we keep track of the original enum value for PackageDeprecationStatus.Vulnerable = 4
3029
/// <summary>
31-
/// The package is deprecated because it is vulnerable.
30+
/// The package is deprecated because it has critical bugs.
3231
/// </summary>
33-
// Vulnerable = 4
32+
CriticalBugs = 4
3433
}
3534
}

src/NuGetGallery/Controllers/ManageDeprecationJsonApiController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public virtual async Task<JsonResult> Deprecate(
5252
string id,
5353
IEnumerable<string> versions,
5454
bool isLegacy,
55+
bool hasCriticalBugs,
5556
bool isOther,
5657
string alternatePackageId,
5758
string alternatePackageVersion,
@@ -141,6 +142,11 @@ public virtual async Task<JsonResult> Deprecate(
141142
status |= PackageDeprecationStatus.Legacy;
142143
}
143144

145+
if (hasCriticalBugs)
146+
{
147+
status |= PackageDeprecationStatus.CriticalBugs;
148+
}
149+
144150
if (isOther)
145151
{
146152
status |= PackageDeprecationStatus.Other;

src/NuGetGallery/Helpers/PackageHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ public static string GetSelectListText(Package package)
191191
deprecationReasons.Add("Legacy");
192192
}
193193

194+
if (deprecation.Status.HasFlag(PackageDeprecationStatus.CriticalBugs))
195+
{
196+
deprecationReasons.Add("Critical Bugs");
197+
}
198+
194199
if (deprecation.Status.HasFlag(PackageDeprecationStatus.Other))
195200
{
196201
deprecationReasons.Add("Other");

src/NuGetGallery/Scripts/gallery/page-manage-deprecation.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
1111
versionData.Text,
1212
version,
1313
version === defaultVersion,
14-
versionData.IsLegacy || versionData.IsOther);
14+
versionData.IsLegacy || versionData.HasCriticalBugs || versionData.IsOther);
1515
});
1616

1717
this.dropdown = new MultiSelectDropdown(items, "version", "versions");
1818
this.chosenItemsConflictWarning = ko.pureComputed(function () {
1919
var chosenItems = self.dropdown.chosenItems();
2020
var isLegacy = self.isLegacy();
21+
var hasCriticalBugs = self.hasCriticalBugs();
2122
var isOther = self.isOther();
2223
var warningMessage = null;
2324
var areMultipleVersionsSelected = chosenItems.length > 1;
@@ -38,13 +39,13 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
3839
continue;
3940
}
4041

41-
if (versionData.IsLegacy || versionData.IsOther) {
42+
if (versionData.IsLegacy || versionData.HasCriticalBugs || versionData.IsOther) {
4243
hasVersionsWithExistingDeprecationState = true;
4344
break;
4445
}
4546
}
4647

47-
if (isLegacy || isOther) {
48+
if (isLegacy || hasCriticalBugs || isOther) {
4849
if (areMultipleVersionsSelected && hasVersionsWithExistingDeprecationState) {
4950
// Show a warning if multiple versions are selected and at least one has an existing deprecation
5051
// The user should be aware they are replacing existing deprecations
@@ -63,6 +64,7 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
6364
}, this);
6465

6566
this.isLegacy = ko.observable(false);
67+
this.hasCriticalBugs = ko.observable(false);
6668
this.isOther = ko.observable(false);
6769

6870
// The ID entered into the alternate package ID textbox.
@@ -76,8 +78,8 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
7678

7779
// The list of options in the alternate package version dropdown.
7880
this.alternatePackageVersions = ko.pureComputed(function () {
79-
// Include an "Any Version" option in case users want to select the package registration.
80-
return [strings_AnyVersion].concat(self.alternatePackageVersionsCached());
81+
// Include a "Latest" selection label in case users want to select the package registration.
82+
return [strings_SelectAlternateVersionOption].concat(self.alternatePackageVersionsCached());
8183
}, this);
8284

8385
// Whether or not the versions of the currently entered alternate package ID have been loaded.
@@ -141,8 +143,8 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
141143
this.alternatePackageVersion = ko.pureComputed(function () {
142144
if (self.alternatePackageId()) {
143145
var version = self.chosenAlternatePackageVersion();
144-
// If the chosen version is the "Any Version" string, don't submit it with the form.
145-
if (version !== strings_AnyVersion) {
146+
// If the chosen version string is the selection label, don't submit it with the form.
147+
if (version !== strings_SelectAlternateVersionOption) {
146148
return version;
147149
}
148150
}
@@ -171,6 +173,7 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
171173
id: id,
172174
versions: self.dropdown.chosenItems(),
173175
isLegacy: self.isLegacy(),
176+
hasCriticalBugs: self.hasCriticalBugs(),
174177
isOther: self.isOther(),
175178
alternatePackageId: self.alternatePackageId(),
176179
alternatePackageVersion: self.alternatePackageVersion(),
@@ -198,6 +201,7 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
198201
}
199202

200203
versionData.IsLegacy = self.isLegacy();
204+
versionData.HasCriticalBugs = self.hasCriticalBugs();
201205
versionData.IsOther = self.isOther();
202206
versionData.AlternatePackageId = self.alternatePackageId();
203207
versionData.AlternatePackageVersion = self.alternatePackageVersion();
@@ -211,6 +215,7 @@ function ManageDeprecationViewModel(id, versionDeprecationStateDictionary, defau
211215
}
212216

213217
self.isLegacy(versionData.IsLegacy);
218+
self.hasCriticalBugs(versionData.HasCriticalBugs);
214219
self.isOther(versionData.IsOther);
215220

216221
self.chosenAlternatePackageId(versionData.AlternatePackageId);

src/NuGetGallery/ViewModels/ManagePackageViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public VersionDeprecationState(Package package, string text)
149149
if (deprecation != null)
150150
{
151151
IsLegacy = deprecation.Status.HasFlag(PackageDeprecationStatus.Legacy);
152+
HasCriticalBugs = deprecation.Status.HasFlag(PackageDeprecationStatus.CriticalBugs);
152153
IsOther = deprecation.Status.HasFlag(PackageDeprecationStatus.Other);
153154

154155
AlternatePackageId = deprecation.AlternatePackageRegistration?.Id;
@@ -168,6 +169,7 @@ public VersionDeprecationState(Package package, string text)
168169

169170
public string Text { get; }
170171
public bool IsLegacy { get; }
172+
public bool HasCriticalBugs { get; }
171173
public bool IsOther { get; }
172174
public string AlternatePackageId { get; }
173175
public string AlternatePackageVersion { get; }

src/NuGetGallery/Views/Packages/DisplayPackage.cshtml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,21 @@
582582
{
583583
var deprecationTitle = packageVersion.Version;
584584
var isLegacy = packageVersion.DeprecationStatus.HasFlag(PackageDeprecationStatus.Legacy);
585-
if (isLegacy)
585+
var hasCriticalBugs = packageVersion.DeprecationStatus.HasFlag(PackageDeprecationStatus.CriticalBugs);
586+
if (hasCriticalBugs)
586587
{
587-
deprecationTitle += " is deprecated because it is legacy and is no longer maintained.";
588+
if (isLegacy)
589+
{
590+
deprecationTitle += " is deprecated because it's legacy and has critical bugs.";
591+
}
592+
else
593+
{
594+
deprecationTitle += " is deprecated because it has critical bugs.";
595+
}
596+
}
597+
else if (isLegacy)
598+
{
599+
deprecationTitle += " is deprecated because it's legacy and no longer maintained.";
588600
}
589601
else
590602
{

src/NuGetGallery/Views/Packages/Manage.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
var versionListedState = @Html.Raw(Json.Encode(Model.VersionListedStateDictionary));
8484
8585
// Set up deprecation section
86-
var strings_AnyVersion = "Any version";
86+
var strings_SelectAlternateVersionOption = "Latest";
8787
var versionDeprecationState = @Html.Raw(Json.Encode(Model.VersionDeprecationStateDictionary));
8888
8989
$(function () {

src/NuGetGallery/Views/Packages/_DisplayPackageDeprecation.cshtml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,22 @@
99

1010
<div id="deprecation-container-label" class="deprecation-expander-info-right">
1111
@{
12+
var hasCriticalBugs = Model.DeprecationStatus.HasFlag(PackageDeprecationStatus.CriticalBugs);
1213
var isLegacy = Model.DeprecationStatus.HasFlag(PackageDeprecationStatus.Legacy);
13-
if (isLegacy)
14+
if (hasCriticalBugs)
1415
{
15-
@:This package has been deprecated because it is <b>legacy</b> and is no longer maintained.
16+
if (isLegacy)
17+
{
18+
@:This package has been deprecated because it's <b>legacy</b> and has <b>critical bugs</b>.
19+
}
20+
else
21+
{
22+
@:This package has been deprecated because it has <b>critical bugs</b>.
23+
}
24+
}
25+
else if (isLegacy)
26+
{
27+
@:This package has been deprecated because it's <b>legacy</b> and no longer maintained.
1628
}
1729
else
1830
{

0 commit comments

Comments
 (0)