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][2024.01.09]RI of dev into main for NuGetGallery #9774

Merged
merged 4 commits into from
Jan 18, 2024
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
8 changes: 7 additions & 1 deletion src/AccountDeleter/EmptyFeatureFlagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,13 @@ public bool IsDisplayPackageReadmeWarningEnabled(User user)
throw new NotImplementedException();
}

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

public bool IsDisplayTfmBadgesEnabled(User user)
{
throw new NotImplementedException();
}
}
Expand Down
36 changes: 30 additions & 6 deletions src/Bootstrap/dist/css/bootstrap-theme.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/Bootstrap/dist/css/bootstrap.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Bootstrap/dist/js/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Bootstrap v3.4.1 (https://getbootstrap.com/)
* Copyright 2011-2023 Twitter, Inc.
* Copyright 2011-2024 Twitter, Inc.
* Licensed under the MIT license
*/

Expand Down
33 changes: 33 additions & 0 deletions src/Bootstrap/less/theme/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,39 @@ img.reserved-indicator-icon {
}
}

li.package-warning-indicators {
display: block;
overflow-y: visible;
margin-bottom: 5px;
font-size: 14px;
}

li.package-tfm-badges {
display: block;
overflow-y: visible;

.framework-badges {
margin-bottom: 2px;

span {
margin-right: 1px;
}

.framework-badge-computed {
color: #000;
border: 1px solid rgba(0,0,0,.15);
}

@media (max-width: @screen-sm-min) {
a + a {
span {
margin-bottom: 4px;
}
}
}
}
}

