Skip to content

Commit 6cb7f30

Browse files
authored
Upload license expression redirect url logic (#6641)
* Upload license expression redirect url logic * fix nit and update
1 parent 51ca9a7 commit 6cb7f30

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
using System;
5+
6+
namespace NuGetGallery.Helpers
7+
{
8+
public static class LicenseExpressionRedirectUrlHelper
9+
{
10+
private const string LicenseExpressionDeprecationUrlFormat = "https://licenses.nuget.org/{0}";
11+
12+
public static string GetLicenseExpressionRedirectUrl(string licenseExpression)
13+
{
14+
return new Uri(string.Format(LicenseExpressionDeprecationUrlFormat, licenseExpression)).AbsoluteUri;
15+
}
16+
}
17+
}

src/NuGetGallery/NuGetGallery.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@
284284
<Compile Include="GalleryConstants.cs" />
285285
<Compile Include="GlobalSuppressions.cs" />
286286
<Compile Include="Helpers\GravatarHelper.cs" />
287+
<Compile Include="Helpers\LicenseExpressionRedirectUrlHelper.cs" />
287288
<Compile Include="Helpers\ObfuscationHelper.cs" />
288289
<Compile Include="Helpers\TextHelper.cs" />
289290
<Compile Include="Helpers\ZipArchiveHelpers.cs" />

src/NuGetGallery/Services/PackageUploadService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ namespace NuGetGallery
2222
{
2323
public class PackageUploadService : IPackageUploadService
2424
{
25-
private const string LicenseExpressionDeprecationUrlFormat = "https://licenses.nuget.org/{0}";
26-
2725
private static readonly IReadOnlyCollection<string> AllowedLicenseFileExtensions = new HashSet<string>
2826
{
2927
"",
@@ -374,7 +372,7 @@ private static string GetExpectedLicenseUrl(LicenseMetadata licenseMetadata)
374372

375373
if (LicenseType.Expression == licenseMetadata.Type)
376374
{
377-
return new Uri(string.Format(LicenseExpressionDeprecationUrlFormat, licenseMetadata.License)).AbsoluteUri;
375+
return LicenseExpressionRedirectUrlHelper.GetLicenseExpressionRedirectUrl(licenseMetadata.License);
378376
}
379377

380378
throw new InvalidOperationException($"Unsupported license metadata type: {licenseMetadata.Type}");

src/NuGetGallery/ViewModels/DisplayPackageViewModel.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using NuGet.Services.Entities;
88
using NuGet.Services.Validation.Issues;
99
using NuGet.Versioning;
10+
using NuGetGallery.Helpers;
1011

1112
namespace NuGetGallery
1213
{
@@ -63,7 +64,12 @@ public DisplayPackageViewModel(Package package, User currentUser, string pushedB
6364
ProjectUrl = projectUrl;
6465
}
6566

66-
if (PackageHelper.TryPrepareUrlForRendering(package.LicenseUrl, out string licenseUrl))
67+
var licenseExpression = package.LicenseExpression;
68+
if (!String.IsNullOrWhiteSpace(licenseExpression))
69+
{
70+
LicenseUrl = LicenseExpressionRedirectUrlHelper.GetLicenseExpressionRedirectUrl(licenseExpression);
71+
}
72+
else if (PackageHelper.TryPrepareUrlForRendering(package.LicenseUrl, out string licenseUrl))
6773
{
6874
LicenseUrl = licenseUrl;
6975

0 commit comments

Comments
 (0)