diff --git a/pachca.go b/pachca.go index c5136df..10c2c3f 100644 --- a/pachca.go +++ b/pachca.go @@ -1671,8 +1671,13 @@ func (p *Property) Int() int { // FullName returns user full name func (u *User) FullName() string { - if u == nil { + switch { + case u == nil, u.FirstName == "" && u.LastName == "": return "" + case u.FirstName == "" && u.LastName != "": + return u.LastName + case u.FirstName != "" && u.LastName == "": + return u.FirstName } return u.FirstName + " " + u.LastName @@ -1709,7 +1714,7 @@ func (u Users) Invited() Users { var result Users for _, uu := range u { - if uu.InviteStatus == INVITE_SENT { + if !uu.IsBot && uu.InviteStatus == INVITE_SENT { result = append(result, uu) } } diff --git a/pachca_test.go b/pachca_test.go index 3fbfacb..46065ec 100644 --- a/pachca_test.go +++ b/pachca_test.go @@ -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},