summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-09-14 08:58:53 -0400
committerChristopher Speller <crspeller@gmail.com>2015-09-14 08:58:53 -0400
commitc3742aef71801544172cf77a46d52835594096a4 (patch)
tree76b3aacf1ee6da724201ea5411bef068cce3b26a /model
parent75721b5cb5ea19c1d6754adcc82891fa888fcacf (diff)
parent714f47e015adf4a455d29cbddfb5f58f84d9973e (diff)
downloadchat-c3742aef71801544172cf77a46d52835594096a4.tar.gz
chat-c3742aef71801544172cf77a46d52835594096a4.tar.bz2
chat-c3742aef71801544172cf77a46d52835594096a4.zip
Merge pull request #648 from mattermost/PLT-12
PLT-12: Work in progress for Admin Console UI
Diffstat (limited to 'model')
-rw-r--r--model/user.go49
-rw-r--r--model/user_test.go23
2 files changed, 70 insertions, 2 deletions
diff --git a/model/user.go b/model/user.go
index 05fc96953..fdc519b99 100644
--- a/model/user.go
+++ b/model/user.go
@@ -13,9 +13,8 @@ import (
)
const (
- ROLE_ADMIN = "admin"
+ ROLE_TEAM_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_TEAM_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
+}
+
func (u *User) PreExport() {
u.Password = ""
u.AuthData = ""
diff --git a/model/user_test.go b/model/user_test.go
index a3b4be091..d9c1a00b6 100644
--- a/model/user_test.go
+++ b/model/user_test.go
@@ -192,3 +192,26 @@ func TestCleanUsername(t *testing.T) {
t.Fatal("didn't clean name properly")
}
}
+
+func TestRoles(t *testing.T) {
+
+ if !IsValidRoles("admin") {
+ t.Fatal()
+ }
+
+ if IsValidRoles("junk") {
+ t.Fatal()
+ }
+
+ if IsInRole("system_admin junk", "admin") {
+ t.Fatal()
+ }
+
+ if !IsInRole("system_admin junk", "system_admin") {
+ t.Fatal()
+ }
+
+ if IsInRole("admin", "system_admin") {
+ t.Fatal()
+ }
+}