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 vulnerability messaging to package details page #8358

Merged
merged 3 commits into from
Jan 8, 2021

Conversation

drewgillies
Copy link
Contributor

@drewgillies drewgillies commented Dec 17, 2020

Completes: #7650

Here we change the view to include a vulnerabilities panel for an affected package version.

Non-owner view, not expanded:
image

Owner view, expanded:
image

  • bangs and tooltips in the version list (combined for deprecations and vulnerabilities). Again, formats and icons may be tweaked going forward.

Vulnerability only:
image

Vulnerability + deprecation:
image

@drewgillies drewgillies changed the title Dg vulnerabilitymessaging Add vulnerability messaging to package details page Dec 17, 2020
@drewgillies drewgillies force-pushed the dg-vulnerabilitymessaging branch 2 times, most recently from 7d3afb4 to 22e3b63 Compare December 17, 2020 08:02
useAlso = true;
}

if (Model.IsPackageVulnerabilitiesEnabled && packageVersion.Vulnerabilities != null && packageVersion.Vulnerabilities.Any())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packageVersion.Vulnerabilities != null && packageVersion.Vulnerabilities.Any() [](start = 85, length = 78)

This condition is repeated a couple of times. Can we move it to a shared location?

{
vulnerabilitiesTitle = useAlso ? "Also, " : "";
var severity = Enum.GetName(typeof(PackageVulnerabilitySeverity), packageVersion.MaxVulnerabilitySeverity).ToLowerInvariant();
vulnerabilitiesTitle += packageVersion.Version + " has at least one vulnerability with " + severity + " severity.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packageVersion.Version + " has at least one vulnerability with " + severity + " severity."; [](start = 68, length = 91)

consider string.Format for readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done--thanks. I wanted to do an interpolated string, but we're targeting a .NET version that doesn't support them in razor. string.Format is 👍 though.

@@ -753,15 +772,16 @@
</td>
}
}
@if (Model.IsPackageDeprecationEnabled)

@if (Model.IsPackageDeprecationEnabled || Model.IsPackageVulnerabilitiesEnabled)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bunch of logic here and it's not testable because it's in the cshtml. Consider moving it to the ViewModel so you can add UTs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've taken a simpler approach here and called the column "Package Warnings"--I don't think we need to customize a hidden column header based on feature flags.

Copy link
Contributor

@zhhyu zhhyu Dec 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, we have a code block here to obtain "iconTitle", and set up a warning icon with the associated title based on some checks. Maybe it's better that we add another property named "warningIconTitle" (and with another additional boolean property named "hasWarningIcon") in the view model, and when we create the view model in the factory, we can run these checks and set up this property. Then in the view, we can easily check this property to determine whether to show the icon and title for a specific version.
In this way, we can move the logic of this code block to the factory, and some tests can be added to cover these checks and messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call--this is much more robust now.

@drewgillies drewgillies force-pushed the dg-vulnerabilityservice-and-featureflags branch from ec2c439 to d0c7212 Compare December 17, 2020 20:39
Base automatically changed from dg-vulnerabilityservice-and-featureflags to dev December 17, 2020 20:51
@drewgillies drewgillies force-pushed the dg-vulnerabilitymessaging branch 9 times, most recently from d31453f to 5be36a5 Compare December 21, 2020 05:20
{
<th aria-hidden="true" abbr="Deprecation Information"></th>
<th aria-hidden="true" abbr ="Package Warnings" />
Copy link
Contributor

@zhhyu zhhyu Dec 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still keep </th> here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made this consistent--thanks.

var expanderAttributes = ['data-toggle', 'data-target', 'aria-expanded', 'aria-controls', 'tabindex'];
var vulnerabilitiesContainer = $('#show-vulnerabilities-content-container');
if ($('#vulnerabilities-content-container').children().length) {
// If the deprecation information container has content, configure it as an expander.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "// If the vulnerabilities information container ..."

@@ -63,6 +63,50 @@
}
}

