From b1734b84184b8ac970138ae4fcd6c21047f7752f Mon Sep 17 00:00:00 2001 From: Heng Liu <45407901+heng-liu@users.noreply.github.com> Date: Wed, 6 Sep 2023 10:01:31 -0700 Subject: [PATCH] Do not show warning icons for HTTP sources in VS Options when allowInsecureConnections is true (#5399) --- .../Options/CheckedListBoxAccessibleObject.cs | 2 +- .../Options/PackageSourceCheckedListBox.cs | 7 ++++--- .../PackageSourcesOptionsControl.Designer.cs | 1 - .../Options/PackageSourcesOptionsControl.cs | 21 +++++++++++++++---- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/CheckedListBoxAccessibleObject.cs b/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/CheckedListBoxAccessibleObject.cs index be2fa0ab020..e26f367d0c5 100644 --- a/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/CheckedListBoxAccessibleObject.cs +++ b/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/CheckedListBoxAccessibleObject.cs @@ -34,7 +34,7 @@ public override AccessibleObject GetChild(int index) { var item = (PackageSourceContextInfo)CheckedListBox.Items[index]; PackageSource packageSource = new PackageSource(item.Source, item.Name); - if (packageSource.IsHttp && !packageSource.IsHttps) + if (packageSource.IsHttp && !packageSource.IsHttps && !packageSource.AllowInsecureConnections) { var sourceMessage = string.Concat( Resources.Warning_HTTPSource, diff --git a/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourceCheckedListBox.cs b/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourceCheckedListBox.cs index 6fc6b40b79c..1f43314f532 100644 --- a/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourceCheckedListBox.cs +++ b/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourceCheckedListBox.cs @@ -136,10 +136,11 @@ protected override void OnDrawItem(DrawItemEventArgs e) graphics.DrawString(currentItem.Name, e.Font, foreBrush, nameBounds, drawFormat); var packageSource = new PackageSource(currentItem.Source, currentItem.Name); - var isSourceHttp = packageSource.IsHttp && !packageSource.IsHttps; + packageSource.AllowInsecureConnections = currentItem.AllowInsecureConnections; + var shouldShowHttpWarningIcon = packageSource.IsHttp && !packageSource.IsHttps && !packageSource.AllowInsecureConnections; Rectangle warningBounds = default; - if (isSourceHttp) + if (shouldShowHttpWarningIcon) { var warningIcon = GetWarningIcon(); @@ -152,7 +153,7 @@ protected override void OnDrawItem(DrawItemEventArgs e) } var sourceBounds = new Rectangle( - isSourceHttp ? warningBounds.Right : nameBounds.Left, + shouldShowHttpWarningIcon ? warningBounds.Right : nameBounds.Left, nameBounds.Bottom, textWidth, e.Bounds.Bottom - nameBounds.Bottom); diff --git a/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourcesOptionsControl.Designer.cs b/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourcesOptionsControl.Designer.cs index 4aca1e946f5..80117e90bbd 100644 --- a/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourcesOptionsControl.Designer.cs +++ b/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourcesOptionsControl.Designer.cs @@ -124,7 +124,6 @@ private void InitializeComponent() resources.ApplyResources(this.NewPackageSource, "NewPackageSource"); this.NewPackageSource.Name = "NewPackageSource"; this.NewPackageSource.AccessibleName = "Source:"; - this.NewPackageSource.TextChanged += new System.EventHandler(this.NewPackageSource_TextChanged); // // NewPackageNameLabel // diff --git a/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourcesOptionsControl.cs b/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourcesOptionsControl.cs index 0de0162e871..5b8643b99df 100644 --- a/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourcesOptionsControl.cs +++ b/src/NuGet.Clients/NuGet.PackageManagement.UI/Options/PackageSourcesOptionsControl.cs @@ -152,6 +152,16 @@ private void UpdateUI() // Always enable addButton for PackageSourceListBox addButton.Enabled = true; } + + // Show HttpWarning for the selected source if needed + if (selectedSource != null) + { + SetHttpWarningVisibilityForSelectSource(selectedSource); + } + else if (selectedMachineSource != null) + { + SetHttpWarningVisibilityForSelectSource(selectedMachineSource); + } } internal async Task InitializeOnActivatedAsync(CancellationToken cancellationToken) @@ -477,6 +487,8 @@ private TryUpdateSourceResults TryUpdateSource() selectedPackageSource.Source = source; _packageSources.ResetCurrentItem(); + SetHttpWarningVisibilityForSelectSource(selectedPackageSource); + return TryUpdateSourceResults.Successful; } @@ -703,12 +715,13 @@ private static bool IsPathRootedSafe(string path) return path.IndexOfAny(Path.GetInvalidPathChars()) == -1 && Path.IsPathRooted(path); } - private void NewPackageSource_TextChanged(object sender, EventArgs e) + private void SetHttpWarningVisibilityForSelectSource(PackageSourceContextInfo selectedSource) { - var source = new PackageSource(NewPackageSource.Text.Trim(), NewPackageName.Text.Trim()); + var source = new PackageSource(selectedSource.Source, selectedSource.Name); + source.AllowInsecureConnections = selectedSource.AllowInsecureConnections; - // Warn if the source is http, support for this will be removed - if (source.IsHttp && !source.IsHttps) + // Warn if the selected source is http, and the AllowInsecureConnections for this source is set to false. + if (source.IsHttp && !source.IsHttps && !source.AllowInsecureConnections) { HttpWarning.Visible = true; HttpWarningIcon.Visible = true;