diff options
author | Wim <wim@42.be> | 2016-11-12 22:00:53 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2016-11-12 22:00:53 +0100 |
commit | 1d5cd1d7c479c382c9cddaf02f1e59bf55971f12 (patch) | |
tree | abaf22fc41326750e376f0831537bbbbe769d5b2 /vendor/github.com/mattermost/platform/model/user.go | |
parent | 08ebee6b4faf677da159db1cffea292050492fd5 (diff) | |
download | matterbridge-msglm-1d5cd1d7c479c382c9cddaf02f1e59bf55971f12.tar.gz matterbridge-msglm-1d5cd1d7c479c382c9cddaf02f1e59bf55971f12.tar.bz2 matterbridge-msglm-1d5cd1d7c479c382c9cddaf02f1e59bf55971f12.zip |
Sync with mattermost 3.5.0
Diffstat (limited to 'vendor/github.com/mattermost/platform/model/user.go')
-rw-r--r-- | vendor/github.com/mattermost/platform/model/user.go | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/vendor/github.com/mattermost/platform/model/user.go b/vendor/github.com/mattermost/platform/model/user.go index 680bc48c..330d26d8 100644 --- a/vendor/github.com/mattermost/platform/model/user.go +++ b/vendor/github.com/mattermost/platform/model/user.go @@ -15,7 +15,6 @@ import ( ) const ( - ROLE_SYSTEM_ADMIN = "system_admin" USER_NOTIFY_ALL = "all" USER_NOTIFY_MENTION = "mention" USER_NOTIFY_NONE = "none" @@ -233,14 +232,15 @@ func (u *User) Sanitize(options map[string]bool) { if len(options) != 0 && !options["passwordupdate"] { u.LastPasswordUpdate = 0 } + if len(options) != 0 && !options["authservice"] { + u.AuthService = "" + } } func (u *User) ClearNonProfileFields() { u.Password = "" u.AuthData = new(string) *u.AuthData = "" - u.AuthService = "" - u.MfaActive = false u.MfaSecret = "" u.EmailVerified = false u.AllowMarketing = false @@ -319,9 +319,17 @@ func (u *User) GetDisplayNameForPreference(nameFormat string) string { return displayName } +func (u *User) GetRoles() []string { + return strings.Fields(u.Roles) +} + +func (u *User) GetRawRoles() string { + return u.Roles +} + func IsValidUserRoles(userRoles string) bool { - roles := strings.Split(userRoles, " ") + roles := strings.Fields(userRoles) for _, r := range roles { if !isValidRole(r) { @@ -329,19 +337,17 @@ func IsValidUserRoles(userRoles string) bool { } } - return true -} - -func isValidRole(role string) bool { - if role == "" { - return true + // Exclude just the system_admin role explicitly to prevent mistakes + if len(roles) == 1 && roles[0] == "system_admin" { + return false } - if role == ROLE_SYSTEM_ADMIN { - return true - } + return true +} - return false +func isValidRole(roleId string) bool { + _, ok := BuiltInRoles[roleId] + return ok } // Make sure you acually want to use this function. In context.go there are functions to check permissions @@ -411,6 +417,26 @@ func UserMapFromJson(data io.Reader) map[string]*User { } } +func UserListToJson(u []*User) string { + b, err := json.Marshal(u) + if err != nil { + return "" + } else { + return string(b) + } +} + +func UserListFromJson(data io.Reader) []*User { + decoder := json.NewDecoder(data) + var users []*User + err := decoder.Decode(&users) + if err == nil { + return users + } else { + return nil + } +} + // HashPassword generates a hash using the bcrypt.GenerateFromPassword func HashPassword(password string) string { hash, err := bcrypt.GenerateFromPassword([]byte(password), 10) |