diff options
author | =Corey Hulen <corey@hulen.com> | 2015-09-04 11:59:10 -0700 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-09-04 11:59:10 -0700 |
commit | 58d0d9afd286afd715e9f04825e1305045d404e2 (patch) | |
tree | 10615aa68c68106684503fb18ae4e4ef8998bc22 /model | |
parent | 05d95d80a896d14474c7f7384d67b9edd524b922 (diff) | |
download | chat-58d0d9afd286afd715e9f04825e1305045d404e2.tar.gz chat-58d0d9afd286afd715e9f04825e1305045d404e2.tar.bz2 chat-58d0d9afd286afd715e9f04825e1305045d404e2.zip |
Adding cmd line options
Diffstat (limited to 'model')
-rw-r--r-- | model/user.go | 47 | ||||
-rw-r--r-- | model/user_test.go | 10 |
2 files changed, 56 insertions, 1 deletions
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) diff --git a/model/user_test.go b/model/user_test.go index a3b4be091..32a6f9b78 100644 --- a/model/user_test.go +++ b/model/user_test.go @@ -192,3 +192,13 @@ func TestCleanUsername(t *testing.T) { t.Fatal("didn't clean name properly") } } + +func TestRoles(t *testing.T) { + + if !IsValidRoles("admin") { + t.Fatal() + } + + //IsInRole + +} |