4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-06-28 07:59:24 +00:00

Sync with mattermost 3.5.0

This commit is contained in:
Wim
2016-11-12 22:00:53 +01:00
parent 08ebee6b4f
commit 1d5cd1d7c4
32 changed files with 1476 additions and 430 deletions

View File

@ -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 {
}
}
// Exclude just the system_admin role explicitly to prevent mistakes
if len(roles) == 1 && roles[0] == "system_admin" {
return false
}
return true
}
func isValidRole(role string) bool {
if role == "" {
return true
}
if role == ROLE_SYSTEM_ADMIN {
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)