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

[Feature]: DNDocs #10055 #10056

Closed
wants to merge 1 commit into from
Closed
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 @@ -71,6 +71,11 @@ public bool IsDisplayFuGetLinksEnabled()
throw new NotImplementedException();
}

public bool IsDisplayDNDocsLinksEnabled()
{
throw new NotImplementedException();
}

public bool IsDisplayNuGetPackageExplorerLinkEnabled()
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public bool IsDisplayFuGetLinksEnabled()
throw new NotImplementedException();
}

public bool IsDisplayDNDocsLinksEnabled()
{
throw new NotImplementedException();
}

public bool IsDisplayNuGetTrendsLinksEnabled()
{
throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class FeatureFlagService : IFeatureFlagService
private const string DisplayVulnerabilitiesFeatureName = GalleryPrefix + "DisplayVulnerabilities";
private const string ManagePackagesVulnerabilitiesFeatureName = GalleryPrefix + "ManagePackagesVulnerabilities";
private const string DisplayFuGetLinksFeatureName = GalleryPrefix + "DisplayFuGetLinks";
private const string DisplayDNDocsLinksFeatureName = GalleryPrefix + "DisplayDNDocsLinks";
private const string DisplayNuGetPackageExplorerLinkFeatureName = GalleryPrefix + "DisplayNuGetPackageExplorerLink";
private const string DisplayNuGetTrendsLinkFeatureName = GalleryPrefix + "DisplayNuGetTrendsLink";
private const string ODataReadOnlyDatabaseFeatureName = GalleryPrefix + "ODataReadOnlyDatabase";
Expand Down Expand Up @@ -168,6 +169,11 @@ public bool IsDisplayFuGetLinksEnabled()
return _client.IsEnabled(DisplayFuGetLinksFeatureName, defaultValue: false);
}

public bool IsDisplayDNDocsLinksEnabled()
{
return _client.IsEnabled(DisplayDNDocsLinksFeatureName, defaultValue: false);
}

