Skip to content

Commit

Permalink
Upload license expression redirect url logic (#6641)
Browse files Browse the repository at this point in the history
* Upload license expression redirect url logic

* fix nit and update
  • Loading branch information
zhhyu authored Nov 9, 2018
1 parent 51ca9a7 commit 6cb7f30
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/NuGetGallery/Helpers/LicenseExpressionRedirectUrlHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;

namespace NuGetGallery.Helpers
{
public static class LicenseExpressionRedirectUrlHelper
{
private const string LicenseExpressionDeprecationUrlFormat = "https://licenses.nuget.org/{0}";

public static string GetLicenseExpressionRedirectUrl(string licenseExpression)
{
return new Uri(string.Format(LicenseExpressionDeprecationUrlFormat, licenseExpression)).AbsoluteUri;
}
}
}
1 change: 1 addition & 0 deletions src/NuGetGallery/NuGetGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
<Compile Include="GalleryConstants.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Helpers\GravatarHelper.cs" />
<Compile Include="Helpers\LicenseExpressionRedirectUrlHelper.cs" />
<Compile Include="Helpers\ObfuscationHelper.cs" />
<Compile Include="Helpers\TextHelper.cs" />
<Compile Include="Helpers\ZipArchiveHelpers.cs" />
Expand Down
4 changes: 1 addition & 3 deletions src/NuGetGallery/Services/PackageUploadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ namespace NuGetGallery
{
public class PackageUploadService : IPackageUploadService
{
private const string LicenseExpressionDeprecationUrlFormat = "https://licenses.nuget.org/{0}";

private static readonly IReadOnlyCollection<string> AllowedLicenseFileExtensions = new HashSet<string>
{
"",
Expand Down Expand Up @@ -374,7 +372,7 @@ private static string GetExpectedLicenseUrl(LicenseMetadata licenseMetadata)

if (LicenseType.Expression == licenseMetadata.Type)
{
return new Uri(string.Format(LicenseExpressionDeprecationUrlFormat, licenseMetadata.License)).AbsoluteUri;
return LicenseExpressionRedirectUrlHelper.GetLicenseExpressionRedirectUrl(licenseMetadata.License);
}

throw new InvalidOperationException($"Unsupported license metadata type: {licenseMetadata.Type}");
Expand Down
8 changes: 7 additions & 1 deletion src/NuGetGallery/ViewModels/DisplayPackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NuGet.Services.Entities;
using NuGet.Services.Validation.Issues;
using NuGet.Versioning;
using NuGetGallery.Helpers;

namespace NuGetGallery
{
Expand Down Expand Up @@ -63,7 +64,12 @@ public DisplayPackageViewModel(Package package, User currentUser, string pushedB
ProjectUrl = projectUrl;
}

if (PackageHelper.TryPrepareUrlForRendering(package.LicenseUrl, out string licenseUrl))
var licenseExpression = package.LicenseExpression;
if (!String.IsNullOrWhiteSpace(licenseExpression))
{
LicenseUrl = LicenseExpressionRedirectUrlHelper.GetLicenseExpressionRedirectUrl(licenseExpression);
}
else if (PackageHelper.TryPrepareUrlForRendering(package.LicenseUrl, out string licenseUrl))
{
LicenseUrl = licenseUrl;

Expand Down

0 comments on commit 6cb7f30

Please sign in to comment.