Skip to content

Commit

Permalink
Improve FullName helper
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 28, 2024
1 parent cbd1be0 commit 5e38d0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pachca.go
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,15 @@ func (u *User) FullName() string {
return ""
}

switch {
case u == nil:
return ""
case u.FirstName == "" && u.LastName != "":
return u.LastName
case u.FirstName != "" && u.LastName == "":
return u.FirstName
}

return u.FirstName + " " + u.LastName
}

Expand Down
4 changes: 4 additions & 0 deletions pachca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ func (s *PachcaSuite) TestUsersHelpers(c *C) {
c.Assert(u.FullName(), Equals, "")
u = &User{ID: 1234, FirstName: "John", LastName: "Doe", Nickname: "j.doe"}
c.Assert(u.FullName(), Equals, "John Doe")
u = &User{ID: 1234, LastName: "Doe", Nickname: "j.doe"}
c.Assert(u.FullName(), Equals, "Doe")
u = &User{ID: 1234, FirstName: "John", Nickname: "j.doe"}
c.Assert(u.FullName(), Equals, "John")

uu := Users{
{ID: 1, IsSuspended: true, InviteStatus: INVITE_SENT, IsBot: false, Role: ROLE_USER},
Expand Down

0 comments on commit 5e38d0f

Please sign in to comment.