From c09f1b9e4e5638080622ff9aa70735db382a16df Mon Sep 17 00:00:00 2001 From: hmhealey Date: Thu, 9 Jul 2015 13:59:19 -0400 Subject: Renamed FullName column in database to Nickname. Renamed all serverside references from FullName to Nickname. --- model/channel_extra.go | 4 ++-- model/user.go | 10 +++++----- model/user_test.go | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'model') diff --git a/model/channel_extra.go b/model/channel_extra.go index a5c9acf71..d1579f905 100644 --- a/model/channel_extra.go +++ b/model/channel_extra.go @@ -10,7 +10,7 @@ import ( type ExtraMember struct { Id string `json:"id"` - FullName string `json:"full_name"` + Nickname string `json:"nickname"` Email string `json:"email"` Roles string `json:"roles"` Username string `json:"username"` @@ -21,7 +21,7 @@ func (o *ExtraMember) Sanitize(options map[string]bool) { o.Email = "" } if len(options) == 0 || !options["fullname"] { - o.FullName = "" + o.Nickname = "" } } diff --git a/model/user.go b/model/user.go index c5a4d846d..88f8f718a 100644 --- a/model/user.go +++ b/model/user.go @@ -37,7 +37,7 @@ type User struct { AuthData string `json:"auth_data"` Email string `json:"email"` EmailVerified bool `json:"email_verified"` - FullName string `json:"full_name"` + Nickname string `json:"nickname"` Roles string `json:"roles"` LastActivityAt int64 `json:"last_activity_at"` LastPingAt int64 `json:"last_ping_at"` @@ -82,8 +82,8 @@ func (u *User) IsValid() *AppError { return NewAppError("User.IsValid", "Invalid email", "user_id="+u.Id) } - if len(u.FullName) > 64 { - return NewAppError("User.IsValid", "Invalid full name", "user_id="+u.Id) + if len(u.Nickname) > 64 { + return NewAppError("User.IsValid", "Invalid nickname", "user_id="+u.Id) } return nil @@ -152,7 +152,7 @@ func (u *User) SetDefaultNotifications() { u.NotifyProps["first_name"] = "false" u.NotifyProps["all"] = "true" u.NotifyProps["channel"] = "true" - splitName := strings.Split(u.FullName, " ") + splitName := strings.Split(u.Nickname, " ") if len(splitName) > 0 && splitName[0] != "" { u.NotifyProps["first_name"] = "true" u.NotifyProps["mention_keys"] += "," + splitName[0] @@ -191,7 +191,7 @@ func (u *User) Sanitize(options map[string]bool) { u.Email = "" } if len(options) != 0 && !options["fullname"] { - u.FullName = "" + u.Nickname = "" } if len(options) != 0 && !options["skypeid"] { // TODO - fill in when SkypeId is added to user model diff --git a/model/user_test.go b/model/user_test.go index df9ac19c2..013bacc1c 100644 --- a/model/user_test.go +++ b/model/user_test.go @@ -80,12 +80,12 @@ func TestUserIsValid(t *testing.T) { } user.Email = "test@nowhere.com" - user.FullName = strings.Repeat("01234567890", 20) + user.Nickname = strings.Repeat("01234567890", 20) if err := user.IsValid(); err == nil { t.Fatal() } - user.FullName = "" + user.Nickname = "" if err := user.IsValid(); err != nil { t.Fatal(err) } -- cgit v1.2.3-1-g7c22 From 9d8073328a5e971aaff6285e33e212c08b31b510 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Thu, 9 Jul 2015 17:06:04 -0400 Subject: Added FirstName and LastName fields to User object and attempt to populate them from the FullName/Nickname field --- model/user.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'model') diff --git a/model/user.go b/model/user.go index 88f8f718a..7265381fd 100644 --- a/model/user.go +++ b/model/user.go @@ -38,6 +38,8 @@ type User struct { Email string `json:"email"` EmailVerified bool `json:"email_verified"` Nickname string `json:"nickname"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` Roles string `json:"roles"` LastActivityAt int64 `json:"last_activity_at"` LastPingAt int64 `json:"last_ping_at"` @@ -86,6 +88,14 @@ func (u *User) IsValid() *AppError { return NewAppError("User.IsValid", "Invalid nickname", "user_id="+u.Id) } + if len(u.FirstName) > 64 { + return NewAppError("User.IsValid", "Invalid first name", "user_id="+u.Id) + } + + if len(u.LastName) > 64 { + return NewAppError("User.IsValid", "Invalid last name", "user_id="+u.Id) + } + return nil } -- cgit v1.2.3-1-g7c22 From 31415c8ddcc915c64c791ece2e2439883b7cf6ae Mon Sep 17 00:00:00 2001 From: hmhealey Date: Fri, 10 Jul 2015 16:52:32 -0400 Subject: Sanitize FirstName and LastName fields of an object instead of the nickname when ShowFullName is set to false --- model/channel_extra.go | 3 --- model/user.go | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'model') diff --git a/model/channel_extra.go b/model/channel_extra.go index d1579f905..3a918b524 100644 --- a/model/channel_extra.go +++ b/model/channel_extra.go @@ -20,9 +20,6 @@ func (o *ExtraMember) Sanitize(options map[string]bool) { if len(options) == 0 || !options["email"] { o.Email = "" } - if len(options) == 0 || !options["fullname"] { - o.Nickname = "" - } } type ChannelExtra struct { diff --git a/model/user.go b/model/user.go index 7265381fd..5422f68a5 100644 --- a/model/user.go +++ b/model/user.go @@ -201,7 +201,8 @@ func (u *User) Sanitize(options map[string]bool) { u.Email = "" } if len(options) != 0 && !options["fullname"] { - u.Nickname = "" + u.FirstName = "" + u.LastName = "" } if len(options) != 0 && !options["skypeid"] { // TODO - fill in when SkypeId is added to user model -- cgit v1.2.3-1-g7c22 From abcb44089c421872de582584049ca4cc6b268f37 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 13 Jul 2015 16:43:59 -0400 Subject: Add tests to check if a User's first/last name are valid --- model/user_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'model') diff --git a/model/user_test.go b/model/user_test.go index 013bacc1c..4db099f97 100644 --- a/model/user_test.go +++ b/model/user_test.go @@ -89,4 +89,21 @@ func TestUserIsValid(t *testing.T) { if err := user.IsValid(); err != nil { t.Fatal(err) } + + user.FirstName = "" + user.LastName = "" + if err := user.IsValid(); err != nil { + t.Fatal(err) + } + + user.FirstName = strings.Repeat("01234567890", 20) + if err := user.IsValid(); err == nil { + t.Fatal(err) + } + + user.FirstName = "" + user.LastName = strings.Repeat("01234567890", 20) + if err := user.IsValid(); err == nil { + t.Fatal(err) + } } -- cgit v1.2.3-1-g7c22 From 098cbcdc21effeebe7e57fbd912a785e85cbfc5d Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 13 Jul 2015 17:47:57 -0400 Subject: Unify all locations where we determine a user's display named based off of their nickname/username into a helper function --- model/user.go | 8 ++++++++ model/user_test.go | 13 +++++++++++++ 2 files changed, 21 insertions(+) (limited to 'model') diff --git a/model/user.go b/model/user.go index 5422f68a5..5b603cd92 100644 --- a/model/user.go +++ b/model/user.go @@ -237,6 +237,14 @@ func (u *User) AddNotifyProp(key string, value string) { u.NotifyProps[key] = value } +func (u *User) GetDisplayName() string { + if u.Nickname != "" { + return u.Nickname + } else { + return u.Username + } +} + // UserFromJson will decode the input and return a User func UserFromJson(data io.Reader) *User { decoder := json.NewDecoder(data) diff --git a/model/user_test.go b/model/user_test.go index 4db099f97..a0c62676a 100644 --- a/model/user_test.go +++ b/model/user_test.go @@ -107,3 +107,16 @@ func TestUserIsValid(t *testing.T) { t.Fatal(err) } } + +func TestUserGetDisplayName(t *testing.T) { + user := User{FirstName: "first", LastName: "last", Username: "user"} + + if displayName := user.GetDisplayName(); displayName != "user" { + t.Fatal("Display name should be username") + } + + user.Nickname = "nickname" + if displayName := user.GetDisplayName(); displayName != "nickname" { + t.Fatal("Display name should be nickname") + } +} -- cgit v1.2.3-1-g7c22 From 1dba330146a10718a2fc9eac0ae7d6e1d6bc0d79 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Tue, 14 Jul 2015 17:07:19 -0400 Subject: Use a user's full name as their display name if a nickname hasn't been specified --- model/user.go | 14 ++++++++++++++ model/user_test.go | 32 +++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) (limited to 'model') diff --git a/model/user.go b/model/user.go index 5b603cd92..727165b8c 100644 --- a/model/user.go +++ b/model/user.go @@ -237,9 +237,23 @@ func (u *User) AddNotifyProp(key string, value string) { u.NotifyProps[key] = value } +func (u *User) GetFullName() string { + if u.FirstName != "" && u.LastName != "" { + return u.FirstName + " " + u.LastName + } else if u.FirstName != "" { + return u.FirstName + } else if u.LastName != "" { + return u.LastName + } else { + return "" + } +} + func (u *User) GetDisplayName() string { if u.Nickname != "" { return u.Nickname + } else if fullName := u.GetFullName(); fullName != "" { + return fullName } else { return u.Username } diff --git a/model/user_test.go b/model/user_test.go index a0c62676a..a48c3f2e7 100644 --- a/model/user_test.go +++ b/model/user_test.go @@ -108,13 +108,43 @@ func TestUserIsValid(t *testing.T) { } } +func TestUserGetFullName(t *testing.T) { + user := User{} + + if fullName := user.GetFullName(); fullName != "" { + t.Fatal("Full name should be blank") + } + + user.FirstName = "first" + if fullName := user.GetFullName(); fullName != "first" { + t.Fatal("Full name should be first name") + } + + user.FirstName = "" + user.LastName = "last" + if fullName := user.GetFullName(); fullName != "last" { + t.Fatal("Full name should be last name") + } + + user.FirstName = "first" + if fullName := user.GetFullName(); fullName != "first last" { + t.Fatal("Full name should be first name and last name") + } +} + func TestUserGetDisplayName(t *testing.T) { - user := User{FirstName: "first", LastName: "last", Username: "user"} + user := User{Username: "user"} if displayName := user.GetDisplayName(); displayName != "user" { t.Fatal("Display name should be username") } + user.FirstName = "first" + user.LastName = "last" + if displayName := user.GetDisplayName(); displayName != "first last" { + t.Fatal("Display name should be full name") + } + user.Nickname = "nickname" if displayName := user.GetDisplayName(); displayName != "nickname" { t.Fatal("Display name should be nickname") -- cgit v1.2.3-1-g7c22