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

[ReleasePrep][2022.11.09]RI of dev into main #9305

Merged
merged 15 commits into from
Nov 10, 2022
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
5 changes: 5 additions & 0 deletions src/AccountDeleter/EmptyFeatureFlagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,10 @@ public bool ProxyGravatarEnSubdomain()
{
throw new NotImplementedException();
}

public bool IsDisplayUploadWarningV2Enabled(User user)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public bool IsMarkdigMdSyntaxHighlightEnabled()
throw new NotImplementedException();
}

public bool IsDisplayUploadWarningV2Enabled(User user)
{
throw new NotImplementedException();
}

public bool IsODataDatabaseReadOnlyEnabled()
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@
<Version>2.106.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Content Include="Scripts\nssm.exe" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NuGet.Services.Entities\NuGet.Services.Entities.csproj">
<Project>{6262f4fc-29be-4226-b676-db391c89d396}</Project>
Expand Down
11 changes: 11 additions & 0 deletions src/NuGetGallery.Core/NuGetVersionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Text.RegularExpressions;
using NuGet.Services.Entities;
using NuGet.Versioning;

namespace NuGetGallery
Expand Down Expand Up @@ -31,6 +32,16 @@ public static string ToFullString(string version)
return version;
}
}

public static string GetNormalizedPackageVersion(Package package)
{
if (package == null)
{
return string.Empty;
}

return string.IsNullOrEmpty(package.NormalizedVersion) ? Normalize(package.Version) : package.NormalizedVersion;
}
}

public static class NuGetVersionExtensions
Expand Down
5 changes: 2 additions & 3 deletions src/NuGetGallery.Core/Services/FIleNameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ public static string BuildFileName(Package package, string format, string exten

return BuildFileName(
package.PackageRegistration.Id,
string.IsNullOrEmpty(package.NormalizedVersion) ?
NuGetVersionFormatter.Normalize(package.Version) :
package.NormalizedVersion, format, extension);
NuGetVersionFormatter.GetNormalizedPackageVersion(package),
format, extension);
}

public static string BuildFileName(string id, string version, string pathTemplate, string extension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class FeatureFlagService : IFeatureFlagService
private const string LicenseMdRenderingFlightName = GalleryPrefix + "LicenseMdRendering";
private const string MarkdigMdRenderingFlightName = GalleryPrefix + "MarkdigMdRendering";
private const string MarkdigMdSyntaxHighlightFlightName = GalleryPrefix + "MarkdigMdSyntaxHighlight";
private const string DisplayUploadWarningV2FlightName = GalleryPrefix + "DisplayUploadWarningV2";
private const string DeletePackageApiFlightName = GalleryPrefix + "DeletePackageApi";
private const string ImageAllowlistFlightName = GalleryPrefix + "ImageAllowlist";
private const string DisplayBannerFlightName = GalleryPrefix + "Banner";
Expand Down Expand Up @@ -341,6 +342,11 @@ public bool IsMarkdigMdSyntaxHighlightEnabled()
return _client.IsEnabled(MarkdigMdSyntaxHighlightFlightName, defaultValue: false);
}

public bool IsDisplayUploadWarningV2Enabled(User user)
{
return _client.IsEnabled(DisplayUploadWarningV2FlightName, user, defaultValue: false);
}

public bool IsDeletePackageApiEnabled(User user)
{
return _client.IsEnabled(DeletePackageApiFlightName, user, defaultValue: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ public interface IFeatureFlagService
/// </summary>
bool IsMarkdigMdSyntaxHighlightEnabled();

/// <summary>
/// Whether the new warning of the verfiy metadata when upload package is enabled.
/// </summary>
bool IsDisplayUploadWarningV2Enabled(User user);

/// <summary>
/// Whether or not the user can delete a package through the API.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public async Task<Issue> AddNewSupportRequestAsync(
newIssue.CreatedBy = loggedInUser;
newIssue.OwnerEmail = requestorEmailAddress;
newIssue.PackageId = package?.PackageRegistration.Id;
newIssue.PackageVersion = package?.Version;
newIssue.PackageVersion = NuGetVersionFormatter.GetNormalizedPackageVersion(package);
newIssue.Reason = reason;
newIssue.SiteRoot = _siteRoot;
newIssue.UserKey = user?.Key;
Expand Down
6 changes: 6 additions & 0 deletions src/NuGetGallery/App_Data/Files/Content/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@
"SiteAdmins": false,
"Accounts": [],
"Domains": []
},
"NuGetGallery.DisplayUploadWarningV2": {
"All": true,
"SiteAdmins": false,
"Accounts": [],
"Domains": []
}
}
}
4 changes: 2 additions & 2 deletions src/NuGetGallery/Controllers/OrganizationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected override Task SendNewAccountEmailAsync(User account)
var message = new NewAccountMessage(
MessageServiceConfiguration,
account,
Url.ConfirmOrganizationEmail(account.Username, account.EmailConfirmationToken, relativeUrl: false));
Url.ConfirmOrganizationEmail(account.Username, account.EmailConfirmationToken, relativeUrl: false, supportEmail: true));