.vulnerabilities-container {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better that we share styles with the deprecation container? We can have a "warning-container" to define these shared styles, and it will be easier to maintain if we need more warning containers in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhhyu Looks like this change isn't practical--the js script that toggles chevron state uses the outer style name to identify the panel on which to rotate it when expanded. Messing with an outer style name has cascading effects. It could be feasible to change inner style names but this wouldn't achieve much as the names would then be duplicated in each outer style.

else
{
viewModel.Vulnerabilities = new List<PackageVulnerability>();
viewModel.MaxVulnerabilitySeverity = PackageVulnerabilitySeverity.Low;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any considerations to have an empty list and a low "MaxVulnerabilitySeverity" if there are no vulnerabilities? I see that we check "Vulnerabilities.Any()" in the view. Maybe it's better that we just leave "Vulnerabilities" as null, and take a null check of "Vulnerabilities" when there are no vulnerabilities? Setting "MaxVulnerabilitySeverity" as low seems a little confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no consideration except that it defaults to low. Changing it now would be disruptive to the db and I'm not sure much would be gained. I have made the null change though.

@@ -5,22 +5,36 @@ $(function () {
window.nuget.configureExpander("rename-content-container", "ChevronDown", null, "ChevronUp");
configureExpanderWithEnterKeydown($('#show-rename-content-container'));

// Configure the vulnerability information container
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe it's better to put this comment below the next line as "expanderAttributes" is also used for the deprecation container.

if (truncatedUrl.Length > 50)
{
truncatedUrl = truncatedUrl.Substring(0, 47) + "...";
}
Copy link
Contributor

@zhhyu zhhyu Dec 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we pick up the number 50 or 47? This may lead to the accessibility issue @ryuyu. How will a page reflow affect the appearance? Feel free to ignore this if we have already used the trick.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing this truncation. It will simply wrap if it needs to, and the table caters for that nicely now.

@drewgillies drewgillies force-pushed the dg-vulnerabilitymessaging branch 3 times, most recently from c5776ce to 91f55fa Compare January 7, 2021 05:31
@drewgillies
Copy link
Contributor Author

Note that I've also made calls to the deprecation and vulnerabilities services conditional on the respective feature flags (for perf and cleanness), so UTs needed updating to not verify calls against them that we no longer expect to happen.

Copy link
Contributor

@skofman1 skofman1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

PackageDeprecation deprecation,
PackageVulnerabilitySeverity? maxSeverity)
{
// We want a tooltip title for the warning icon, which concatenates deprecation and vulnerability information cleanly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: empty line

}

viewModel.PackageWarningIconTitle =
GetWarningIconTitle(viewModel.Version, deprecation, maxSeverity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe it's more clear as: maxSeverity -> maxVulnerabilitySeverity

}
@if (string.IsNullOrEmpty(packageVersion.PackageWarningIconTitle))
{
<td class="package-icon-cell" aria-hidden="true" />
Copy link
Contributor

@zhhyu zhhyu Jan 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still keep </td> here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of the advantage of empty tags over self-closing ones. I've changed this to an empty tag for consistency, but it just seems like a waste of chars to me. Self-closing tags are neater IMHO.

[InlineData(false, true, "{0} has at least one vulnerability with {1} severity.")]
[InlineData(true, true, "{0} is deprecated because it's legacy and no longer maintained; {0} has at least one vulnerability with {1} severity.")]
public async Task ShowsCombinedDeprecationAndVulnerabilitiesIconTitle(
bool isDeprecationEnabled,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great test!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! :)

@drewgillies drewgillies merged commit 5ce2f98 into dev Jan 8, 2021
@drewgillies drewgillies deleted the dg-vulnerabilitymessaging branch January 8, 2021 10:28
@zhhyu zhhyu mentioned this pull request Jan 28, 2021
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants