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

Add fuget.org links to packages #8364

Merged
merged 2 commits into from
Jan 7, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class FeatureFlagService : IFeatureFlagService
private const string ManageDeprecationForManyVersionsFeatureName = GalleryPrefix + "ManageDeprecationMany";
private const string ManageDeprecationApiFeatureName = GalleryPrefix + "ManageDeprecationApi";
private const string DisplayVulnerabilitiesFeatureName = GalleryPrefix + "DisplayVulnerabilities";
private const string DisplayFuGetLinksFeatureName = GalleryPrefix + "DisplayFuGetLinks";
private const string ODataReadOnlyDatabaseFeatureName = GalleryPrefix + "ODataReadOnlyDatabase";
private const string PackagesAtomFeedFeatureName = GalleryPrefix + "PackagesAtomFeed";
private const string SearchSideBySideFlightName = GalleryPrefix + "SearchSideBySide";
Expand Down Expand Up @@ -133,6 +134,11 @@ public bool IsDisplayVulnerabilitiesEnabled()
return _client.IsEnabled(DisplayVulnerabilitiesFeatureName, defaultValue: false);
}

public bool IsDisplayFuGetLinksEnabled()
{
return _client.IsEnabled(DisplayFuGetLinksFeatureName, defaultValue: false);
}

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

/// <summary>
/// Whether or not a fuget.org link is visible on a package's details page.
/// </summary>
bool IsDisplayFuGetLinksEnabled();

/// <summary>
/// Whether the user is allowed to publish packages with an embedded icon.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/NuGetGallery/App_Data/Files/Content/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"NuGetGallery.ODataV2FindPackagesByIdCountNonHijacked": "Enabled",
"NuGetGallery.ODataV2SearchNonHijacked": "Enabled",
"NuGetGallery.ODataV2SearchCountNonHijacked": "Enabled",
"NuGetGallery.DisplayVulnerabilities": "Enabled"
"NuGetGallery.DisplayVulnerabilities": "Enabled",
"NuGetGallery.DisplayFuGetLinks": "Enabled"
},
"Flights": {
"NuGetGallery.TyposquattingFlight": {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/NuGetGallery/Content/gallery/img/fuget.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/NuGetGallery/Controllers/PackagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,7 @@ public virtual async Task<ActionResult> DisplayPackage(string id, string version
model.IsAtomFeedEnabled = _featureFlagService.IsPackagesAtomFeedEnabled();
model.IsPackageDeprecationEnabled = _featureFlagService.IsManageDeprecationEnabled(currentUser, allVersions);
model.IsPackageVulnerabilitiesEnabled = _featureFlagService.IsDisplayVulnerabilitiesEnabled();
model.IsFuGetLinksEnabled = _featureFlagService.IsDisplayFuGetLinksEnabled();
model.IsPackageRenamesEnabled = _featureFlagService.IsPackageRenamesEnabled(currentUser);
model.IsPackageDependentsEnabled = _featureFlagService.IsPackageDependentsEnabled(currentUser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ private DisplayPackageViewModel SetupCommon(
viewModel.ProjectUrl = projectUrl;
}

var fugetUrl = $"https://www.fuget.org/packages/{package.Id}/{package.NormalizedVersion}";
if (PackageHelper.TryPrepareUrlForRendering(fugetUrl, out string fugetReadyUrl))
{
viewModel.FuGetUrl = fugetReadyUrl;
}

viewModel.EmbeddedLicenseType = package.EmbeddedLicenseType;
viewModel.LicenseExpression = package.LicenseExpression;

Expand Down
2 changes: 2 additions & 0 deletions src/NuGetGallery/ViewModels/DisplayPackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class DisplayPackageViewModel : ListPackageItemViewModel
public bool IsAtomFeedEnabled { get; set; }
public bool IsPackageDeprecationEnabled { get; set; }
public bool IsPackageVulnerabilitiesEnabled { get; set; }
public bool IsFuGetLinksEnabled { get; set; }
joelverhagen marked this conversation as resolved.
Show resolved Hide resolved
public bool IsPackageRenamesEnabled { get; set; }
public bool IsGitHubUsageEnabled { get; set; }
public bool IsPackageDependentsEnabled { get; set; }
Expand Down Expand Up @@ -77,6 +78,7 @@ public bool HasNewerRelease
public RepositoryKind RepositoryType { get; private set; }
public string ProjectUrl { get; set; }
public string LicenseUrl { get; set; }
public string FuGetUrl { get; set; }
public IReadOnlyCollection<string> LicenseNames { get; set; }
public string LicenseExpression { get; set; }
public IReadOnlyCollection<CompositeLicenseExpressionSegment> LicenseExpressionSegments { get; set; }
Expand Down
19 changes: 18 additions & 1 deletion src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,24 @@
<a href="@Url.ViewValidations(Model)">View validations</a>
</li>
}
</ul>

@if (Model.IsFuGetLinksEnabled && !string.IsNullOrEmpty(Model.FuGetUrl))
{
var disclaimer = "fuget.org is a 3rd party website, not controlled by Microsoft. This link is made available to you per the NuGet Terms of Use.";

<li>
<img class="icon"
aria-label="@disclaimer" title="@disclaimer"
src="@Url.Absolute("~/Content/gallery/img/fuget.svg")"
@ViewHelpers.ImageFallback(Url.Absolute("~/Content/gallery/img/fuget-32x32.png")) />
<a href="@Model.FuGetUrl" data-track="outbound-repository-url"
aria-label="open in fuget.org explorer"
title="Explore additional package info on fuget.org" rel="nofollow" target="_blank">
Open in FuGet Package Explorer
</a>
</li>
}
</ul>
@if (Model.LicenseNames.AnySafe())
{
<p>License info provided by <a href="http://sonatype.com/">Sonatype</a>.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ public void ItInitializesProjectUrl(string projectUrl, string expected)
Assert.Equal(expected, model.ProjectUrl);
}

[Theory]
[InlineData("foo", "1.0.0", "https://www.fuget.org/packages/foo/1.0.0")]
[InlineData("foo", "1.1.0", "https://www.fuget.org/packages/foo/1.1.0")]
[InlineData("Foo.Bar", "1.1.0-bETa", "https://www.fuget.org/packages/Foo.Bar/1.1.0-bETa")]
public void ItInitializesFuGetUrl(string packageId, string packageVersion, string expected)
{
var package = new Package
{
Version = packageVersion,
NormalizedVersion = packageVersion,
PackageRegistration = new PackageRegistration
{
Id = packageId,
Owners = Enumerable.Empty<User>().ToList(),
Packages = Enumerable.Empty<Package>().ToList()
}
};

var model = CreateDisplayPackageViewModel(package, currentUser: null, packageKeyToDeprecation: null, readmeHtml: null);
Assert.Equal(expected, model.FuGetUrl);
}

[Theory]
[InlineData(null, null)]
Expand Down