From 58d0d9afd286afd715e9f04825e1305045d404e2 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Fri, 4 Sep 2015 11:59:10 -0700 Subject: Adding cmd line options --- model/user.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'model/user.go') diff --git a/model/user.go b/model/user.go index d82f96db3..9cec37ac6 100644 --- a/model/user.go +++ b/model/user.go @@ -15,7 +15,6 @@ import ( const ( ROLE_ADMIN = "admin" ROLE_SYSTEM_ADMIN = "system_admin" - ROLE_SYSTEM_SUPPORT = "system_support" USER_AWAY_TIMEOUT = 5 * 60 * 1000 // 5 minutes USER_OFFLINE_TIMEOUT = 1 * 60 * 1000 // 1 minute USER_OFFLINE = "offline" @@ -272,6 +271,52 @@ func (u *User) GetDisplayName() string { } } +func IsValidRoles(userRoles string) bool { + + roles := strings.Split(userRoles, " ") + + for _, r := range roles { + if !isValidRole(r) { + return false + } + } + + return true +} + +func isValidRole(role string) bool { + if role == "" { + return true + } + + if role == ROLE_ADMIN { + return true + } + + if role == ROLE_SYSTEM_ADMIN { + return true + } + + return false +} + +func (u *User) IsInRole(inRole string) bool { + return IsInRole(u.Roles, inRole) +} + +func IsInRole(userRoles string, inRole string) bool { + roles := strings.Split(userRoles, " ") + + for _, r := range roles { + if r == inRole { + return true + } + + } + + return false +} + // UserFromJson will decode the input and return a User func UserFromJson(data io.Reader) *User { decoder := json.NewDecoder(data) -- cgit v1.2.3-1-g7c22