[release-11.3.5] Service Accounts: Do not show error pop-ups for Service Account and Renderer UI flows (#101791)

* Service Accounts: Don't show error pop-ups for Service Account and Renderer UI flows (#101679)

don't show error pop-ups for SAs and renderer

(cherry picked from commit f0d260ba5b)

* Service Accounts: Don't show error pop-ups for Service Account and Renderer UI flows (#101776)

* don't show error pop-ups for SAs and renderer

* only hide non 4xx error pop'ups

* linting

(cherry picked from commit 392124de00)
pull/101831/head
Ieva 4 months ago committed by GitHub
parent 534a96a72c
commit 9f1e8e66be
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 22
      pkg/api/user.go
  2. 10
      public/app/core/services/backend_srv.ts

@ -150,7 +150,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
}
@ -350,7 +350,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
}
@ -370,7 +370,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
}
@ -480,7 +480,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
}
@ -505,7 +505,8 @@ func (hs *HTTPServer) ChangeActiveOrgAndRedirectToHome(c *contextmodel.ReqContex
}
if !c.SignedInUser.IsIdentityType(claims.TypeUser) {
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
}
@ -549,7 +550,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
}
@ -585,7 +586,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
}
@ -615,7 +616,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
}
@ -628,9 +629,10 @@ 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) {
if !c.SignedInUser.IsIdentityType(claims.TypeUser) {
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 := c.SignedInUser.GetInternalID()

@ -269,6 +269,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;
}

Loading…
Cancel
Save