Skip to content

Commit

Permalink
remove nameInferredFromGithub
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-r-warren committed Oct 2, 2024
1 parent 4f887c4 commit cf98337
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table users
add column name_inferred_from_github boolean;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table users
drop column name_inferred_from_github;
25 changes: 2 additions & 23 deletions sherlock/internal/api/sherlock/users_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
9 changes: 0 additions & 9 deletions sherlock/internal/api/sherlock/users_v3_upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 0 additions & 57 deletions sherlock/internal/api/sherlock/users_v3_upsert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
})
})
}

Expand Down

0 comments on commit cf98337

Please sign in to comment.