mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 04:12:09 +08:00
AccessControl: Clear user permission cache for update org user role (#62745)
* clear user permission cache for update org user role * check enabled state of ac
This commit is contained in:
@ -381,16 +381,23 @@ func (hs *HTTPServer) UpdateOrgUser(c *contextmodel.ReqContext) response.Respons
|
||||
|
||||
func (hs *HTTPServer) updateOrgUserHelper(c *contextmodel.ReqContext, cmd org.UpdateOrgUserCommand) response.Response {
|
||||
if !cmd.Role.IsValid() {
|
||||
return response.Error(400, "Invalid role specified", nil)
|
||||
return response.Error(http.StatusBadRequest, "Invalid role specified", nil)
|
||||
}
|
||||
if !c.OrgRole.Includes(cmd.Role) && !c.IsGrafanaAdmin {
|
||||
return response.Error(http.StatusForbidden, "Cannot assign a role higher than user's role", nil)
|
||||
}
|
||||
if err := hs.orgService.UpdateOrgUser(c.Req.Context(), &cmd); err != nil {
|
||||
if errors.Is(err, org.ErrLastOrgAdmin) {
|
||||
return response.Error(400, "Cannot change role so that there is no organization admin left", nil)
|
||||
return response.Error(http.StatusBadRequest, "Cannot change role so that there is no organization admin left", nil)
|
||||
}
|
||||
return response.Error(500, "Failed update org user", err)
|
||||
return response.Error(http.StatusInternalServerError, "Failed update org user", err)
|
||||
}
|
||||
|
||||
if !hs.accesscontrolService.IsDisabled() {
|
||||
hs.accesscontrolService.ClearUserPermissionCache(&user.SignedInUser{
|
||||
UserID: cmd.UserID,
|
||||
OrgID: cmd.OrgID,
|
||||
})
|
||||
}
|
||||
|
||||
return response.Success("Organization user updated")
|
||||
|
Reference in New Issue
Block a user