From 139f6611d6162158ea88c679aee710f7a6c76c49 Mon Sep 17 00:00:00 2001 From: nickago Date: Thu, 16 Jul 2015 08:55:37 -0700 Subject: Added last updated for pictures --- model/user.go | 1 + 1 file changed, 1 insertion(+) (limited to 'model') diff --git a/model/user.go b/model/user.go index b94ceb899..c5a4d846d 100644 --- a/model/user.go +++ b/model/user.go @@ -45,6 +45,7 @@ type User struct { Props StringMap `json:"props"` NotifyProps StringMap `json:"notify_props"` LastPasswordUpdate int64 `json:"last_password_update"` + LastPictureUpdate int64 `json:"last_picture_update"` } // IsValid validates the user and returns an error if it isn't configured -- cgit v1.2.3-1-g7c22 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 From c6fb95912bb481791c1ca370a46a4da9c05d05ad Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 8 Jul 2015 11:50:10 -0400 Subject: Changing the way we mattermost handles URLs. team.domain.com becomes domain.com/team. Renaming team.Name to team.DisplayName and team.Domain to team.Name. So: team.Name -> url safe name. team.DisplayName -> nice name for users --- model/client.go | 20 ++++++++++---------- model/team.go | 14 +++++++------- model/team_signup_test.go | 2 +- model/team_test.go | 14 +++++++------- model/utils.go | 8 ++++---- model/utils_test.go | 8 ++++---- 6 files changed, 33 insertions(+), 33 deletions(-) (limited to 'model') diff --git a/model/client.go b/model/client.go index ab01e7d62..c7e17a6db 100644 --- a/model/client.go +++ b/model/client.go @@ -98,10 +98,10 @@ func (c *Client) Must(result *Result, err *AppError) *Result { return result } -func (c *Client) SignupTeam(email string, name string) (*Result, *AppError) { +func (c *Client) SignupTeam(email string, displayName string) (*Result, *AppError) { m := make(map[string]string) m["email"] = email - m["name"] = name + m["display_name"] = displayName if r, err := c.DoPost("/teams/signup", MapToJson(m)); err != nil { return nil, err } else { @@ -128,11 +128,11 @@ func (c *Client) CreateTeam(team *Team) (*Result, *AppError) { } } -func (c *Client) FindTeamByDomain(domain string, allServers bool) (*Result, *AppError) { +func (c *Client) FindTeamByName(name string, allServers bool) (*Result, *AppError) { m := make(map[string]string) - m["domain"] = domain + m["name"] = name m["all"] = fmt.Sprintf("%v", allServers) - if r, err := c.DoPost("/teams/find_team_by_domain", MapToJson(m)); err != nil { + if r, err := c.DoPost("/teams/find_team_by_name", MapToJson(m)); err != nil { return nil, err } else { val := false @@ -177,7 +177,7 @@ func (c *Client) InviteMembers(invites *Invites) (*Result, *AppError) { } } -func (c *Client) UpdateTeamName(data map[string]string) (*Result, *AppError) { +func (c *Client) UpdateTeamDisplayName(data map[string]string) (*Result, *AppError) { if r, err := c.DoPost("/teams/update_name", MapToJson(data)); err != nil { return nil, err } else { @@ -247,17 +247,17 @@ func (c *Client) LoginById(id string, password string) (*Result, *AppError) { return c.login(m) } -func (c *Client) LoginByEmail(domain string, email string, password string) (*Result, *AppError) { +func (c *Client) LoginByEmail(name string, email string, password string) (*Result, *AppError) { m := make(map[string]string) - m["domain"] = domain + m["name"] = name m["email"] = email m["password"] = password return c.login(m) } -func (c *Client) LoginByEmailWithDevice(domain string, email string, password string, deviceId string) (*Result, *AppError) { +func (c *Client) LoginByEmailWithDevice(name string, email string, password string, deviceId string) (*Result, *AppError) { m := make(map[string]string) - m["domain"] = domain + m["name"] = name m["email"] = email m["password"] = password m["device_id"] = deviceId diff --git a/model/team.go b/model/team.go index 5c66f3b1f..e7005625b 100644 --- a/model/team.go +++ b/model/team.go @@ -18,8 +18,8 @@ type Team struct { CreateAt int64 `json:"create_at"` UpdateAt int64 `json:"update_at"` DeleteAt int64 `json:"delete_at"` + DisplayName string `json:"display_name"` Name string `json:"name"` - Domain string `json:"domain"` Email string `json:"email"` Type string `json:"type"` CompanyName string `json:"company_name"` @@ -97,20 +97,20 @@ func (o *Team) IsValid() *AppError { return NewAppError("Team.IsValid", "Invalid email", "id="+o.Id) } - if len(o.Name) > 64 { + if len(o.DisplayName) > 64 { return NewAppError("Team.IsValid", "Invalid name", "id="+o.Id) } - if len(o.Domain) > 64 { - return NewAppError("Team.IsValid", "Invalid domain", "id="+o.Id) + if len(o.Name) > 64 { + return NewAppError("Team.IsValid", "Invalid URL Identifier", "id="+o.Id) } - if IsReservedDomain(o.Domain) { + if IsReservedTeamName(o.Name) { return NewAppError("Team.IsValid", "This URL is unavailable. Please try another.", "id="+o.Id) } - if !IsValidDomain(o.Domain) { - return NewAppError("Team.IsValid", "Domain must be 4 or more lowercase alphanumeric characters", "id="+o.Id) + if !IsValidTeamName(o.Name) { + return NewAppError("Team.IsValid", "Name must be 4 or more lowercase alphanumeric characters", "id="+o.Id) } if !(o.Type == TEAM_OPEN || o.Type == TEAM_INVITE) { diff --git a/model/team_signup_test.go b/model/team_signup_test.go index f3f74470b..eb2fbc69f 100644 --- a/model/team_signup_test.go +++ b/model/team_signup_test.go @@ -9,7 +9,7 @@ import ( ) func TestTeamSignupJson(t *testing.T) { - team := Team{Id: NewId(), Name: NewId()} + team := Team{Id: NewId(), DisplayName: NewId()} o := TeamSignup{Team: team, Data: "data"} json := o.ToJson() ro := TeamSignupFromJson(strings.NewReader(json)) diff --git a/model/team_test.go b/model/team_test.go index 6261ed6bf..071b1a2e9 100644 --- a/model/team_test.go +++ b/model/team_test.go @@ -9,7 +9,7 @@ import ( ) func TestTeamJson(t *testing.T) { - o := Team{Id: NewId(), Name: NewId()} + o := Team{Id: NewId(), DisplayName: NewId()} json := o.ToJson() ro := TeamFromJson(strings.NewReader(json)) @@ -46,18 +46,18 @@ func TestTeamIsValid(t *testing.T) { } o.Email = "corey@hulen.com" - o.Name = strings.Repeat("01234567890", 20) + o.DisplayName = strings.Repeat("01234567890", 20) if err := o.IsValid(); err == nil { t.Fatal("should be invalid") } - o.Name = "1234" - o.Domain = "ZZZZZZZ" + o.DisplayName = "1234" + o.Name = "ZZZZZZZ" if err := o.IsValid(); err == nil { t.Fatal("should be invalid") } - o.Domain = "zzzzz" + o.Name = "zzzzz" o.Type = TEAM_OPEN if err := o.IsValid(); err != nil { t.Fatal(err) @@ -65,12 +65,12 @@ func TestTeamIsValid(t *testing.T) { } func TestTeamPreSave(t *testing.T) { - o := Team{Name: "test"} + o := Team{DisplayName: "test"} o.PreSave() o.Etag() } func TestTeamPreUpdate(t *testing.T) { - o := Team{Name: "test"} + o := Team{DisplayName: "test"} o.PreUpdate() } diff --git a/model/utils.go b/model/utils.go index 465901a09..38592b984 100644 --- a/model/utils.go +++ b/model/utils.go @@ -148,7 +148,7 @@ func IsValidEmail(email string) bool { return false } -var reservedDomains = []string{ +var reservedName = []string{ "www", "web", "admin", @@ -168,10 +168,10 @@ var reservedDomains = []string{ "api", } -func IsReservedDomain(s string) bool { +func IsReservedTeamName(s string) bool { s = strings.ToLower(s) - for _, value := range reservedDomains { + for _, value := range reservedName { if strings.Index(s, value) == 0 { return true } @@ -180,7 +180,7 @@ func IsReservedDomain(s string) bool { return false } -func IsValidDomain(s string) bool { +func IsValidTeamName(s string) bool { if !IsValidAlphaNum(s) { return false diff --git a/model/utils_test.go b/model/utils_test.go index a9721042d..dbb448882 100644 --- a/model/utils_test.go +++ b/model/utils_test.go @@ -83,9 +83,9 @@ var domains = []struct { {"test", true}, } -func TestValidDomain(t *testing.T) { +func TestValidTeamName(t *testing.T) { for _, v := range domains { - if IsValidDomain(v.value) != v.expected { + if IsValidTeamName(v.value) != v.expected { t.Errorf("expect %v as %v", v.value, v.expected) } } @@ -102,9 +102,9 @@ var tReservedDomains = []struct { {"spin-punch-admin", false}, } -func TestReservedDomain(t *testing.T) { +func TestReservedTeamName(t *testing.T) { for _, v := range tReservedDomains { - if IsReservedDomain(v.value) != v.expected { + if IsReservedTeamName(v.value) != v.expected { t.Errorf("expect %v as %v", v.value, v.expected) } } -- cgit v1.2.3-1-g7c22