verdier opened a new pull request, #44238:
URL: https://github.com/apache/superset/pull/44238
### SUMMARY
Two frontend flows throw away the response body on failure and show a fixed
toast, so when the backend refuses the request with an explicit message, the
user never sees why:
1. **Dashboard header Draft/Published toggle.** `savePublished`
(`src/dashboard/actions/dashboardState.ts`) always shows "You do not have
permissions to edit this dashboard.", whatever the status and body: a
validation error, a refusal from a security manager hook or a `before_request`
guard, even a 5xx or a network error.
2. **User info modal (edit user / reset password).** `UserInfoModal` shows
"Something went wrong while saving the user info" on any failure of `PUT
/api/v1/me/`, including the 400 validation errors the endpoint returns itself
(field length, `current_password`, password complexity when enabled).
Both now read the error with `getClientErrorObject` and show its `error`
text when there is one, like neighbouring flows already do:
- `savePublished` follows `saveDashboardRequest`'s `onError` in the same
file and `PropertiesModal`'s `handleErrorResponse` (same `PUT
/api/v1/dashboard/<id>` endpoint): the stock `{"message": "Forbidden"}` body
still maps to the existing permission toast, anything else shows the server's
text.
- `UserInfoModal` uses the `error || t(generic)` pattern of
`URLShortLinkButton`, and keeps the generic toast when the helper finds no
message.
No new strings, no change on success. The "still the current dashboard"
check in `savePublished` now runs after the body is read, right before the
dispatch.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before: any failure shows the fixed toast ("You do not have permissions to
edit this dashboard." / "Something went wrong while saving the user info").
After: the toast shows the message from the response body, e.g. "Only owners
can publish this dashboard"; the default 403 body and bodies with no message
keep the previous toast.
### TESTING INSTRUCTIONS
Unit tests:
```bash
cd superset-frontend
npm run test -- src/dashboard/actions/dashboardState.test.ts
src/features/userInfo/UserInfoModal.test.tsx
```
- `dashboardState.test.ts`: a 403 with a JSON message shows that message;
the default `{"message": "Forbidden"}` 403 and a body without a message keep
the permission toast. The existing race-condition tests are unchanged and still
pass.
- `UserInfoModal.test.tsx` (new): a JSON message is shown; a body without a
message keeps the generic toast.
Manual:
1. Make `PUT /api/v1/dashboard/<id>` refuse with a message, e.g. a
`before_request` hook in `superset_config.py` returning `jsonify(message="Only
owners can publish this dashboard"), 403` for that route. Toggle
Draft/Published in the dashboard header: the toast shows that message. Remove
the hook and toggle as a user without edit rights: the toast still reads "You
do not have permissions to edit this dashboard."
2. On the user info page, "Edit user", set a first name longer than 64
characters and save: the toast reads "Length must be between 1 and 64." instead
of "Something went wrong while saving the user info".
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [x] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
Note: since #42934, `PUT /api/v1/me/` requires `current_password` whenever
`password` is set, but the reset password modal has no such field, so a reset
by a user who already has a password always fails. With this change the toast
reads "This field is required to change the password." instead of the generic
message. Adding the field to the modal is a separate fix and is not part of
this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]