RBAC: Allow listing user permissions with scope (#57538)
* RBAC: Allow listing user permissions with scope * Add docs * Document the api endpoint * Update docs Co-authored-by: Garrett Guillotte <100453168+gguillotte-grafana@users.noreply.github.com> * Split endpoint in two * document reloadcache * Update docs/sources/developers/http_api/access_control.md * Fix test * Ieva's nit. * Simplify flag description Co-authored-by: Garrett Guillotte <100453168+gguillotte-grafana@users.noreply.github.com>
This commit is contained in:
co-authored by
Garrett Guillotte
parent
f1f0a6f88b
commit
101ce57a94
@@ -24,12 +24,14 @@ type AccessControlAPI struct {
|
||||
|
||||
func (api *AccessControlAPI) RegisterAPIEndpoints() {
|
||||
// Users
|
||||
api.RouteRegister.Get("/api/access-control/user/permissions",
|
||||
middleware.ReqSignedIn, routing.Wrap(api.getUsersPermissions))
|
||||
api.RouteRegister.Group("/api/access-control", func(rr routing.RouteRegister) {
|
||||
rr.Get("/user/actions", middleware.ReqSignedIn, routing.Wrap(api.getUserActions))
|
||||
rr.Get("/user/permissions", middleware.ReqSignedIn, routing.Wrap(api.getUserPermissions))
|
||||
})
|
||||
}
|
||||
|
||||
// GET /api/access-control/user/permissions
|
||||
func (api *AccessControlAPI) getUsersPermissions(c *models.ReqContext) response.Response {
|
||||
// GET /api/access-control/user/actions
|
||||
func (api *AccessControlAPI) getUserActions(c *models.ReqContext) response.Response {
|
||||
reloadCache := c.QueryBool("reloadcache")
|
||||
permissions, err := api.Service.GetUserPermissions(c.Req.Context(),
|
||||
c.SignedInUser, ac.Options{ReloadCache: reloadCache})
|
||||
@@ -39,3 +41,15 @@ func (api *AccessControlAPI) getUsersPermissions(c *models.ReqContext) response.
|
||||
|
||||
return response.JSON(http.StatusOK, ac.BuildPermissionsMap(permissions))
|
||||
}
|
||||
|
||||
// GET /api/access-control/user/permissions
|
||||
func (api *AccessControlAPI) getUserPermissions(c *models.ReqContext) response.Response {
|
||||
reloadCache := c.QueryBool("reloadcache")
|
||||
permissions, err := api.Service.GetUserPermissions(c.Req.Context(),
|
||||
c.SignedInUser, ac.Options{ReloadCache: reloadCache})
|
||||
if err != nil {
|
||||
response.JSON(http.StatusInternalServerError, err)
|
||||
}
|
||||
|
||||
return response.JSON(http.StatusOK, ac.GroupScopesByAction(permissions))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user