grafana/pkg/services/teamguardian/team.go
2020-02-29 13:35:15 +01:00

35 lines
690 B
Go

package teamguardian
import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
)
func CanAdmin(bus bus.Bus, orgId int64, teamId int64, user *models.SignedInUser) error {
if user.OrgRole == models.ROLE_ADMIN {
return nil
}
if user.OrgId != orgId {
return models.ErrNotAllowedToUpdateTeamInDifferentOrg
}
cmd := models.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 == models.PERMISSION_ADMIN {
return nil
}
}
return models.ErrNotAllowedToUpdateTeam
}