Skip to content

Commit 9dd5b06

Browse files
authored
Polish upload UI for license html file (#8735)
* polish upload for license html file
1 parent a1e448b commit 9dd5b06

12 files changed

Lines changed: 115 additions & 15 deletions

File tree

src/Bootstrap/dist/css/bootstrap-theme.css

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

src/Bootstrap/less/theme/common-licenses.less

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
word-break: normal;
55
}
66

7-
.custom-license-container {
7+
.custom-license-container, .license-file-html-container{
8+
display: block;
9+
padding: 10.5px;
10+
background-color: @pre-bg;
11+
border: 1px solid #ccc;
12+
word-break: normal;
813
margin-bottom: @default-margin-bottom;
14+
overflow: auto;
15+
max-height: 450px;
916
}
1017
}

src/NuGetGallery/App_Code/ViewHelpers.cshtml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@
8181
)
8282
}
8383

84+
@helper AlertImageSourceDisallowed()
85+
{
86+
@AlertWarning(
87+
@<text>
88+
Some images are not displayed as they are not from <a href='https://aka.ms/nuget-org-readme#allowed-domains-for-images-and-badges'>trusted domains</a>.
89+
</text>
90+
)
91+
}
92+
93+
@helper AlertImagesRewritten()
94+
{
95+
@AlertWarning(
96+
@<text>
97+
This documentation had some images automatically rewritten to use secure links and may be broken.
98+
</text>)
99+
}
100+
84101
@helper ErrorPage(UrlHelper url, System.Web.Mvc.HtmlHelper html, string errorNumber, string errorName, Func<MvcHtmlString, HelperResult> errorTextMain, Func<MvcHtmlString, HelperResult> errorTextSub = null)
85102
{
86103
<section role="main" class="container main-container">

src/NuGetGallery/Controllers/PackagesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ private async Task<JsonResult> GetVerifyPackageView(User currentUser,
658658
packageMetadata.LicenseMetadata?.Type == LicenseType.File &&
659659
Path.GetExtension(license).Equals(ServicesConstants.MarkdownFileExtension, StringComparison.InvariantCulture))
660660
{
661-
model.LicenseFileContentsHtml = _markdownService.GetHtmlFromMarkdown(packageContentData.LicenseFileContents, incrementHeadersBy: 2)?.Content;
661+
model.LicenseFileContentsHtml = _markdownService.GetHtmlFromMarkdown(packageContentData.LicenseFileContents, incrementHeadersBy: 2);
662662
}
663663

664664
model.LicenseExpressionSegments = packageContentData.LicenseExpressionSegments;

src/NuGetGallery/Helpers/ViewModelExtensions/DisplayLicenseViewModelFactory.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ private DisplayLicenseViewModel SetupInternal(
4949
string licenseFileContents,
5050
User currentUser)
5151
{
52+
viewModel.CanDisplayPrivateMetadata = CanPerformAction(currentUser, package, ActionsRequiringPermissions.DisplayPrivatePackageMetadata);
5253
viewModel.EmbeddedLicenseType = package.EmbeddedLicenseType;
5354
viewModel.LicenseExpression = package.LicenseExpression;
5455
if (PackageHelper.TryPrepareUrlForRendering(package.LicenseUrl, out string licenseUrl))
@@ -68,10 +69,15 @@ private DisplayLicenseViewModel SetupInternal(
6869
package.EmbeddedLicenseType == EmbeddedLicenseFileType.Markdown &&
6970
licenseFileContents != null)
7071
{
71-
viewModel.LicenseFileContentsHtml = _markdownService.GetHtmlFromMarkdown(licenseFileContents)?.Content;
72+
viewModel.LicenseFileContentsHtml = _markdownService.GetHtmlFromMarkdown(licenseFileContents);
7273
}
7374

7475
return viewModel;
7576
}
77+
78+
private static bool CanPerformAction(User currentUser, Package package, ActionRequiringPackagePermissions action)
79+
{
80+
return action.CheckPermissionsOnBehalfOfAnyAccount(currentUser, package) == PermissionsCheckResult.Allowed;
81+
}
7682
}
7783
}