return MessageService.SendMessageAsync(message);
}
Expand All @@ -78,7 +78,7 @@ protected override Task SendEmailChangedConfirmationNoticeAsync(User account)
var message = new EmailChangeConfirmationMessage(
MessageServiceConfiguration,
account,
Url.ConfirmOrganizationEmail(account.Username, account.EmailConfirmationToken, relativeUrl: false));
Url.ConfirmOrganizationEmail(account.Username, account.EmailConfirmationToken, relativeUrl: false, supportEmail: true));

return MessageService.SendMessageAsync(message);
}
Expand Down
7 changes: 7 additions & 0 deletions src/NuGetGallery/Controllers/PackagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ private async Task<ActionResult> UploadPackageInternal(SubmitPackageRequest mode
verifyRequest.LicenseExpressionSegments = GetLicenseExpressionSegmentsOrNull(packageMetadata.LicenseMetadata);
verifyRequest.ReadmeFileContents = await GetReadmeFileContentsOrNullAsync(packageMetadata, packageArchiveReader);
verifyRequest.IsMarkdigMdSyntaxHighlightEnabled = _featureFlagService.IsMarkdigMdSyntaxHighlightEnabled();
verifyRequest.IsDisplayUploadWarningV2Enabled = _featureFlagService.IsDisplayUploadWarningV2Enabled(currentUser);

model.InProgressUpload = verifyRequest;
return View(model);
Expand Down Expand Up @@ -658,6 +659,7 @@ private async Task<JsonResult> GetVerifyPackageView(User currentUser,
model.IsSymbolsPackage = isSymbolsPackageUpload;
model.HasExistingAvailableSymbols = hasExistingSymbolsPackageAvailable;
model.IsMarkdigMdSyntaxHighlightEnabled = _featureFlagService.IsMarkdigMdSyntaxHighlightEnabled();
model.IsDisplayUploadWarningV2Enabled = _featureFlagService.IsDisplayUploadWarningV2Enabled(currentUser);
model.Warnings.AddRange(packageContentData.Warnings.Select(w => new JsonValidationMessage(w)));
model.LicenseFileContents = packageContentData.LicenseFileContents;

Expand Down Expand Up @@ -1172,6 +1174,11 @@ public virtual ActionResult AtomFeed(string id, bool prerel = true)
[HttpGet]
public virtual async Task<ActionResult> License(string id, string version)
{
if (version == null)
{
return HttpNotFound();
}

var package = _packageService.FindPackageByIdAndVersionStrict(id, version);
if (package == null || package.PackageStatusKey == PackageStatus.Deleted)
{
Expand Down
14 changes: 8 additions & 6 deletions src/NuGetGallery/NuGetGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@
<Compile Include="Modules\CookieComplianceHttpModule.cs" />
<Compile Include="RequestModels\DeletePackagesApiRequest.cs" />
<Compile Include="RequestModels\UpdateListedRequest.cs" />
<Compile Include="Services\MissingLicenseValidationMessageV2.cs" />
<Compile Include="Services\UploadPackageMissingReadme.cs" />
<Compile Include="Services\MissingLicenseValidationMessage.cs" />
<Compile Include="Services\UploadPackageIdNamespaceConflict.cs" />
<Compile Include="Services\ImageDomainValidator.cs" />
Expand Down Expand Up @@ -635,6 +637,11 @@
<Compile Include="Services\TyposquattingStringNormalization.cs" />
<Compile Include="Services\UpdateDeprecationError.cs" />
<Compile Include="Services\ValidationService.cs" />
<Compile Include="Strings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
<Compile Include="Telemetry\ClientInformationTelemetryEnricher.cs" />
<Compile Include="Telemetry\ClientTelemetryPIIProcessor.cs" />
<Compile Include="Telemetry\CustomerResourceIdEnricher.cs" />
Expand Down Expand Up @@ -1483,11 +1490,6 @@
<Compile Include="Services\IFormsAuthenticationService.cs" />
<Compile Include="Services\IPackageFileService.cs" />
<Compile Include="RequestModels\DisplayPackageRequest.cs" />
<Compile Include="Strings.Designer.cs">
<DependentUpon>Strings.resx</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.*.cs" />
<Compile Include="RequestModels\SubmitPackageRequest.cs" />
Expand Down Expand Up @@ -2058,8 +2060,8 @@
</EmbeddedResource>
<EmbeddedResource Include="Strings.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/NuGetGallery/RequestModels/SubmitPackageRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public class SubmitPackageRequest
public bool IsUserLocked { get; set; }

public bool IsMarkdigMdSyntaxHighlightEnabled { get; set; }

public bool IsDisplayUploadWarningV2Enabled { get; set; }
}
}
1 change: 1 addition & 0 deletions src/NuGetGallery/RequestModels/VerifyPackageRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public VerifyPackageRequest(PackageMetadata packageMetadata, IEnumerable<User> p
public bool IsSymbolsPackage { get; set; }
public bool HasExistingAvailableSymbols { get; set; }
public bool IsMarkdigMdSyntaxHighlightEnabled { get; set; }
public bool IsDisplayUploadWarningV2Enabled { get; set; }

public List<JsonValidationMessage> Warnings { get; set; } = new List<JsonValidationMessage>();

Expand Down
5 changes: 5 additions & 0 deletions src/NuGetGallery/Scripts/gallery/async-file-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@
$("#verify-collapser-container").removeClass("hidden");
$("#submit-collapser-container").removeClass("hidden");

if (model != null && model.IsDisplayUploadWarningV2Enabled) {
$('#upload-package-form').collapse('hide');
$('#warning-container').addClass('hidden');
}

window.nuget.configureExpanderHeading("verify-package-section");
window.nuget.configureExpanderHeading("submit-package-form");
}
Expand Down
38 changes: 38 additions & 0 deletions src/NuGetGallery/Services/MissingLicenseValidationMessageV2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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;
using System.Globalization;
using System.Web;

namespace NuGetGallery
{
/// <summary>
/// A warning for packages that are missing licensing metadata.
/// </summary>
public class MissingLicenseValidationMessageV2 : IValidationMessage
{
private string DocumentationLink => $"<a href=\"https://aka.ms/nuget/authoring-best-practices#licensing\" aria-label=\"{Strings.UploadPackage_LearnMore_PackagingLicenseV2}\">{Strings.UploadPackage_LearnMore_PackagingLicenseV2}</a>.";

private readonly string _baseMessage;

public MissingLicenseValidationMessageV2(string basePlainTextMessage)
{
if (string.IsNullOrWhiteSpace(basePlainTextMessage))
{
throw new ArgumentException(
string.Format(CultureInfo.CurrentCulture, Strings.ParameterCannotBeNullOrEmpty, nameof(basePlainTextMessage)), nameof(basePlainTextMessage));
}

_baseMessage = basePlainTextMessage;
PlainTextMessage = $"{_baseMessage} {Strings.UploadPackage_LearnMore_PackagingLicenseV2}: https://aka.ms/nuget/authoring-best-practices#licensing.";
}

public string PlainTextMessage { get; }

public bool HasRawHtmlRepresentation => true;

public string RawHtmlMessage
=> Strings.UploadPackage_LicenseShouldBeSpecifiedHtmlV2 + " " + DocumentationLink;
}
}
18 changes: 15 additions & 3 deletions src/NuGetGallery/Services/PackageMetadataValidationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public async Task<PackageValidationResult> ValidateMetadataBeforeUploadAsync(
return result;
}

result = await CheckReadmeMetadataAsync(nuGetPackage, currentUser);
result = await CheckReadmeMetadataAsync(nuGetPackage, warnings, currentUser);
if (result != null)
{
return result;
Expand Down Expand Up @@ -211,7 +211,14 @@ private async Task<PackageValidationResult> CheckLicenseMetadataAsync(PackageArc
}
else
{
warnings.Add(new MissingLicenseValidationMessage(Strings.UploadPackage_LicenseShouldBeSpecified));
if (_featureFlagService.IsDisplayUploadWarningV2Enabled(user))
{
warnings.Add(new MissingLicenseValidationMessageV2(Strings.UploadPackage_LicenseShouldBeSpecifiedV2));
}
else
{
warnings.Add(new MissingLicenseValidationMessage(Strings.UploadPackage_LicenseShouldBeSpecified));
}
}
}

Expand Down Expand Up @@ -415,13 +422,18 @@ private async Task<PackageValidationResult> CheckIconMetadataAsync(PackageArchiv
return null;
}

private async Task<PackageValidationResult> CheckReadmeMetadataAsync(PackageArchiveReader nuGetPackage, User user)
private async Task<PackageValidationResult> CheckReadmeMetadataAsync(PackageArchiveReader nuGetPackage, List<IValidationMessage> warnings, User user)
{
var nuspecReader = GetNuspecReader(nuGetPackage);
var readmeElement = nuspecReader.ReadmeElement;

if (readmeElement == null)
{
if (_featureFlagService.IsDisplayUploadWarningV2Enabled(user))
{
warnings.Add(new UploadPackageMissingReadme());
}

return null;
}

Expand Down
12 changes: 12 additions & 0 deletions src/NuGetGallery/Services/UploadPackageMissingReadme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace NuGetGallery
{
/// <summary>
/// Represents a package ID reservation conflict
/// </summary>
public class UploadPackageMissingReadme : IValidationMessage
{
public bool HasRawHtmlRepresentation => true;
public string PlainTextMessage => Strings.UploadPackage_MissingReadme;
public string RawHtmlMessage => Strings.UploadPackage_MissingReadmeHtml;
}
}
Loading