mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 10:20:29 -06: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:
parent
6840cc11ff
commit
12d192d80e
@ -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")
|
||||
|
@ -630,6 +630,7 @@ func TestOrgUsersAPIEndpointWithSetPerms_AccessControl(t *testing.T) {
|
||||
ExpectedUser: &user.User{},
|
||||
ExpectedSignedInUser: userWithPermissions(1, tt.permissions),
|
||||
}
|
||||
hs.accesscontrolService = &actest.FakeService{}
|
||||
})
|
||||
|
||||
u := userWithPermissions(1, tt.permissions)
|
||||
@ -703,6 +704,7 @@ func TestPatchOrgUsersAPIEndpoint_AccessControl(t *testing.T) {
|
||||
hs.Cfg.RBACEnabled = tt.enableAccessControl
|
||||
hs.orgService = &orgtest.FakeOrgService{}
|
||||
hs.authInfoService = &logintest.AuthInfoServiceFake{}
|
||||
hs.accesscontrolService = &actest.FakeService{}
|
||||
hs.userService = &usertest.FakeUserService{
|
||||
ExpectedUser: &user.User{},
|
||||
ExpectedSignedInUser: userWithPermissions(1, tt.permissions),
|
||||
|
Loading…
Reference in New Issue
Block a user