diff options
-rw-r--r-- | model/user.go | 10 | ||||
-rw-r--r-- | store/sql_user_store.go | 16 |
2 files changed, 24 insertions, 2 deletions
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 } diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 9e1cc9331..728c6b243 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -26,6 +26,8 @@ func NewSqlUserStore(sqlStore *SqlStore) UserStore { table.ColMap("AuthData").SetMaxSize(128) table.ColMap("Email").SetMaxSize(128) table.ColMap("Nickname").SetMaxSize(64) + table.ColMap("FirstName").SetMaxSize(64) + table.ColMap("LastName").SetMaxSize(64) table.ColMap("Roles").SetMaxSize(64) table.ColMap("Props").SetMaxSize(4000) table.ColMap("NotifyProps").SetMaxSize(2000) @@ -39,8 +41,18 @@ func NewSqlUserStore(sqlStore *SqlStore) UserStore { func (us SqlUserStore) UpgradeSchemaIfNeeded() { us.CreateColumnIfNotExists("Users", "LastPictureUpdate", "LastPasswordUpdate", "bigint(20)", "0") - // migrating the FullName column to Nickname for MM-825 - us.RenameColumnIfExists("Users", "FullName", "Nickname", "varchar(64)") + // migrating the FullName column to Nickname and adding the FirstName and LastName columns for MM-825 + if us.RenameColumnIfExists("Users", "FullName", "Nickname", "varchar(64)") { + us.CreateColumnIfNotExists("Users", "FirstName", "Nickname", "varchar(64)", "") + us.CreateColumnIfNotExists("Users", "LastName", "FirstName", "varchar(64)", "") + + // infer values of first and last name by splitting the previous full name + if _, err := us.GetMaster().Exec("UPDATE Users SET " + + "FirstName = SUBSTRING_INDEX(SUBSTRING_INDEX(Nickname, ' ', 1), ' ', -1), " + + "LastName = SUBSTRING(Nickname, INSTR(Nickname, ' ') + 1)"); err != nil { + panic("Failed to set first and last name columns from nickname " + err.Error()) + } + } } //func (ss SqlStore) CreateColumnIfNotExists(tableName string, columnName string, afterName string, colType string, defaultValue string) bool { |