From d31b3e413a71607f6f9593f414892cace955fb1a Mon Sep 17 00:00:00 2001 From: nickago Date: Thu, 16 Jul 2015 13:40:18 -0700 Subject: Moved admin checking into seperate function --- api/context.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'api/context.go') diff --git a/api/context.go b/api/context.go index bea0fbeff..0c9dee5c3 100644 --- a/api/context.go +++ b/api/context.go @@ -265,6 +265,16 @@ func (c *Context) IsSystemAdmin() bool { return false } +func (c *Context) IsTeamAdmin() bool { + if uresult := <-Srv.Store.User().Get(c.Session.UserId); uresult.Err != nil { + c.Err = uresult.Err + return false + } else { + user := uresult.Data.(*model.User) + return strings.Contains(user.Roles, model.ROLE_ADMIN) && user.TeamId == c.Session.TeamId + } +} + func (c *Context) RemoveSessionCookie(w http.ResponseWriter) { sessionCache.Remove(c.Session.Id) -- cgit v1.2.3-1-g7c22 From 41d2786e3e256acf22be18c96c036e84e0ae4fc9 Mon Sep 17 00:00:00 2001 From: nickago Date: Thu, 16 Jul 2015 13:50:20 -0700 Subject: reworked logic to stem from post --- api/context.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'api/context.go') diff --git a/api/context.go b/api/context.go index 0c9dee5c3..9f23d71a0 100644 --- a/api/context.go +++ b/api/context.go @@ -265,8 +265,8 @@ func (c *Context) IsSystemAdmin() bool { return false } -func (c *Context) IsTeamAdmin() bool { - if uresult := <-Srv.Store.User().Get(c.Session.UserId); uresult.Err != nil { +func (c *Context) IsTeamAdmin(userId string) bool { + if uresult := <-Srv.Store.User().Get(userId); uresult.Err != nil { c.Err = uresult.Err return false } else { -- cgit v1.2.3-1-g7c22 From f0841af393d1d0c48bf27b68fca3be8fde096dd6 Mon Sep 17 00:00:00 2001 From: nickago Date: Thu, 16 Jul 2015 14:47:28 -0700 Subject: Check your credentials from session --- api/context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/context.go') diff --git a/api/context.go b/api/context.go index 9f23d71a0..054e42e2e 100644 --- a/api/context.go +++ b/api/context.go @@ -271,7 +271,7 @@ func (c *Context) IsTeamAdmin(userId string) bool { return false } else { user := uresult.Data.(*model.User) - return strings.Contains(user.Roles, model.ROLE_ADMIN) && user.TeamId == c.Session.TeamId + return strings.Contains(c.Session.Roles, model.ROLE_ADMIN) && user.TeamId == c.Session.TeamId } } -- cgit v1.2.3-1-g7c22