mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* AccessControl: Add endpoint to get user permissions Co-authored-by: ievaVasiljeva <ieva.vasiljeva@grafana.com> Co-authored-by: Kalle Persson <kalle.persson@grafana.com> Co-authored-by: Eric Leijonmarck <eric.leijonmarck@gmail.com> Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com> * Fix SA tests * Linter is wrong :p * Wait I was wrong * Adding the route for teams:creator too Co-authored-by: ievaVasiljeva <ieva.vasiljeva@grafana.com> Co-authored-by: Kalle Persson <kalle.persson@grafana.com> Co-authored-by: Eric Leijonmarck <eric.leijonmarck@gmail.com> Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com>
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/grafana/grafana/pkg/api/response"
|
|
"github.com/grafana/grafana/pkg/api/routing"
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
|
|
)
|
|
|
|
type AccessControlAPI struct {
|
|
RouteRegister routing.RouteRegister
|
|
AccessControl ac.AccessControl
|
|
}
|
|
|
|
func (api *AccessControlAPI) RegisterAPIEndpoints() {
|
|
// Users
|
|
api.RouteRegister.Get("/api/access-control/user/permissions",
|
|
middleware.ReqSignedIn, routing.Wrap(api.getUsersPermissions))
|
|
}
|
|
|
|
// GET /api/access-control/user/permissions
|
|
func (api *AccessControlAPI) getUsersPermissions(c *models.ReqContext) response.Response {
|
|
reloadCache := c.QueryBool("reloadcache")
|
|
permissions, err := api.AccessControl.GetUserPermissions(c.Req.Context(),
|
|
c.SignedInUser, ac.Options{ReloadCache: reloadCache})
|
|
if err != nil {
|
|
response.JSON(http.StatusInternalServerError, err)
|
|
}
|
|
|
|
return response.JSON(http.StatusOK, ac.BuildPermissionsMap(permissions))
|
|
}
|