Skip to content

Commit 1cb2166

Browse files
authored
[Upload UI]: Improve experience when package has no license (#9038)
* Improve warning if package has no license * Tweak * Tweak
1 parent 1cdf0b3 commit 1cb2166

8 files changed

Lines changed: 53 additions & 14 deletions

src/NuGetGallery/NuGetGallery.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@
331331
<Compile Include="Modules\CookieComplianceHttpModule.cs" />
332332
<Compile Include="RequestModels\DeletePackagesApiRequest.cs" />
333333
<Compile Include="RequestModels\UpdateListedRequest.cs" />
334+
<Compile Include="Services\MissingLicenseValidationMessage.cs" />
334335
<Compile Include="Services\UploadPackageIdNamespaceConflict.cs" />
335336
<Compile Include="Services\ImageDomainValidator.cs" />
336337
<Compile Include="Services\IMarkdownService.cs" />

src/NuGetGallery/Services/InvalidLicenseUrlValidationMessage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace NuGetGallery
1111
/// </summary>
1212
public class InvalidLicenseUrlValidationMessage : IValidationMessage
1313
{
14-
private string DetailsLink => $"<a href=\"https://aka.ms/invalidNuGetLicenseUrl\" aria-label= \"{Strings.UploadPackage_LearMore_PackagingLicense}\">{Strings.UploadPackage_LearnMore}</a>.";
14+
private string DetailsLink => $"<a href=\"https://aka.ms/invalidNuGetLicenseUrl\" aria-label= \"{Strings.UploadPackage_LearnMore_PackagingLicense}\">{Strings.UploadPackage_LearnMore}</a>.";
1515
private string DetailsPlainText => "https://aka.ms/invalidNuGetLicenseUrl";
1616

1717
private readonly string _baseMessage;

src/NuGetGallery/Services/LicenseUrlDeprecationValidationMessage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace NuGetGallery
1212
/// </summary>
1313
public class LicenseUrlDeprecationValidationMessage : IValidationMessage
1414
{
15-
private string DeprecationLink => $"<a href=\"{GalleryConstants.LicenseDeprecationUrl}\" aria-label= \"{Strings.UploadPackage_LearnMore_LicenseUrlDreprecation}\">{Strings.UploadPackage_LearnMore}</a>.";
15+
private string DeprecationLink => $"<a href=\"{GalleryConstants.LicenseDeprecationUrl}\" aria-label=\"{Strings.UploadPackage_LearnMore_LicenseUrlDreprecation}\">{Strings.UploadPackage_LearnMore}</a>.";
1616

1717
private readonly string _baseMessage;
1818

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
using System.Globalization;
6+
using System.Web;
7+
8+
namespace NuGetGallery
9+
{
10+
/// <summary>
11+
/// A warning for packages that are missing licensing metadata.
12+
/// </summary>
13+
public class MissingLicenseValidationMessage : IValidationMessage
14+
{
15+
private string DocumentationLink => $"<a href=\"https://aka.ms/nuget/authoring-best-practices#licensing\" aria-label=\"{Strings.UploadPackage_LearnMore_PackagingLicense}\">{Strings.UploadPackage_LearnMore}</a>.";
16+
17+
private readonly string _baseMessage;
18+
19+
public MissingLicenseValidationMessage(string basePlainTextMessage)
20+
{
21+
if (string.IsNullOrWhiteSpace(basePlainTextMessage))
22+
{
23+
throw new ArgumentException(
24+
string.Format(CultureInfo.CurrentCulture, Strings.ParameterCannotBeNullOrEmpty, nameof(basePlainTextMessage)), nameof(basePlainTextMessage));
25+
}
26+
27+
_baseMessage = basePlainTextMessage;
28+
PlainTextMessage = $"{_baseMessage} {Strings.UploadPackage_LearnMore}: https://aka.ms/nuget/authoring-best-practices#licensing.";
29+
}
30+
31+
public string PlainTextMessage { get; }
32+
33+
public bool HasRawHtmlRepresentation => true;
34+
35+
public string RawHtmlMessage
36+
=> HttpUtility.HtmlEncode(_baseMessage) + " " + DocumentationLink;
37+
}
38+
}

src/NuGetGallery/Services/PackageMetadataValidationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private async Task<PackageValidationResult> CheckLicenseMetadataAsync(PackageArc
211211
}
212212
else
213213
{
214-
warnings.Add(new LicenseUrlDeprecationValidationMessage(Strings.UploadPackage_LicenseShouldBeSpecified));
214+
warnings.Add(new MissingLicenseValidationMessage(Strings.UploadPackage_LicenseShouldBeSpecified));
215215
}
216216
}
217217

src/NuGetGallery/Strings.Designer.cs

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGetGallery/Strings.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ The {1} Team</value>
11901190
<data name="ReadmeNotEditableWithEmbeddedReadme" xml:space="preserve">
11911191
<value>The readme is not editable with the package has the embedded readme</value>
11921192
</data>
1193-
<data name="UploadPackage_LearMore_PackagingLicense" xml:space="preserve">
1193+
<data name="UploadPackage_LearnMore_PackagingLicense" xml:space="preserve">
11941194
<value>Learn more about including a license within the package</value>
11951195
</data>
11961196
<data name="UploadPackage_LearnMore_IconUrlDeprecation" xml:space="preserve">

tests/NuGetGallery.Facts/Services/PackageMetadataValidationServiceFacts.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public async Task HandlesMissingLicenseAccordingToSettings(bool allowLicenseless
437437
Assert.Equal(PackageValidationResultType.Accepted, result.Type);
438438
Assert.Null(result.Message);
439439
Assert.Single(result.Warnings);
440-
Assert.IsType<LicenseUrlDeprecationValidationMessage>(result.Warnings[0]);
440+
Assert.IsType<MissingLicenseValidationMessage>(result.Warnings[0]);
441441
Assert.StartsWith("All published packages should have license information specified.", result.Warnings[0].PlainTextMessage);
442442
}
443443
}

0 commit comments

Comments
 (0)