Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload license expression redirect url logic #6641

Merged
merged 2 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}";
zhhyu marked this conversation as resolved.
Show resolved Hide resolved

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