src/NuGetGallery/RequestModels/VerifyPackageRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public VerifyPackageRequest(PackageMetadata packageMetadata, IEnumerable<User> p
105105
public string LicenseExpression { get; set; }
106106
public IReadOnlyCollection<CompositeLicenseExpressionSegmentViewModel> LicenseExpressionSegments { get; set; }
107107
public string LicenseFileContents { get; set; }
108-
public string LicenseFileContentsHtml { get; set; }
108+
public RenderedMarkdownResult LicenseFileContentsHtml { get; set; }
109109
public string MinClientVersionDisplay { get; set; }
110110
public string ProjectUrl { get; set; }
111111
public string RepositoryUrl { get; set; }

src/NuGetGallery/ViewModels/DisplayLicenseViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class DisplayLicenseViewModel : PackageViewModel
1515
public IReadOnlyCollection<string> LicenseNames { get; set; }
1616
public IReadOnlyCollection<CompositeLicenseExpressionSegment> LicenseExpressionSegments { get; set; }
1717
public string LicenseFileContents { get; set; }
18-
public string LicenseFileContentsHtml { get; set; }
18+
public RenderedMarkdownResult LicenseFileContentsHtml { get; set; }
19+
public bool CanDisplayPrivateMetadata { get; set; }
1920
}
2021
}

src/NuGetGallery/Views/Packages/DisplayPackage.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,12 @@
522522
<div id="readme-container" class="collapse in">
523523
@if (Model.ReadMeImagesRewritten && Model.CanDisplayPrivateMetadata)
524524
{
525-
@ViewHelpers.AlertWarning(@<text>This documentation had some images automatically rewritten to use secure links and may be broken.</text>);
525+
@ViewHelpers.AlertImagesRewritten();
526526
}
527527

528528
@if (Model.ReadmeImageSourceDisallowed && Model.CanDisplayPrivateMetadata)
529529
{
530-
@ViewHelpers.AlertWarning(@<text>Some images are not displayed as they are not from <a href='https://aka.ms/nuget-org-readme#allowed-domains-for-images-and-badges'>trusted domains</a>.</text>);
530+
@ViewHelpers.AlertImageSourceDisallowed();
531531
}
532532
<div id="readme-less" class="collapse in">
533533
@Html.Raw(Model.ReadMeHtml)

src/NuGetGallery/Views/Packages/DisplayPackageV2.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,12 +561,12 @@
561561
<div id="readme-container">
562562
@if (Model.ReadMeImagesRewritten && Model.CanDisplayPrivateMetadata)
563563
{
564-
@ViewHelpers.AlertWarning(@<text>This documentation had some images automatically rewritten to use secure links and may be broken.</text>);
564+
@ViewHelpers.AlertImagesRewritten();
565565
}
566566

567567
@if (Model.ReadmeImageSourceDisallowed && Model.CanDisplayPrivateMetadata)
568568
{
569-
@ViewHelpers.AlertWarning(@<text>Some images are not displayed as they are not from <a href='https://aka.ms/nuget-org-readme#allowed-domains-for-images-and-badges'>trusted domains</a>.</text>);
569+
@ViewHelpers.AlertImageSourceDisallowed();
570570
}
571571

572572
@Html.Raw(Model.ReadMeHtml)

src/NuGetGallery/Views/Packages/License.cshtml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,22 @@
6464
}
6565
else
6666
{
67-
<label>License text</label>
67+
<label>License file</label>
6868
<div class="common-licenses">
6969
@if (Model.LicenseFileContentsHtml != null)
7070
{
71-
@Html.Raw(Model.LicenseFileContentsHtml)
72-
}
73-
else
71+
if (Model.LicenseFileContentsHtml.ImageSourceDisallowed && Model.CanDisplayPrivateMetadata)
72+
{
73+
@ViewHelpers.AlertImageSourceDisallowed();
74+
}
75+
76+
if (Model.LicenseFileContentsHtml.ImagesRewritten && Model.CanDisplayPrivateMetadata)
77+
{
78+
@ViewHelpers.AlertImagesRewritten();
79+
}
80+
@Html.Raw(Model.LicenseFileContentsHtml.Content)
81+
}
82+
else
7483
{
7584
<pre class="license-file-contents custom-license-container">@Model.LicenseFileContents</pre>
7685
}

0 commit comments

Comments
 (0)