Files
grafana/pkg/services/ngalert/accesscontrol/models.go
T
Yuri Tseretyan 2be7605794 Alerting: Fix fine-grained rule access control to use 403 for authorization error (#79239)
* use 403 for authorization error
* update silences API
* add ForbiddenError to rule API responses
2023-12-07 13:43:58 -05:00

29 lines
680 B
Go

package accesscontrol
import (
"fmt"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/util/errutil"
)
var (
errAuthorizationGeneric = errutil.Forbidden("alerting.unauthorized")
)
func NewAuthorizationErrorWithPermissions(action string, eval accesscontrol.Evaluator) error {
msg := fmt.Sprintf("user is not authorized to %s", action)
err := errAuthorizationGeneric.Errorf(msg)
err.PublicMessage = msg
if eval != nil {
err.PublicPayload = map[string]any{
"permissions": eval.GoString(),
}
}
return err
}
func NewAuthorizationErrorGeneric(action string) error {
return NewAuthorizationErrorWithPermissions(action, nil)
}