@media (min-width: @screen-sm-min) {
li {
display: inline-block;
Expand Down
7 changes: 4 additions & 3 deletions src/Bootstrap/less/theme/common-list-packages.less
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@
@badge-border-radius: 2px;

.package-warning {
padding-right: 8px;
padding-left: 8px;
padding: 1px 8px;
border-radius: @badge-border-radius;
margin-right: 5px;
color: @package-warning-color
color: @package-warning-color;
}

.package-warning--vulnerable {
.package-warning;
background-color: @severe-warning-background-color;
border: 1px solid darken(@severe-warning-background-color, 15%);
i {
color: @severe-warning-icon-color;
}
Expand All @@ -100,4 +100,5 @@
.package-warning--deprecated {
.package-warning;
background-color: @warning-background-color;
border: 1px solid darken(@warning-background-color, 35%);
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,13 @@ public bool IsNuGetAccountPasswordLoginEnabled()
throw new NotImplementedException();
}

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

public bool IsDisplayTfmBadgesEnabled(User user)
{
throw new NotImplementedException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace NuGetGallery.Frameworks
{
public interface IPackageFrameworkCompatibilityFactory
{
PackageFrameworkCompatibility Create(ICollection<PackageFramework> packageFrameworks);
PackageFrameworkCompatibility Create(ICollection<PackageFramework> packageFrameworks, string packageId, bool includeComputedBadges = false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public class PackageFrameworkCompatibility
/// Key: Is the <see cref="FrameworkProductNames"/> if resolved on (<seealso cref="PackageFrameworkCompatibilityFactory.ResolveFrameworkProductName(NuGetFramework)"/>) or the <see cref="NuGetFramework.Framework"/>.<br></br>
/// Value: Is an ordered collection containing all the compatible frameworks.
/// </remarks>
public IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityTableData>> Table { get; set; }
public IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityData>> Table { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ namespace NuGetGallery.Frameworks
/// </summary>
/// <remarks>
/// All these properties are retrieved from the <see cref="PackageFrameworkCompatibility.Table"/>, one for each .NET product.<br></br>
/// Only package asset frameworks are considered. i.e. <see cref="PackageFrameworkCompatibilityTableData.IsComputed"/> <c>= false</c>.<br></br>
/// Only package asset frameworks are considered. i.e. <see cref="PackageFrameworkCompatibilityData.IsComputed"/> <c>= false</c>.<br></br>
/// If there are no package asset frameworks for a particular .NET product, then the value will be <c>null</c>.
/// </remarks>
public class PackageFrameworkCompatibilityBadges
{
public NuGetFramework Net { get; set; }
public NuGetFramework NetCore { get; set; }
public NuGetFramework NetStandard { get; set; }
public NuGetFramework NetFramework { get; set; }
public string PackageId { get; set; }
public PackageFrameworkCompatibilityData Net { get; set; }
public PackageFrameworkCompatibilityData NetCore { get; set; }
public PackageFrameworkCompatibilityData NetStandard { get; set; }
public PackageFrameworkCompatibilityData NetFramework { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace NuGetGallery.Frameworks
{
public class PackageFrameworkCompatibilityTableData
public class PackageFrameworkCompatibilityData
{
/// <summary>
/// Compatible framework.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PackageFrameworkCompatibilityFactory : IPackageFrameworkCompatibili
private readonly NuGetFrameworkSorter Sorter = new NuGetFrameworkSorter();
private readonly int NetStartingMajorVersion = 5;

public PackageFrameworkCompatibility Create(ICollection<PackageFramework> packageFrameworks)
public PackageFrameworkCompatibility Create(ICollection<PackageFramework> packageFrameworks, string packageId, bool includeComputedBadges = false)
{
if (packageFrameworks == null)
{
Expand All @@ -35,7 +35,7 @@ public PackageFrameworkCompatibility Create(ICollection<PackageFramework> packag
.ToHashSet();

var table = CreateFrameworkCompatibilityTable(filteredPackageFrameworks);
var badges = CreateFrameworkCompatibilityBadges(table);
var badges = CreateFrameworkCompatibilityBadges(table, packageId, includeComputedBadges);

return new PackageFrameworkCompatibility
{
Expand All @@ -44,16 +44,16 @@ public PackageFrameworkCompatibility Create(ICollection<PackageFramework> packag
};
}

private IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityTableData>> CreateFrameworkCompatibilityTable(ICollection<NuGetFramework> filteredPackageFrameworks)
private IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityData>> CreateFrameworkCompatibilityTable(ICollection<NuGetFramework> filteredPackageFrameworks)
{
var compatibleFrameworks = FrameworkCompatibilityService.GetCompatibleFrameworks(filteredPackageFrameworks);

var table = new Dictionary<string, SortedSet<PackageFrameworkCompatibilityTableData>>();
var table = new Dictionary<string, SortedSet<PackageFrameworkCompatibilityData>>();

foreach (var compatibleFramework in compatibleFrameworks)
{
var productName = ResolveFrameworkProductName(compatibleFramework);
var data = new PackageFrameworkCompatibilityTableData
var data = new PackageFrameworkCompatibilityData
{
Framework = compatibleFramework,
IsComputed = !filteredPackageFrameworks.Contains(compatibleFramework)
Expand All @@ -65,8 +65,8 @@ private IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatib
}
else
{
var newCompatibleFrameworks = new SortedSet<PackageFrameworkCompatibilityTableData>
(Comparer<PackageFrameworkCompatibilityTableData>.Create((a, b) => Sorter.Compare(a.Framework, b.Framework)));
var newCompatibleFrameworks = new SortedSet<PackageFrameworkCompatibilityData>
(Comparer<PackageFrameworkCompatibilityData>.Create((a, b) => Sorter.Compare(a.Framework, b.Framework)));

newCompatibleFrameworks.Add(data);
table.Add(productName, newCompatibleFrameworks);
Expand Down Expand Up @@ -118,9 +118,9 @@ private string ResolveFrameworkProductName(NuGetFramework framework)
return framework.Framework;
}

private IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityTableData>> OrderDictionaryKeys(Dictionary<string, SortedSet<PackageFrameworkCompatibilityTableData>> table)
private IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityData>> OrderDictionaryKeys(Dictionary<string, SortedSet<PackageFrameworkCompatibilityData>> table)
{
var orderedTable = new Dictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityTableData>>();
var orderedTable = new Dictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityData>>();

AddOrderedKey(table, orderedTable, FrameworkProductNames.Net);
AddOrderedKey(table, orderedTable, FrameworkProductNames.NetCore);
Expand All @@ -139,38 +139,38 @@ private IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatib
return orderedTable;
}

private void AddOrderedKey(Dictionary<string, SortedSet<PackageFrameworkCompatibilityTableData>> table, Dictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityTableData>> orderedTable, string framework)
private void AddOrderedKey(Dictionary<string, SortedSet<PackageFrameworkCompatibilityData>> table, Dictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityData>> orderedTable, string framework)
{
if (table.TryGetValue(framework, out var compatibleFrameworks))
{
orderedTable.Add(framework, compatibleFrameworks);
}
}

private PackageFrameworkCompatibilityBadges CreateFrameworkCompatibilityBadges(IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityTableData>> table)
private PackageFrameworkCompatibilityBadges CreateFrameworkCompatibilityBadges(IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityData>> table, string packageId, bool includeComputed = false)
{
var net = GetBadgeFramework(table, FrameworkProductNames.Net);
var netCore = GetBadgeFramework(table, FrameworkProductNames.NetCore);
var netStandard = GetBadgeFramework(table, FrameworkProductNames.NetStandard);
var netFramework = GetBadgeFramework(table, FrameworkProductNames.NetFramework);
var net = GetBadgeFramework(table, FrameworkProductNames.Net, includeComputed);
var netCore = GetBadgeFramework(table, FrameworkProductNames.NetCore, includeComputed);
var netStandard = GetBadgeFramework(table, FrameworkProductNames.NetStandard, includeComputed);
var netFramework = GetBadgeFramework(table, FrameworkProductNames.NetFramework, includeComputed);

return new PackageFrameworkCompatibilityBadges
{
PackageId = packageId,
Net = net,
NetCore = netCore,
NetStandard = netStandard,
NetFramework = netFramework
};
}

private NuGetFramework GetBadgeFramework(IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityTableData>> table, string productName)
private PackageFrameworkCompatibilityData GetBadgeFramework(IReadOnlyDictionary<string, IReadOnlyCollection<PackageFrameworkCompatibilityData>> table, string productName, bool includeComputed = false)
{
if (table.TryGetValue(productName, out var data))
{
return data
.Where(d => !d.IsComputed)
.Select(d => d.Framework)
.FirstOrDefault();
.Where(d => includeComputed || !d.IsComputed)
.FirstOrDefault();
}

return null;
Expand Down
19 changes: 19 additions & 0 deletions src/NuGetGallery.Core/Services/ITyposquattingServiceHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.

namespace NuGetGallery
{
/// <summary>
/// This interface for providing additional methods for ITyposquattingService.
/// </summary>
public interface ITyposquattingServiceHelper
{
/// <summary>
/// This method is used to check if the distance between the currently uploaded package ID and another package ID is less than or equal to the threshold.
/// </summary>
/// <param name="uploadedPackageId">Uploaded package Id</param>
/// <param name="packageId">Package Id compared to</param>
/// <returns>Return true if distance is less than the threshold</returns>
bool IsDistanceLessThanOrEqualToThreshold(string uploadedPackageId, string packageId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class FeatureFlagService : IFeatureFlagService
private const string NewAccount2FAEnforcementFeatureName = GalleryPrefix + "NewAccount2FAEnforcement";
private const string NuGetAccountPasswordLoginFeatureName = GalleryPrefix + "NuGetAccountPasswordLogin";
private const string FrameworkFilteringFeatureName = GalleryPrefix + "FrameworkFiltering";
private const string DisplayTfmBadgesFeatureName = GalleryPrefix + "DisplayTfmBadges";

private const string ODataV1GetAllNonHijackedFeatureName = GalleryPrefix + "ODataV1GetAllNonHijacked";
private const string ODataV1GetAllCountNonHijackedFeatureName = GalleryPrefix + "ODataV1GetAllCountNonHijacked";
Expand Down Expand Up @@ -403,5 +404,10 @@ public bool IsNuGetAccountPasswordLoginEnabled()
public bool IsFrameworkFilteringEnabled(User user) {
return _client.IsEnabled(FrameworkFilteringFeatureName, user, defaultValue: false);
}

public bool IsDisplayTfmBadgesEnabled(User user)
{
return _client.IsEnabled(DisplayTfmBadgesFeatureName, user, defaultValue: false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,5 +327,10 @@ public interface IFeatureFlagService
/// Whether or not to allow filtering by frameworks on NuGet.org search
/// </summary>
bool IsFrameworkFilteringEnabled(User user);

/// <summary>
/// Whether or not to display TFM badges in search results
/// </summary>
bool IsDisplayTfmBadgesEnabled(User user);
}
}
Loading