[release-11.1.13] Service Accounts: Do not show error pop-ups for Service Account and Renderer UI flows (#101796)
* backport fixes from https://github.com/grafana/grafana/pull/101679 * Update user.go Fix an error * fix more errors
This commit is contained in:
+12
-10
@@ -151,7 +151,7 @@ func (hs *HTTPServer) UpdateSignedInUser(c *contextmodel.ReqContext) response.Re
|
||||
cmd.Email = strings.TrimSpace(cmd.Email)
|
||||
cmd.Login = strings.TrimSpace(cmd.Login)
|
||||
|
||||
userID, errResponse := getUserID(c)
|
||||
userID, errResponse := hs.getUserID(c)
|
||||
if errResponse != nil {
|
||||
return errResponse
|
||||
}
|
||||
@@ -352,7 +352,7 @@ func (hs *HTTPServer) UpdateUserEmail(c *contextmodel.ReqContext) response.Respo
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetSignedInUserOrgList(c *contextmodel.ReqContext) response.Response {
|
||||
userID, errResponse := getUserID(c)
|
||||
userID, errResponse := hs.getUserID(c)
|
||||
if errResponse != nil {
|
||||
return errResponse
|
||||
}
|
||||
@@ -372,7 +372,7 @@ func (hs *HTTPServer) GetSignedInUserOrgList(c *contextmodel.ReqContext) respons
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) GetSignedInUserTeamList(c *contextmodel.ReqContext) response.Response {
|
||||
userID, errResponse := getUserID(c)
|
||||
userID, errResponse := hs.getUserID(c)
|
||||
if errResponse != nil {
|
||||
return errResponse
|
||||
}
|
||||
@@ -482,7 +482,7 @@ func (hs *HTTPServer) UserSetUsingOrg(c *contextmodel.ReqContext) response.Respo
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
}
|
||||
|
||||
userID, errResponse := getUserID(c)
|
||||
userID, errResponse := hs.getUserID(c)
|
||||
if errResponse != nil {
|
||||
return errResponse
|
||||
}
|
||||
@@ -508,7 +508,8 @@ func (hs *HTTPServer) ChangeActiveOrgAndRedirectToHome(c *contextmodel.ReqContex
|
||||
|
||||
namespace, identifier := c.SignedInUser.GetNamespacedID()
|
||||
if namespace != identity.NamespaceUser {
|
||||
c.JsonApiErr(http.StatusForbidden, "Endpoint only available for users", nil)
|
||||
hs.log.Debug("Requested endpoint only available to users")
|
||||
c.JsonApiErr(http.StatusNotModified, "Endpoint only available for users", nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -552,7 +553,7 @@ func (hs *HTTPServer) ChangeUserPassword(c *contextmodel.ReqContext) response.Re
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
|
||||
userID, errResponse := getUserID(c)
|
||||
userID, errResponse := hs.getUserID(c)
|
||||
if errResponse != nil {
|
||||
return errResponse
|
||||
}
|
||||
@@ -588,7 +589,7 @@ func (hs *HTTPServer) SetHelpFlag(c *contextmodel.ReqContext) response.Response
|
||||
return response.Error(http.StatusBadRequest, "id is invalid", err)
|
||||
}
|
||||
|
||||
userID, errResponse := getUserID(c)
|
||||
userID, errResponse := hs.getUserID(c)
|
||||
if errResponse != nil {
|
||||
return errResponse
|
||||
}
|
||||
@@ -618,7 +619,7 @@ func (hs *HTTPServer) SetHelpFlag(c *contextmodel.ReqContext) response.Response
|
||||
// 403: forbiddenError
|
||||
// 500: internalServerError
|
||||
func (hs *HTTPServer) ClearHelpFlags(c *contextmodel.ReqContext) response.Response {
|
||||
userID, errResponse := getUserID(c)
|
||||
userID, errResponse := hs.getUserID(c)
|
||||
if errResponse != nil {
|
||||
return errResponse
|
||||
}
|
||||
@@ -631,10 +632,11 @@ func (hs *HTTPServer) ClearHelpFlags(c *contextmodel.ReqContext) response.Respon
|
||||
return response.JSON(http.StatusOK, &util.DynMap{"message": "Help flag set", "helpFlags1": flags})
|
||||
}
|
||||
|
||||
func getUserID(c *contextmodel.ReqContext) (int64, *response.NormalResponse) {
|
||||
func (hs *HTTPServer) getUserID(c *contextmodel.ReqContext) (int64, *response.NormalResponse) {
|
||||
namespace, identifier := c.SignedInUser.GetNamespacedID()
|
||||
if namespace != identity.NamespaceUser {
|
||||
return 0, response.Error(http.StatusForbidden, "Endpoint only available for users", nil)
|
||||
hs.log.Debug("Requested endpoint only available to users")
|
||||
return 0, response.Error(http.StatusNotModified, "Endpoint only available for users", nil)
|
||||
}
|
||||
|
||||
userID, err := identity.IntIdentifier(namespace, identifier)
|
||||
|
||||
@@ -274,6 +274,16 @@ export class BackendSrv implements BackendService {
|
||||
}
|
||||
|
||||
showErrorAlert(config: BackendSrvRequest, err: FetchError) {
|
||||
// do not show non-user error alerts for api keys or render tokens, they are used for kiosk mode and reporting and can't react to error pop-ups
|
||||
if (
|
||||
(err.status < 400 || err.status >= 500) &&
|
||||
this.dependencies.contextSrv.isSignedIn &&
|
||||
(this.dependencies.contextSrv.user.authenticatedBy === 'apikey' ||
|
||||
this.dependencies.contextSrv.user.authenticatedBy === 'render')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.showErrorAlert === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user