forked from grafana.jool/grafana-jool
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
731 B
36 lines
731 B
package teamguardian
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
func CanAdmin(ctx context.Context, 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.DispatchCtx(ctx, &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
|
|
}
|
|
|