From 9983d1299f597598c24a9c3052a5d87947b1834a Mon Sep 17 00:00:00 2001 From: Emma May Date: Wed, 20 Nov 2024 13:34:49 -0500 Subject: [PATCH 1/2] [DDO-3900] Fix clearing banner bucket --- sherlock/internal/api/sherlock/environments_v3_edit.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sherlock/internal/api/sherlock/environments_v3_edit.go b/sherlock/internal/api/sherlock/environments_v3_edit.go index 89eaa26a3..1b5c82a1c 100644 --- a/sherlock/internal/api/sherlock/environments_v3_edit.go +++ b/sherlock/internal/api/sherlock/environments_v3_edit.go @@ -65,5 +65,14 @@ func environmentsV3Edit(ctx *gin.Context) { } } + // Allow clearing serviceBannerBucket by setting an empty string. + if body.ServiceBannerBucket != nil && *body.ServiceBannerBucket == "" { + toEdit.ServiceBannerBucket = nil + if err = db.Model(&toEdit).Omit(clause.Associations).Update("service_banner_bucket", nil).Error; err != nil { + errors.AbortRequest(ctx, err) + return + } + } + ctx.JSON(http.StatusOK, environmentFromModel(toEdit)) } From 5705e88f634b3233b19426af221acef8538258d3 Mon Sep 17 00:00:00 2001 From: Emma May Date: Wed, 20 Nov 2024 14:37:23 -0500 Subject: [PATCH 2/2] tests --- .../api/sherlock/environments_v3_edit_test.go | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/sherlock/internal/api/sherlock/environments_v3_edit_test.go b/sherlock/internal/api/sherlock/environments_v3_edit_test.go index 19d027afa..f9c01d1ba 100644 --- a/sherlock/internal/api/sherlock/environments_v3_edit_test.go +++ b/sherlock/internal/api/sherlock/environments_v3_edit_test.go @@ -204,3 +204,30 @@ func (s *handlerSuite) TestEnvironmentsV3Edit_deleteAfter_failToParse() { s.Equal(errors.BadRequest, got.Type) s.Contains(got.Message, "foobar") } + +func (s *handlerSuite) TestEnvironmentsV3Edit_clearExistingBannerBucket() { + edit := s.TestData.Environment_Swatomation_TestBee() + var got EnvironmentV3 + code := s.HandleRequest( + s.NewRequest("PATCH", fmt.Sprintf("/api/environments/v3/%d", edit.ID), EnvironmentV3Edit{ + ServiceBannerBucket: utils.PointerTo(""), + }), + &got) + s.Equal(http.StatusOK, code) + println(got.ServiceBannerBucket) + s.Nil(got.ServiceBannerBucket) +} + +func (s *handlerSuite) TestEnvironmentsV3Edit_setMissingBannerBucket() { + edit := s.TestData.Environment_DdpAzureDev() + var got EnvironmentV3 + code := s.HandleRequest( + s.NewRequest("PATCH", fmt.Sprintf("/api/environments/v3/%d", edit.ID), EnvironmentV3Edit{ + ServiceBannerBucket: utils.PointerTo("firecloud-alerts-ddp-azure-dev"), + }), + &got) + s.Equal(http.StatusOK, code) + if s.NotNil(got.ServiceBannerBucket) { + s.Equal("firecloud-alerts-ddp-azure-dev", *got.ServiceBannerBucket) + } +}