Skip to content

Commit

Permalink
Display warning when specified version was not found (#8155)
Browse files Browse the repository at this point in the history
* Display warning message if specified package version isn't found
* made info a warning
* fixed version comparison and warning text that is displayed
* Addresses #4624
  • Loading branch information
rocklan authored Aug 17, 2020
1 parent 533076a commit 6975320
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/NuGetGallery.Services/PackageManagement/PackageFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public Package GetFiltered(IReadOnlyCollection<Package> packages, PackageFilterC
result = result ?? _packageService.FilterLatestPackageBySuffix(packages, version, preRelease);
}

// The package still wasn't found so let's just get the latest version. This applies when
// no version is specified, or when the version asked for (in context.Version) wasn't found
result = result ?? _packageService.FilterLatestPackage(packages, SemVerLevelKey.SemVer2, allowPrerelease: true);

return result;
Expand Down
6 changes: 6 additions & 0 deletions src/NuGetGallery/Controllers/PackagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,12 @@ public virtual async Task<ActionResult> DisplayPackage(string id, string version
model.GitHubDependenciesInformation = _contentObjectService.GitHubUsageConfiguration.GetPackageInformation(id);
}

if (normalized != null && !string.Equals(package.NormalizedVersion, normalized, StringComparison.OrdinalIgnoreCase))
{
model.VersionRequested = normalized;
model.VersionRequestedWasNotFound = true;
}

if (!string.IsNullOrWhiteSpace(package.LicenseExpression))
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/NuGetGallery/ViewModels/PackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class PackageViewModel : IPackageVersionModel
public bool LatestStableVersionSemVer2 { get; set; }
public bool DevelopmentDependency { get; set; }
public bool Prerelease { get; set; }
public string VersionRequested { get; set; }
public bool VersionRequestedWasNotFound { get; set; }
public int DownloadCount { get; set; }
public bool Listed { get; set; }
public bool FailedValidation { get; set; }
Expand Down
9 changes: 8 additions & 1 deletion src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,14 @@
</text>
)
}

@if (Model.VersionRequestedWasNotFound)
{
@ViewHelpers.AlertWarning(
@<text>
The specified version @Model.VersionRequested was not found. You have been taken to version @(Model.Version).
</text>
)
}
@if (Model.HasNewerRelease)
{
@ViewHelpers.AlertInfo(
Expand Down

0 comments on commit 6975320

Please sign in to comment.