From cf98337311305f8630bdcb89cb04adc6c4dd9f23 Mon Sep 17 00:00:00 2001 From: Jack Warren Date: Wed, 2 Oct 2024 10:08:12 -0400 Subject: [PATCH] remove nameInferredFromGithub --- ...99_drop_name_inferred_from_github.down.sql | 2 + ...0099_drop_name_inferred_from_github.up.sql | 2 + sherlock/internal/api/sherlock/users_v3.go | 25 +------- .../internal/api/sherlock/users_v3_upsert.go | 9 --- .../api/sherlock/users_v3_upsert_test.go | 57 ------------------- 5 files changed, 6 insertions(+), 89 deletions(-) create mode 100644 sherlock/db/migrations/000099_drop_name_inferred_from_github.down.sql create mode 100644 sherlock/db/migrations/000099_drop_name_inferred_from_github.up.sql diff --git a/sherlock/db/migrations/000099_drop_name_inferred_from_github.down.sql b/sherlock/db/migrations/000099_drop_name_inferred_from_github.down.sql new file mode 100644 index 000000000..d5c006612 --- /dev/null +++ b/sherlock/db/migrations/000099_drop_name_inferred_from_github.down.sql @@ -0,0 +1,2 @@ +alter table users + add column name_inferred_from_github boolean; \ No newline at end of file diff --git a/sherlock/db/migrations/000099_drop_name_inferred_from_github.up.sql b/sherlock/db/migrations/000099_drop_name_inferred_from_github.up.sql new file mode 100644 index 000000000..e9c08ef34 --- /dev/null +++ b/sherlock/db/migrations/000099_drop_name_inferred_from_github.up.sql @@ -0,0 +1,2 @@ +alter table users + drop column name_inferred_from_github; \ No newline at end of file diff --git a/sherlock/internal/api/sherlock/users_v3.go b/sherlock/internal/api/sherlock/users_v3.go index 00a3e5300..891623407 100644 --- a/sherlock/internal/api/sherlock/users_v3.go +++ b/sherlock/internal/api/sherlock/users_v3.go @@ -20,11 +20,8 @@ type UserV3 struct { } type userDirectlyEditableFields struct { - Name *string `json:"name,omitempty" form:"name"` - // Controls whether Sherlock should automatically update the user's name based on a connected GitHub identity. - // Will be set to true if the user account has no name and a GitHub account is linked. - NameInferredFromGithub *bool `json:"nameInferredFromGithub,omitempty" form:"nameInferredFromGithub"` - NameFrom *string `json:"nameFrom,omitempty" form:"nameFrom" enums:"sherlock,github,slack" binding:"omitempty,oneof=sherlock github slack"` + Name *string `json:"name,omitempty" form:"name"` + NameFrom *string `json:"nameFrom,omitempty" form:"nameFrom" enums:"sherlock,github,slack" binding:"omitempty,oneof=sherlock github slack"` } func (u UserV3) toModel() models.User { @@ -39,15 +36,6 @@ func (u UserV3) toModel() models.User { Name: u.Name, NameFrom: u.NameFrom, } - if u.NameFrom == nil && u.NameInferredFromGithub != nil { - if *u.NameInferredFromGithub { - githubString := "github" - ret.NameFrom = &githubString - } else { - sherlockString := "sherlock" - ret.NameFrom = &sherlockString - } - } return ret } @@ -78,14 +66,5 @@ func userFromModel(model models.User) UserV3 { return utils.NilOrCall(roleAssignmentFromModel, ra) }) } - if model.NameFrom != nil { - if *model.NameFrom == "github" { - trueBool := true - ret.NameInferredFromGithub = &trueBool - } else { - falseBool := false - ret.NameInferredFromGithub = &falseBool - } - } return ret } diff --git a/sherlock/internal/api/sherlock/users_v3_upsert.go b/sherlock/internal/api/sherlock/users_v3_upsert.go index 1945663a0..e8b8728c9 100644 --- a/sherlock/internal/api/sherlock/users_v3_upsert.go +++ b/sherlock/internal/api/sherlock/users_v3_upsert.go @@ -143,15 +143,6 @@ func processUserEdits(callingUser *models.User, directEdits userDirectlyEditable wg.Wait() - // If nameFrom wasn't set but nameInferredFromGithub was, be compatible and convert it to nameFrom - if directEdits.NameFrom == nil && directEdits.NameInferredFromGithub != nil { - if *directEdits.NameInferredFromGithub { - directEdits.NameFrom = &githubString - } else { - directEdits.NameFrom = &sherlockString - } - } - // Set nameFrom if it was provided and is different from what we already have if directEdits.NameFrom != nil && (callingUser.NameFrom == nil || *directEdits.NameFrom != *callingUser.NameFrom) { callingUser.NameFrom = directEdits.NameFrom diff --git a/sherlock/internal/api/sherlock/users_v3_upsert_test.go b/sherlock/internal/api/sherlock/users_v3_upsert_test.go index 02e0a14c8..4d08426c5 100644 --- a/sherlock/internal/api/sherlock/users_v3_upsert_test.go +++ b/sherlock/internal/api/sherlock/users_v3_upsert_test.go @@ -60,7 +60,6 @@ func (s *handlerSuite) TestUserV3Upsert_name_minimal() { s.Equal(s.TestData.User_Suitable().Email, got.Email) s.Equal("a name", *got.Name) s.Equal("sherlock", *got.NameFrom) - s.False(*got.NameInferredFromGithub) s.Run("update name", func() { code = s.HandleRequest( @@ -74,62 +73,6 @@ func (s *handlerSuite) TestUserV3Upsert_name_minimal() { s.Equal(s.TestData.User_Suitable().Email, got.Email) s.Equal("a different name", *got.Name) s.Equal("sherlock", *got.NameFrom) - s.False(*got.NameInferredFromGithub) - }) -} - -func (s *handlerSuite) TestUserV3Upsert_nameInferredFromGithub() { - var got UserV3 - code := s.HandleRequest( - s.NewRequest("PUT", "/api/users/v3", UserV3Upsert{ - userDirectlyEditableFields: userDirectlyEditableFields{ - NameInferredFromGithub: utils.PointerTo(true), - }, - }), - &got) - s.Equal(http.StatusCreated, code) - s.Equal(s.TestData.User_Suitable().Email, got.Email) - s.True(*got.NameInferredFromGithub) - - s.Run("then doesn't update name", func() { - code = s.HandleRequest( - s.NewRequest("PUT", "/api/users/v3", UserV3Upsert{ - userDirectlyEditableFields: userDirectlyEditableFields{ - Name: utils.PointerTo("a different name"), - }, - }), - &got) - s.Equal(http.StatusOK, code) - s.Equal(s.TestData.User_Suitable().Email, got.Email) - s.Nil(got.Name) - s.True(*got.NameInferredFromGithub) - }) - - s.Run("can set to false", func() { - code = s.HandleRequest( - s.NewRequest("PUT", "/api/users/v3", UserV3Upsert{ - userDirectlyEditableFields: userDirectlyEditableFields{ - NameInferredFromGithub: utils.PointerTo(false), - }, - }), - &got) - s.Equal(http.StatusCreated, code) - s.Equal(s.TestData.User_Suitable().Email, got.Email) - s.False(*got.NameInferredFromGithub) - - s.Run("then updates name", func() { - code = s.HandleRequest( - s.NewRequest("PUT", "/api/users/v3", UserV3Upsert{ - userDirectlyEditableFields: userDirectlyEditableFields{ - Name: utils.PointerTo("a different name"), - }, - }), - &got) - s.Equal(http.StatusCreated, code) - s.Equal(s.TestData.User_Suitable().Email, got.Email) - s.Equal("a different name", *got.Name) - s.False(*got.NameInferredFromGithub) - }) }) }