From 8354e23cf1be479b01c63c785592a78f92fc6d38 Mon Sep 17 00:00:00 2001 From: Xavier Decoster Date: Mon, 8 May 2017 10:42:37 +0200 Subject: [PATCH] Show full version on package details page (#3887) --- .../Auditing/PackageAuditRecord.cs | 2 +- src/NuGetGallery.Core/NuGetVersionExtensions.cs | 15 ++++++++++++++- src/NuGetGallery/Controllers/ApiController.cs | 2 +- .../Controllers/PackagesController.cs | 2 +- .../Infrastructure/PackageIndexEntity.cs | 2 +- .../NormalizeVersionInterceptor.cs | 2 +- .../OData/SearchService/SearchHijacker.cs | 2 +- .../V2FeedPackageAnnotationStrategy.cs | 2 +- .../DownloadCountObjectMaterializedInterceptor.cs | 2 +- src/NuGetGallery/Services/PackageFileService.cs | 2 +- src/NuGetGallery/Services/PackageService.cs | 2 +- src/NuGetGallery/ViewModels/PackageViewModel.cs | 10 +++++++++- .../Views/Packages/DisplayPackage.cshtml | 6 +++--- .../Services/PackageFileServiceFacts.cs | 2 +- 14 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/NuGetGallery.Core/Auditing/PackageAuditRecord.cs b/src/NuGetGallery.Core/Auditing/PackageAuditRecord.cs index 2df9d40619..1a1e225a05 100644 --- a/src/NuGetGallery.Core/Auditing/PackageAuditRecord.cs +++ b/src/NuGetGallery.Core/Auditing/PackageAuditRecord.cs @@ -49,7 +49,7 @@ public PackageAuditRecord(Package package, AuditedPackageAction action) public override string GetPath() { - return $"{Id}/{NuGetVersionNormalizer.Normalize(Version)}" + return $"{Id}/{NuGetVersionFormatter.Normalize(Version)}" .ToLowerInvariant(); } } diff --git a/src/NuGetGallery.Core/NuGetVersionExtensions.cs b/src/NuGetGallery.Core/NuGetVersionExtensions.cs index a32f3b18d2..ab66e7e3de 100644 --- a/src/NuGetGallery.Core/NuGetVersionExtensions.cs +++ b/src/NuGetGallery.Core/NuGetVersionExtensions.cs @@ -7,7 +7,7 @@ namespace NuGetGallery { - public static class NuGetVersionNormalizer + public static class NuGetVersionFormatter { public static string Normalize(string version) { @@ -19,6 +19,19 @@ public static string Normalize(string version) return parsed.ToNormalizedString(); } + + public static string ToFullStringOrFallback(string version, string fallback = "") + { + NuGetVersion nugetVersion; + if (NuGetVersion.TryParse(version, out nugetVersion)) + { + return nugetVersion.ToFullString(); + } + else + { + return fallback; + } + } } public static class NuGetVersionExtensions diff --git a/src/NuGetGallery/Controllers/ApiController.cs b/src/NuGetGallery/Controllers/ApiController.cs index ce702d458d..0dd095fdf9 100644 --- a/src/NuGetGallery/Controllers/ApiController.cs +++ b/src/NuGetGallery/Controllers/ApiController.cs @@ -136,7 +136,7 @@ public virtual async Task GetPackage(string id, string version) } // Normalize the version - version = NuGetVersionNormalizer.Normalize(version); + version = NuGetVersionFormatter.Normalize(version); } else { diff --git a/src/NuGetGallery/Controllers/PackagesController.cs b/src/NuGetGallery/Controllers/PackagesController.cs index c3c2c5a212..fb48501376 100644 --- a/src/NuGetGallery/Controllers/PackagesController.cs +++ b/src/NuGetGallery/Controllers/PackagesController.cs @@ -300,7 +300,7 @@ public virtual async Task UploadPackage(HttpPostedFileBase uploadF public virtual async Task DisplayPackage(string id, string version) { - string normalized = NuGetVersionNormalizer.Normalize(version); + string normalized = NuGetVersionFormatter.Normalize(version); if (!string.Equals(version, normalized)) { // Permanent redirect to the normalized one (to avoid multiple URLs for the same content) diff --git a/src/NuGetGallery/Infrastructure/PackageIndexEntity.cs b/src/NuGetGallery/Infrastructure/PackageIndexEntity.cs index 8d922ad35d..c3eff0e59f 100644 --- a/src/NuGetGallery/Infrastructure/PackageIndexEntity.cs +++ b/src/NuGetGallery/Infrastructure/PackageIndexEntity.cs @@ -136,7 +136,7 @@ public Document ToDocument() document.Add(new Field("Version", Package.Version.ToStringSafe(), Field.Store.YES, Field.Index.NO)); string normalizedVersion = String.IsNullOrEmpty(Package.NormalizedVersion) ? - NuGetVersionNormalizer.Normalize(Package.Version) : + NuGetVersionFormatter.Normalize(Package.Version) : Package.NormalizedVersion; document.Add(new Field("NormalizedVersion", normalizedVersion.ToStringSafe(), Field.Store.YES, Field.Index.NO)); diff --git a/src/NuGetGallery/OData/QueryInterceptors/NormalizeVersionInterceptor.cs b/src/NuGetGallery/OData/QueryInterceptors/NormalizeVersionInterceptor.cs index 6ed5c7506b..b74dd4e42d 100644 --- a/src/NuGetGallery/OData/QueryInterceptors/NormalizeVersionInterceptor.cs +++ b/src/NuGetGallery/OData/QueryInterceptors/NormalizeVersionInterceptor.cs @@ -26,7 +26,7 @@ protected override Expression VisitBinary(BinaryExpression node) // We have a "Package.Version == " expression! // Transform the constant version into a normalized version - string newVersion = NuGetVersionNormalizer.Normalize((string)constSide.Value); + string newVersion = NuGetVersionFormatter.Normalize((string)constSide.Value); // Create a new expression that checks the new constant against NormalizedVersion instead return Expression.MakeBinary( diff --git a/src/NuGetGallery/OData/SearchService/SearchHijacker.cs b/src/NuGetGallery/OData/SearchService/SearchHijacker.cs index 02e4f3f750..31cc0c846e 100644 --- a/src/NuGetGallery/OData/SearchService/SearchHijacker.cs +++ b/src/NuGetGallery/OData/SearchService/SearchHijacker.cs @@ -216,7 +216,7 @@ private static Tuple ExtractComparison(BinaryExpression binExpr) } else if (memberSide.Member == VersionMember) { - return Tuple.Create(Target.Version, NuGetVersionNormalizer.Normalize((string)constSide.Value)); + return Tuple.Create(Target.Version, NuGetVersionFormatter.Normalize((string)constSide.Value)); } else if (memberSide.Member == IdMember) { diff --git a/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs b/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs index 8f812f698e..60b5cae411 100644 --- a/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs +++ b/src/NuGetGallery/OData/Serializers/V2FeedPackageAnnotationStrategy.cs @@ -25,7 +25,7 @@ public override void Annotate(HttpRequestMessage request, ODataEntry entry, obje } // Patch links to use normalized versions - var normalizedVersion = NuGetVersionNormalizer.Normalize(feedPackage.Version); + var normalizedVersion = NuGetVersionFormatter.Normalize(feedPackage.Version); NormalizeNavigationLinks(entry, request, feedPackage, normalizedVersion); // Set Atom entry metadata diff --git a/src/NuGetGallery/Services/DownloadCountObjectMaterializedInterceptor.cs b/src/NuGetGallery/Services/DownloadCountObjectMaterializedInterceptor.cs index 3a782a5da3..510026aeee 100644 --- a/src/NuGetGallery/Services/DownloadCountObjectMaterializedInterceptor.cs +++ b/src/NuGetGallery/Services/DownloadCountObjectMaterializedInterceptor.cs @@ -29,7 +29,7 @@ protected void InterceptPackageMaterialized(Package package) } var packageNormalizedVersion = String.IsNullOrEmpty(package.NormalizedVersion) - ? NuGetVersionNormalizer.Normalize(package.Version) + ? NuGetVersionFormatter.Normalize(package.Version) : package.NormalizedVersion; int downloadCount; diff --git a/src/NuGetGallery/Services/PackageFileService.cs b/src/NuGetGallery/Services/PackageFileService.cs index afaabb3141..f51a040d9a 100644 --- a/src/NuGetGallery/Services/PackageFileService.cs +++ b/src/NuGetGallery/Services/PackageFileService.cs @@ -131,7 +131,7 @@ private static string BuildFileName(Package package) return BuildFileName( package.PackageRegistration.Id, String.IsNullOrEmpty(package.NormalizedVersion) ? - NuGetVersionNormalizer.Normalize(package.Version) : + NuGetVersionFormatter.Normalize(package.Version) : package.NormalizedVersion); } diff --git a/src/NuGetGallery/Services/PackageService.cs b/src/NuGetGallery/Services/PackageService.cs index 89eef7aba6..6574578ada 100644 --- a/src/NuGetGallery/Services/PackageService.cs +++ b/src/NuGetGallery/Services/PackageService.cs @@ -244,7 +244,7 @@ public virtual Package FindPackageByIdAndVersionStrict(string id, string version throw new ArgumentException(nameof(version)); } - var normalizedVersion = NuGetVersionNormalizer.Normalize(version); + var normalizedVersion = NuGetVersionFormatter.Normalize(version); // These string comparisons are case-(in)sensitive depending on SQLServer collation. // Case-insensitive collation is recommended, e.g. SQL_Latin1_General_CP1_CI_AS. diff --git a/src/NuGetGallery/ViewModels/PackageViewModel.cs b/src/NuGetGallery/ViewModels/PackageViewModel.cs index 74c877025e..fde5f0d754 100644 --- a/src/NuGetGallery/ViewModels/PackageViewModel.cs +++ b/src/NuGetGallery/ViewModels/PackageViewModel.cs @@ -3,6 +3,7 @@ using System; using System.Linq; using System.Collections.Generic; +using NuGet.Versioning; namespace NuGetGallery { @@ -10,13 +11,18 @@ public class PackageViewModel : IPackageVersionModel { private readonly Package _package; private string _pendingTitle; + private string _fullVersion; public PackageViewModel(Package package) { _package = package; + + _fullVersion = NuGetVersionFormatter.ToFullStringOrFallback(package.Version, fallback: package.Version); + Version = String.IsNullOrEmpty(package.NormalizedVersion) ? - NuGetVersionNormalizer.Normalize(package.Version) : + NuGetVersionFormatter.Normalize(package.Version) : package.NormalizedVersion; + Description = package.Description; ReleaseNotes = package.ReleaseNotes; IconUrl = package.IconUrl; @@ -40,6 +46,7 @@ public PackageViewModel(Package package) LicenseNames = licenseNames.Split(',').Select(l => l.Trim()); } } + public string Description { get; set; } public string ReleaseNotes { get; set; } public string IconUrl { get; set; } @@ -69,6 +76,7 @@ public string Id } public string Version { get; set; } + public string FullVersion => _fullVersion; public string Title { diff --git a/src/NuGetGallery/Views/Packages/DisplayPackage.cshtml b/src/NuGetGallery/Views/Packages/DisplayPackage.cshtml index 3e7ca37536..d552a6b94c 100644 --- a/src/NuGetGallery/Views/Packages/DisplayPackage.cshtml +++ b/src/NuGetGallery/Views/Packages/DisplayPackage.cshtml @@ -219,7 +219,7 @@

@Model.Title.Abbreviate(40)

-

@Model.Version

+

@Model.FullVersion

@foreach (var line in Model.Description.ToStringSafe().Split('\n')) { @@ -354,7 +354,7 @@ @if (!packageVersion.IsCurrent(Model)) { - + @packageVersion.Title.Abbreviate(20) @packageVersion.Version @if (packageVersion.LatestStableVersion) @@ -365,7 +365,7 @@ } else { - + @packageVersion.Title.Abbreviate(20) @packageVersion.Version (this version) } diff --git a/tests/NuGetGallery.Facts/Services/PackageFileServiceFacts.cs b/tests/NuGetGallery.Facts/Services/PackageFileServiceFacts.cs index 8c873bb53c..cde3879e8e 100644 --- a/tests/NuGetGallery.Facts/Services/PackageFileServiceFacts.cs +++ b/tests/NuGetGallery.Facts/Services/PackageFileServiceFacts.cs @@ -439,7 +439,7 @@ static string BuildFileName( return string.Format( Constants.PackageFileSavePathTemplate, id.ToLowerInvariant(), - NuGetVersionNormalizer.Normalize(version).ToLowerInvariant(), // No matter what ends up getting passed in, the version should be normalized + NuGetVersionFormatter.Normalize(version).ToLowerInvariant(), // No matter what ends up getting passed in, the version should be normalized Constants.NuGetPackageFileExtension); }