grafana/pkg/services/accesscontrol/resourcepermissions/middleware.go
idafurjes a14621fff6
Chore: Add user service method SetUsingOrg and GetSignedInUserWithCacheCtx (#53343)
* Chore: Add user service method SetUsingOrg

* Chore: Add user service method GetSignedInUserWithCacheCtx

* Use method GetSignedInUserWithCacheCtx from user service

* Fix lint after rebase

* Fix lint

* Fix lint error

* roll back some changes

* Roll back changes in api and middleware

* Add xorm tags to SignedInUser ID fields
2022-08-11 13:28:55 +02:00

39 lines
1.0 KiB
Go

package resourcepermissions
import (
"net/http"
"github.com/grafana/grafana/pkg/models"
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/util"
"github.com/grafana/grafana/pkg/web"
)
// solveInheritedScopes will add the inherited scopes to the context param by prefix
// Ex: params["folders:uid:"] = "folders:uid:BCeknZL7k"
func solveInheritedScopes(solve InheritedScopesSolver) web.Handler {
return func(c *models.ReqContext) {
if solve != nil && util.IsValidShortUID(web.Params(c.Req)[":resourceID"]) {
params := web.Params(c.Req)
scopes, err := solve(c.Req.Context(), c.OrgID, params[":resourceID"])
if err != nil {
c.JsonApiErr(http.StatusNotFound, "Resource not found", err)
return
}
for _, scope := range scopes {
params[ac.ScopePrefix(scope)] = scope
}
web.SetURLParams(c.Req, params)
}
}
}
func disableMiddleware(shouldDisable bool) web.Handler {
return func(c *models.ReqContext) {
if shouldDisable {
c.Resp.WriteHeader(http.StatusNotFound)
return
}
}
}