public bool IsDisplayNuGetPackageExplorerLinkEnabled()
{
return _client.IsEnabled(DisplayNuGetPackageExplorerLinkFeatureName, defaultValue: false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public interface IFeatureFlagService
/// </summary>
bool IsDisplayFuGetLinksEnabled();

/// <summary>
/// Whether or not a dndocs.com link is visible on a package's details page.
/// </summary>
bool IsDisplayDNDocsLinksEnabled();

/// <summary>
/// Whether or not a nugettrends.com link is visible on a package's details page.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/NuGetGallery/App_Data/Files/Content/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"NuGetGallery.DisplayVulnerabilities": "Enabled",
"NuGetGallery.ManagePackagesVulnerabilities": "Enabled",
"NuGetGallery.DisplayFuGetLinks": "Enabled",
"NuGetGallery.DisplayDNDocsLinks": "Enabled",
"NuGetGallery.DisplayNuGetPackageExplorerLink": "Enabled",
"NuGetGallery.DisplayNuGetTrendsLink": "Enabled",
"NuGetGallery.PatternSetTfmHeuristics": "Enabled",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/NuGetGallery/Content/gallery/img/dndocs.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 @@ -981,6 +981,7 @@ public virtual async Task<ActionResult> DisplayPackage(string id, string version
model.IsPackageDeprecationEnabled = isPackageDeprecationEnabled;
model.IsPackageVulnerabilitiesEnabled = isPackageVulnerabilitiesEnabled;
model.IsFuGetLinksEnabled = _featureFlagService.IsDisplayFuGetLinksEnabled();
model.IsDNDocsLinksEnabled = _featureFlagService.IsDisplayDNDocsLinksEnabled();
model.IsNuGetPackageExplorerLinkEnabled = _featureFlagService.IsDisplayNuGetPackageExplorerLinkEnabled();
model.IsNuGetTrendsLinksEnabled = _featureFlagService.IsDisplayNuGetTrendsLinksEnabled();
model.IsPackageRenamesEnabled = _featureFlagService.IsPackageRenamesEnabled(currentUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ private DisplayPackageViewModel SetupCommon(
viewModel.FuGetUrl = fugetReadyUrl;
}

var dndocsUrl = $"https://dndocs.com/i/nuget/{package.Id}/{package.NormalizedVersion}";
if (PackageHelper.TryPrepareUrlForRendering(dndocsUrl, out string dndocsReadyUrl))
{
viewModel.DNDocsUrl = dndocsReadyUrl;
}

var nugetPackageExplorerUrl = $"https://nuget.info/packages/{package.Id}/{package.NormalizedVersion}";
if (PackageHelper.TryPrepareUrlForRendering(nugetPackageExplorerUrl, out string nugetPackageExplorerReadyUrl))
{
Expand Down
4 changes: 3 additions & 1 deletion src/NuGetGallery/NuGetGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,8 @@
<Content Include="Areas\Admin\DynamicData\PageTemplates\ListDetails.aspx" />
<Content Include="Content\admin\SupportRequestStyles.css" />
<Content Include="Content\fabric.css" />
<Content Include="Content\gallery\img\dndocs-32x32.png" />
<Content Include="Content\gallery\img\dndocs.svg" />
<Content Include="Content\gallery\img\logo-og-600x600.png" />
<Content Include="Content\gallery\img\rss-24x24.png" />
<Content Include="Content\Images\icons\apiKey.png" />
Expand Down Expand Up @@ -2400,4 +2402,4 @@
copy "$(ProjectDir)..\Bootstrap\dist\js\bootstrap.js" "$(ProjectDir)Scripts\gallery" &gt;NUL
</PreBuildEvent>
</PropertyGroup>
</Project>
</Project>
7 changes: 7 additions & 0 deletions src/NuGetGallery/ViewModels/DisplayPackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class DisplayPackageViewModel : ListPackageItemViewModel
public bool IsPackageDeprecationEnabled { get; set; }
public bool IsPackageVulnerabilitiesEnabled { get; set; }
public bool IsFuGetLinksEnabled { get; set; }
public bool IsDNDocsLinksEnabled { get; set; }
public bool IsNuGetTrendsLinksEnabled { get; set; }
public bool IsNuGetPackageExplorerLinkEnabled { get; set; }
public bool IsPackageRenamesEnabled { get; set; }
Expand Down Expand Up @@ -89,6 +90,7 @@ public bool HasNewerRelease
public string ProjectUrl { get; set; }
public string LicenseUrl { get; set; }
public string FuGetUrl { get; set; }
public string DNDocsUrl { get; internal set; }
public string NuGetTrendsUrl { get; set; }
public string NuGetPackageExplorerUrl { get; set; }
public IReadOnlyCollection<string> LicenseNames { get; set; }
Expand Down Expand Up @@ -148,6 +150,11 @@ public bool CanDisplayFuGetLink()
return IsFuGetLinksEnabled && !string.IsNullOrEmpty(FuGetUrl) && Available;
}

public bool CanDisplayDNDocsLink()
{
return IsDNDocsLinksEnabled && !string.IsNullOrEmpty(DNDocsUrl) && Available;
}

public bool CanDisplayNuGetTrendsLink()
{
return IsNuGetTrendsLinksEnabled && !string.IsNullOrEmpty(NuGetTrendsUrl) && Available;
Expand Down
33 changes: 25 additions & 8 deletions src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@
else
{
<a href="@Model.LicenseUrl"
data-track="outbound-license-url" title="Make sure you agree with the license" rel="nofollow">
data-track="outbound-license-url" title="Make sure you agree with the license" rel="nofollow">
License Info
</a>
}
Expand Down Expand Up @@ -1134,8 +1134,8 @@
<li>
<i class="ms-Icon ms-Icon--FabricFolderSearch" aria-hidden="true" aria-label="@disclaimer" title="@disclaimer"></i>
<a href="@Model.NuGetPackageExplorerUrl" data-track="outbound-nugetpackageexplorer-url"
aria-label="open in NuGet Package Explorer"
title="Explore additional package info on NuGet Package Explorer" target="_blank" rel="nofollow noreferrer">
aria-label="open in NuGet Package Explorer"
title="Explore additional package info on NuGet Package Explorer" target="_blank" rel="nofollow noreferrer">
Open in NuGet Package Explorer
</a>
</li>
Expand All @@ -1147,17 +1147,34 @@

<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")) />
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-fuget-url"
aria-label="open in fuget.org explorer"
title="Explore additional package info on fuget.org" target="_blank" rel="nofollow noreferrer">
aria-label="open in fuget.org explorer"
title="Explore additional package info on fuget.org" target="_blank" rel="nofollow noreferrer">
Open in FuGet Package Explorer
</a>
</li>
}

@if (Model.CanDisplayDNDocsLink() && Model.ShowDetailsAndLinks)
{
var disclaimer = "dndocs.com 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/dndocs.svg")"
@ViewHelpers.ImageFallback(Url.Absolute("~/Content/gallery/img/dndocs-32x32.png")) />
<a href="@Model.DNDocsUrl" data-track="outbound-dndocs-url"
aria-label="open in dndocs.com explorer"
title="Explore API on dndocs.com" target="_blank" rel="nofollow noreferrer">
Open in DNDocs API Explorer
</a>
</li>
}

@if (Model.CanDisplayNuGetTrendsLink() && Model.ShowDetailsAndLinks)
{
var disclaimer = "nugettrends.com is a 3rd party website, not controlled by Microsoft. This link is made available to you per the NuGet Terms of Use.";
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
-->
<system.web>
<httpCookies requireSSL="true" httpOnlyCookies="true"/>
<compilation debug="false" targetFramework="4.7.2">
<compilation debug="true" targetFramework="4.7.2">
<assemblies>
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
</assemblies>
Expand Down
2 changes: 2 additions & 0 deletions src/VerifyMicrosoftPackage/Fakes/FakeFeatureFlagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class FakeFeatureFlagService : IFeatureFlagService
public bool IsManagePackagesVulnerabilitiesEnabled() => throw new NotImplementedException();

public bool IsDisplayFuGetLinksEnabled() => throw new NotImplementedException();

public bool IsDisplayDNDocsLinksEnabled() => throw new NotImplementedException();

public bool AreEmbeddedIconsEnabled(User user) => throw new NotImplementedException();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,57 @@ public void CannotDisplayFuGetLinkWhenInvalid(bool isEnabled, string url, bool i
Assert.False(model.CanDisplayFuGetLink());
}

[Theory]
[InlineData("foo", "1.0.0", "https://dndocs.com/i/nuget/foo/1.0.0")]
[InlineData("foo", "1.1.0", "https://dndocs.com/i/nuget/foo/1.1.0")]
[InlineData("Foo.Bar", "1.1.0-bETa", "https://dndocs.com/i/nuget/Foo.Bar/1.1.0-bETa")]
public void ItInitializesDNDocsUrl(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.DNDocsUrl);
}


[Theory]
[InlineData(false, "https://dndocs.com/i/nuget/foo/1.0.0", true)]
[InlineData(true, "", true)]
[InlineData(true, null, true)]
[InlineData(true, "https://dndocs.com/i/nuget/foo/1.0.0", false)]
public void CannotDisplayDNDocsLinkWhenInvalid(bool isEnabled, string url, bool isAvailable)
{
var package = new Package
{
Version = "1.0.0",
NormalizedVersion = "1.0.0",
PackageRegistration = new PackageRegistration
{
Id = "foo",
Owners = Enumerable.Empty<User>().ToList(),
Packages = Enumerable.Empty<Package>().ToList()
}
};

var model = CreateDisplayPackageViewModel(package, currentUser: null, packageKeyToDeprecation: null, readmeHtml: null);

model.IsDNDocsLinksEnabled = isEnabled;
model.DNDocsUrl = url;
model.Available = isAvailable;

Assert.False(model.CanDisplayDNDocsLink());
}

[Fact]
public void ItInitializesNuGetTrendsUrl()
{
Expand Down