Chore: Port user services to identity.Requester (#73851)

* port api key api to signedinuser

* port users to signed in user interface

* fix tests
This commit is contained in:
Jo
2023-08-28 10:42:24 +02:00
committed by GitHub
parent 01d98114b9
commit 5eed495cce
11 changed files with 192 additions and 72 deletions
+10 -2
View File
@@ -14,6 +14,7 @@ import (
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/auth"
"github.com/grafana/grafana/pkg/services/auth/identity"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/grafana/grafana/pkg/services/login"
"github.com/grafana/grafana/pkg/services/org"
@@ -384,8 +385,15 @@ func (hs *HTTPServer) AdminLogoutUser(c *contextmodel.ReqContext) response.Respo
return response.Error(http.StatusBadRequest, "id is invalid", err)
}
if c.UserID == userID {
return response.Error(400, "You cannot logout yourself", nil)
namespace, identifier := c.SignedInUser.GetNamespacedID()
if namespace == identity.NamespaceUser {
activeUserID, err := identity.IntIdentifier(namespace, identifier)
if err != nil {
return response.Error(http.StatusInternalServerError, "Failed to parse active user id", err)
}
if activeUserID == userID {
return response.Error(http.StatusBadRequest, "You cannot logout yourself", nil)
}
}
return hs.logoutUserFromAllDevicesInternal(c.Req.Context(), userID)