[2.11.x] Fix 500 error when change default visibility #3605

Open
mei wants to merge 1 commit from mei/pleroma-fe:fix/profile-config-json-2.11.x into 2.11.x
First-time contributor

Hi. I am running small Pleroma instance (2.11.1, bundled FE 2.11.4).
When I change default post visibility in Settings → Composing, it always fails. PATCH /api/v1/accounts/update_credentials returns 500 error and the setting goes back to old value.

I checked the code. defaultApi in profileConfig.js makes params like { source: { privacy: ... } } and send it with updateProfile, but updateProfile uses FormData. FormData changes the nested object to string [object Object], so backend receives source=[object Object] and crash:

** (FunctionClauseError) no function clause matching in Access.get/3
    (elixir 1.17.3) lib/access.ex:320: Access.get("[object Object]", "privacy", nil)
    lib/pleroma/web/mastodon_api/controllers/account_controller.ex:223: Pleroma.Web.MastodonAPI.AccountController.update_credentials/2

Also browser console shows warning "Object detected in updateProfile API call...".

In develop this is already fixed by 316bf4c226 (it uses updateProfileJSON). But this fix is part of big vuex removal / Pinia migration (#3571), so I think it is not in 2.11.x. This PR is only same change for 2.11.x.
updateProfileJSON is already exist in src/api/user.js and return value is same shape, so I didn't change other part.

Notes:

  • defaultNSFW (source.sensitive) also use same path, so the request is fixed too. But backend still ignore this field (pleroma/pleroma#2837).
  • Other profile options (locked, discoverable etc.) are also sent as JSON now. It is same as develop.

If possible, please include this in 2.11.5.
Thank you! (and sorry for my English)

Hi. I am running small Pleroma instance (2.11.1, bundled FE 2.11.4). When I change default post visibility in Settings → Composing, it always fails. `PATCH /api/v1/accounts/update_credentials` returns 500 error and the setting goes back to old value. I checked the code. `defaultApi` in `profileConfig.js` makes params like `{ source: { privacy: ... } }` and send it with `updateProfile`, but `updateProfile` uses FormData. FormData changes the nested object to string `[object Object]`, so backend receives `source=[object Object]` and crash: ``` ** (FunctionClauseError) no function clause matching in Access.get/3 (elixir 1.17.3) lib/access.ex:320: Access.get("[object Object]", "privacy", nil) lib/pleroma/web/mastodon_api/controllers/account_controller.ex:223: Pleroma.Web.MastodonAPI.AccountController.update_credentials/2 ``` Also browser console shows warning "Object detected in updateProfile API call...". In develop this is already fixed by 316bf4c226 (it uses `updateProfileJSON`). But this fix is part of big vuex removal / Pinia migration (#3571), so I think it is not in 2.11.x. This PR is only same change for 2.11.x. `updateProfileJSON` is already exist in `src/api/user.js` and return value is same shape, so I didn't change other part. Notes: - defaultNSFW (`source.sensitive`) also use same path, so the request is fixed too. But backend still ignore this field (pleroma/pleroma#2837). - Other profile options (`locked`, `discoverable` etc.) are also sent as JSON now. It is same as develop. If possible, please include this in 2.11.5. Thank you! (and sorry for my English)
Fix 500 error when change default visibility
Some checks are pending
ci/woodpecker/pr/build Pipeline is pending approval
ci/woodpecker/pr/changelog Pipeline is pending approval
ci/woodpecker/pr/lint Pipeline is pending approval
ci/woodpecker/pr/test-e2e Pipeline is pending approval
ci/woodpecker/pr/test Pipeline is pending approval
907bea6ba1
defaultApi in profileConfig makes nested params by lodash.set
(defaultScope -> source.privacy) and send it with updateProfile,
but updateProfile uses multipart/form-data. FormData changes the
nested object to string, so the request has source=[object Object]
and backend returns 500 (FunctionClauseError in
AccountController.update_credentials).

Use updateProfileJSON instead. It is same as develop (316bf4c226).
Some checks are pending
ci/woodpecker/pr/build Pipeline is pending approval
ci/woodpecker/pr/changelog Pipeline is pending approval
ci/woodpecker/pr/lint Pipeline is pending approval
ci/woodpecker/pr/test-e2e Pipeline is pending approval
ci/woodpecker/pr/test Pipeline is pending approval
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u fix/profile-config-json-2.11.x:mei-fix/profile-config-json-2.11.x
git switch mei-fix/profile-config-json-2.11.x

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 2.11.x
git merge --no-ff mei-fix/profile-config-json-2.11.x
git switch mei-fix/profile-config-json-2.11.x
git rebase 2.11.x
git switch 2.11.x
git merge --ff-only mei-fix/profile-config-json-2.11.x
git switch mei-fix/profile-config-json-2.11.x
git rebase 2.11.x
git switch 2.11.x
git merge --no-ff mei-fix/profile-config-json-2.11.x
git switch 2.11.x
git merge --squash mei-fix/profile-config-json-2.11.x
git switch 2.11.x
git merge --ff-only mei-fix/profile-config-json-2.11.x
git switch 2.11.x
git merge mei-fix/profile-config-json-2.11.x
git push origin 2.11.x
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pleroma/pleroma-fe!3605
No description provided.