Skip to content

Commit

Permalink
Move channel permission check back to using cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilander committed Feb 17, 2017
1 parent 48b785a commit 56f2f3c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/authorization.go
Expand Up @@ -4,6 +4,8 @@
package app

import (
"strings"

l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/model"
)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 56f2f3c

Please sign in to comment.