2019-03-12 07:59:53 -05:00
|
|
|
package teamguardian
|
2019-03-08 07:37:21 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
|
|
)
|
|
|
|
|
2019-03-14 06:10:10 -05:00
|
|
|
func CanAdmin(bus bus.Bus, orgId int64, teamId int64, user *m.SignedInUser) error {
|
2019-03-08 08:46:15 -06:00
|
|
|
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 {
|
2019-03-13 10:32:59 -05:00
|
|
|
if member.UserId == user.UserId && member.Permission == m.PERMISSION_ADMIN {
|
2019-03-08 08:46:15 -06:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m.ErrNotAllowedToUpdateTeam
|
|
|
|
}
|