From 96f01d8c6c3dae37b6046b13d39aabc6853ba826 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 17 Feb 2017 09:33:38 -0500 Subject: Move channel permission check back to using cache (#5454) --- app/authorization.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'app/authorization.go') diff --git a/app/authorization.go b/app/authorization.go index b43d64341..4d36c63e8 100644 --- a/app/authorization.go +++ b/app/authorization.go @@ -4,6 +4,8 @@ package app import ( + "strings" + l4g "github.com/alecthomas/log4go" "github.com/mattermost/platform/model" ) @@ -32,16 +34,20 @@ func SessionHasPermissionToChannel(session model.Session, channelId string, perm return false } - channelMember, err := GetChannelMember(channelId, session.UserId) - if err == nil { - roles := channelMember.GetRoles() - if CheckIfRolesGrantPermission(roles, permission.Id) { - return true + cmc := Srv.Store.Channel().GetAllChannelMembersForUser(session.UserId, true) + + var channelRoles []string + if cmcresult := <-cmc; cmcresult.Err == nil { + ids := cmcresult.Data.(map[string]string) + if roles, ok := ids[channelId]; ok { + channelRoles = strings.Fields(roles) + if CheckIfRolesGrantPermission(channelRoles, permission.Id) { + return true + } } } - var channel *model.Channel - channel, err = GetChannel(channelId) + channel, err := GetChannel(channelId) if err == nil { return SessionHasPermissionToTeam(session, channel.TeamId, permission) } -- cgit v1.2.3-1-g7c22