grafana/pkg/services/teamguardian/team.go

35 lines
656 B
Go
Raw Normal View History

package teamguardian
2019-03-08 07:37:21 -06:00
import (
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
)
func CanAdmin(orgId int64, teamId int64, user *m.SignedInUser) error {
if user.OrgRole == m.ROLE_ADMIN {
return nil
}
if user.OrgId != orgId {
return m.ErrNotAllowedToUpdateTeamInDifferentOrg
}
cmd := m.GetTeamMembersQuery{
OrgId: orgId,
TeamId: teamId,
UserId: user.UserId,
}
if err := bus.Dispatch(&cmd); err != nil {
return err
}
for _, member := range cmd.Result {
if member.UserId == user.UserId && member.Permission == int64(m.PERMISSION_ADMIN) {
return nil
}
}
return m.ErrNotAllowedToUpdateTeam
}