From f26f41c94b0fc2cafc5eb8e0a9ee0a5bcdef4f17 Mon Sep 17 00:00:00 2001 From: lyndaidaii Date: Wed, 14 Apr 2021 16:35:41 -0700 Subject: [PATCH] add feature flag for banner --- .../Fakes/FakeFeatureFlagService.cs | 5 +++++ .../Configuration/FeatureFlagService.cs | 6 ++++++ .../Configuration/IFeatureFlagService.cs | 5 +++++ src/NuGetGallery/Controllers/PagesController.cs | 3 ++- .../ViewModels/GalleryHomeViewModel.cs | 5 +++++ src/NuGetGallery/Views/Pages/Home.cshtml | 1 + .../Views/Shared/Gallery/Header.cshtml | 17 ++++++++++------- .../Fakes/FakeFeatureFlagService.cs | 2 ++ 8 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/GitHubVulnerabilities2Db/Fakes/FakeFeatureFlagService.cs b/src/GitHubVulnerabilities2Db/Fakes/FakeFeatureFlagService.cs index ee9f78bea3..b26da4fcb3 100644 --- a/src/GitHubVulnerabilities2Db/Fakes/FakeFeatureFlagService.cs +++ b/src/GitHubVulnerabilities2Db/Fakes/FakeFeatureFlagService.cs @@ -55,6 +55,11 @@ public bool IsDeletePackageApiEnabled(User user) throw new NotImplementedException(); } + public bool IsDisplayBannerEnabled() + { + throw new NotImplementedException(); + } + public bool IsDisplayFuGetLinksEnabled() { throw new NotImplementedException(); diff --git a/src/NuGetGallery.Services/Configuration/FeatureFlagService.cs b/src/NuGetGallery.Services/Configuration/FeatureFlagService.cs index edae0f160f..bd6e292494 100644 --- a/src/NuGetGallery.Services/Configuration/FeatureFlagService.cs +++ b/src/NuGetGallery.Services/Configuration/FeatureFlagService.cs @@ -47,6 +47,7 @@ public class FeatureFlagService : IFeatureFlagService private const string MarkdigMdRenderingFlightName = GalleryPrefix + "MarkdigMdRendering"; private const string DeletePackageApiFlightName = GalleryPrefix + "DeletePackageApi"; private const string ImageAllowlistFlightName = GalleryPrefix + "ImageAllowlist"; + private const string DisplayBannerFlightName = GalleryPrefix + "Banner"; private const string ODataV1GetAllNonHijackedFeatureName = GalleryPrefix + "ODataV1GetAllNonHijacked"; private const string ODataV1GetAllCountNonHijackedFeatureName = GalleryPrefix + "ODataV1GetAllCountNonHijacked"; @@ -326,5 +327,10 @@ public bool IsImageAllowlistEnabled() { return _client.IsEnabled(ImageAllowlistFlightName, defaultValue: false); } + + public bool IsDisplayBannerEnabled() + { + return _client.IsEnabled(DisplayBannerFlightName, defaultValue: false); + } } } \ No newline at end of file diff --git a/src/NuGetGallery.Services/Configuration/IFeatureFlagService.cs b/src/NuGetGallery.Services/Configuration/IFeatureFlagService.cs index 3e8e96a2a4..e8ffeed47d 100644 --- a/src/NuGetGallery.Services/Configuration/IFeatureFlagService.cs +++ b/src/NuGetGallery.Services/Configuration/IFeatureFlagService.cs @@ -260,5 +260,10 @@ public interface IFeatureFlagService /// Whether the allowlist is enabled for checking the image sources /// bool IsImageAllowlistEnabled(); + + /// + /// Whether or not display the banner on nuget.org + /// + bool IsDisplayBannerEnabled(); } } diff --git a/src/NuGetGallery/Controllers/PagesController.cs b/src/NuGetGallery/Controllers/PagesController.cs index f03492f05e..3e8b72e101 100644 --- a/src/NuGetGallery/Controllers/PagesController.cs +++ b/src/NuGetGallery/Controllers/PagesController.cs @@ -122,8 +122,9 @@ public virtual ActionResult Home() var externalIdentityList = ClaimsExtensions.GetExternalCredentialIdentityList(identity); var showEnable2FAModal = _featureFlagService.IsShowEnable2FADialogEnabled(); var getFeedbackOnModalDismiss = _featureFlagService.IsGet2FADismissFeedbackEnabled(); + var displayBanner = _featureFlagService.IsDisplayBannerEnabled(); - return View(new GalleryHomeViewModel(showTransformModal, transformIntoOrganization, showEnable2FAModal, getFeedbackOnModalDismiss, externalIdentityList)); + return View(new GalleryHomeViewModel(showTransformModal, transformIntoOrganization, showEnable2FAModal, getFeedbackOnModalDismiss, displayBanner, externalIdentityList)); } [HttpGet] diff --git a/src/NuGetGallery/ViewModels/GalleryHomeViewModel.cs b/src/NuGetGallery/ViewModels/GalleryHomeViewModel.cs index 88b2a0719f..f93538cc41 100644 --- a/src/NuGetGallery/ViewModels/GalleryHomeViewModel.cs +++ b/src/NuGetGallery/ViewModels/GalleryHomeViewModel.cs @@ -15,11 +15,14 @@ public class GalleryHomeViewModel public bool GetFeedbackOnModalDismissFeatureEnabled { get; set; } + public bool DisplayBannerFeatureEnabled { get; set; } + public GalleryHomeViewModel() : this( showTransformModal: false, transformIntoOrganization: false, showEnable2FAModalFeatureEnabled: false, getFeedbackOnModalDismiss: false, + displayBanner: false, identity: null) { } @@ -28,12 +31,14 @@ public GalleryHomeViewModel( bool transformIntoOrganization, bool showEnable2FAModalFeatureEnabled, bool getFeedbackOnModalDismiss, + bool displayBanner, string identity = null) { ShowTransformModal = showTransformModal; TransformIntoOrganization = transformIntoOrganization; ShowEnable2FAModalFeatureEnabled = showEnable2FAModalFeatureEnabled; GetFeedbackOnModalDismissFeatureEnabled = getFeedbackOnModalDismiss; + DisplayBannerFeatureEnabled = displayBanner; Identity = identity; } } diff --git a/src/NuGetGallery/Views/Pages/Home.cshtml b/src/NuGetGallery/Views/Pages/Home.cshtml index efa6fd430b..e453a7f304 100644 --- a/src/NuGetGallery/Views/Pages/Home.cshtml +++ b/src/NuGetGallery/Views/Pages/Home.cshtml @@ -4,6 +4,7 @@ ViewBag.ShowSearchInNavbar = false; ViewBag.AutofocusSearch = true; ViewBag.HasJumbotron = true; + ViewBag.DisplayBanner = Model.DisplayBannerFeatureEnabled; var AskUserToEnable2FA = TempData.ContainsKey("AskUserToEnable2FA") && Convert.ToBoolean(TempData["AskUserToEnable2FA"].ToString()) && Model.ShowEnable2FAModalFeatureEnabled; diff --git a/src/NuGetGallery/Views/Shared/Gallery/Header.cshtml b/src/NuGetGallery/Views/Shared/Gallery/Header.cshtml index fdf9c6231f..e5814935a5 100644 --- a/src/NuGetGallery/Views/Shared/Gallery/Header.cshtml +++ b/src/NuGetGallery/Views/Shared/Gallery/Header.cshtml @@ -22,15 +22,18 @@ } -