Skip to content

Commit 0e467a3

Browse files
author
Scott Bommarito
authored
Mark deprecated versions in Display Package page's version history (#6973)
1 parent ebdca3c commit 0e467a3

14 files changed

Lines changed: 147 additions & 64 deletions

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

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Bootstrap/less/theme/page-display-package.less

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
margin-bottom: 0;
88
}
99

10+
tr {
11+
border-bottom: 1px solid lightgray;
12+
}
13+
1014
.package-title {
1115
margin-bottom: 24px;
1216

@@ -67,14 +71,15 @@
6771
.package-details-main {
6872
.break-word;
6973

70-
.signature-info-cell {
74+
.package-icon-cell {
7175
cursor: default;
72-
max-width: 1em;
7376
padding-left: 0;
7477
padding-right: 0;
78+
text-align: right;
7579

76-
.signature-info {
80+
.package-icon {
7781
padding-left: 6px;
82+
padding-right: 6px;
7883
}
7984
}
8085
}

src/NuGetGallery.Core/NuGetGallery.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
<Compile Include="Services\IFileMetadataService.cs" />
194194
<Compile Include="Services\IRevalidationStateService.cs" />
195195
<Compile Include="Services\ISimpleCloudBlob.cs" />
196+
<Compile Include="Services\PackageDeprecationFieldsToInclude.cs" />
196197
<Compile Include="Services\SymbolPackageFileServiceMetadata.cs" />
197198
<Compile Include="Services\PackageFileServiceMetadata.cs" />
198199
<Compile Include="Services\RevalidationState.cs" />

src/NuGetGallery.Core/Services/CorePackageService.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ public virtual async Task UpdatePackageSigningCertificateAsync(string packageId,
285285
}
286286
}
287287

288-
protected IQueryable<Package> GetPackagesByIdQueryable(string id, bool withDeprecations = false)
288+
protected IQueryable<Package> GetPackagesByIdQueryable(
289+
string id,
290+
PackageDeprecationFieldsToInclude deprecationFields = PackageDeprecationFieldsToInclude.None)
289291
{
290292
var packages = _packageRepository
291293
.GetAll()
@@ -295,7 +297,12 @@ protected IQueryable<Package> GetPackagesByIdQueryable(string id, bool withDepre
295297
.Include(p => p.SymbolPackages)
296298
.Where(p => p.PackageRegistration.Id == id);
297299

298-
if (withDeprecations)
300+
if (deprecationFields == PackageDeprecationFieldsToInclude.Deprecation)
301+
{
302+
packages = packages
303+
.Include(p => p.Deprecations);
304+
}
305+
else if (deprecationFields == PackageDeprecationFieldsToInclude.DeprecationAndRelationships)
299306
{
300307
packages = packages
301308
.Include(p => p.Deprecations.Select(d => d.AlternatePackage.PackageRegistration))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace NuGetGallery
5+
{
6+
public enum PackageDeprecationFieldsToInclude
7+
{
8+
None,
9+
Deprecation,
10+
DeprecationAndRelationships
11+
}
12+
}

src/NuGetGallery/Controllers/ManageDeprecationJsonApiController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public virtual async Task<JsonResult> Deprecate(
145145
return DeprecateErrorResponse(HttpStatusCode.BadRequest, Strings.DeprecatePackage_InvalidCvss);
146146
}
147147

148-
var packages = _packageService.FindPackagesById(id, withDeprecations: true);
148+
var packages = _packageService.FindPackagesById(id, PackageDeprecationFieldsToInclude.DeprecationAndRelationships);
149149
var registration = packages.FirstOrDefault()?.PackageRegistration;
150150
if (registration == null)
151151
{

src/NuGetGallery/Controllers/PackagesController.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ public virtual async Task<ActionResult> DisplayPackage(string id, string version
710710

711711
Package package = null;
712712
// Load all packages with the ID.
713-
var packages = _packageService.FindPackagesById(id);
713+
var packages = _packageService.FindPackagesById(id, PackageDeprecationFieldsToInclude.Deprecation);
714714
if (version != null)
715715
{
716716
if (version.Equals(GalleryConstants.AbsoluteLatestUrlString, StringComparison.InvariantCultureIgnoreCase))
@@ -1456,7 +1456,8 @@ public virtual async Task<ActionResult> Manage(string id, string version = null)
14561456
Package package = null;
14571457

14581458
// Load all versions of the package.
1459-
var packages = _packageService.FindPackagesById(id, withDeprecations: true);
1459+
var packages = _packageService.FindPackagesById(
1460+
id, PackageDeprecationFieldsToInclude.DeprecationAndRelationships);
14601461
if (version != null)
14611462
{
14621463
// Try to find the exact version if it was specified.

src/NuGetGallery/Services/IPackageService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ public interface IPackageService : ICorePackageService
1919
{
2020
/// <summary>
2121
/// Returns all packages with an <see cref="Package.Id"/> of <paramref name="id"/>.
22-
/// Includes deprecation entities if <paramref name="withDeprecations"/> is true.
22+
/// Includes deprecation fields based on <paramref name="deprecationFields"/>.
2323
/// </summary>
24-
IReadOnlyCollection<Package> FindPackagesById(string id, bool withDeprecations = false);
24+
IReadOnlyCollection<Package> FindPackagesById(
25+
string id,
26+
PackageDeprecationFieldsToInclude deprecationFields = PackageDeprecationFieldsToInclude.None);
2527

2628
/// <summary>
2729
/// Gets the package with the given ID and version when exists;

src/NuGetGallery/Services/PackageService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,11 @@ public override PackageRegistration FindPackageRegistrationById(string packageId
135135
.SingleOrDefault(pr => pr.Id == packageId);
136136
}
137137

138-
public virtual IReadOnlyCollection<Package> FindPackagesById(string id, bool withDeprecations = false)
138+
public virtual IReadOnlyCollection<Package> FindPackagesById(
139+
string id,
140+
PackageDeprecationFieldsToInclude deprecationFields = PackageDeprecationFieldsToInclude.None)
139141
{
140-
return GetPackagesByIdQueryable(id, withDeprecations).ToList();
142+
return GetPackagesByIdQueryable(id, deprecationFields).ToList();
141143
}
142144

143145
public virtual Package FindPackageByIdAndVersion(

src/NuGetGallery/ViewModels/DisplayPackageViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public DisplayPackageViewModel(Package package, User currentUser, PackageDepreca
4949

5050
if (deprecation != null)
5151
{
52-
DeprecationStatus = deprecation.Status;
53-
5452
CveIds = deprecation.Cves?.Select(c => c.CveId).ToList();
5553
CweIds = deprecation.Cwes?.Select(c => c.CweId).ToList();
5654

@@ -123,6 +121,9 @@ private DisplayPackageViewModel(Package package, User currentUser, string pushed
123121
LicenseNames = licenseNames.Split(',').Select(l => l.Trim());
124122
}
125123
}
124+
125+
DeprecationStatus = package.Deprecations.SingleOrDefault()?.Status
126+
?? PackageDeprecationStatus.NotDeprecated;
126127
}
127128

128129
public bool ValidatingTooLong { get; set; }

0 commit comments

Comments
 (0)