mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-11-20 00:20:59 +00:00
Mastodon API: Fix PUT /api/web/settings
This commit is contained in:
parent
2592b3c81a
commit
4c783e35c0
3 changed files with 23 additions and 4 deletions
|
@ -149,9 +149,12 @@ defmodule Pleroma.User.Info do
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
def mastodon_settings_update(info, params) do
|
def mastodon_settings_update(info, settings) do
|
||||||
|
params = %{settings: settings}
|
||||||
|
|
||||||
info
|
info
|
||||||
|> cast(params, [:settings])
|
|> cast(params, [:settings])
|
||||||
|
|> validate_required([:settings])
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_source_data(info, source_data) do
|
def set_source_data(info, source_data) do
|
||||||
|
|
|
@ -929,7 +929,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
settings:
|
settings:
|
||||||
Map.get(user.info, :settings) ||
|
user.info.settings ||
|
||||||
%{
|
%{
|
||||||
onboarded: true,
|
onboarded: true,
|
||||||
home: %{
|
home: %{
|
||||||
|
@ -978,13 +978,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
|
def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do
|
||||||
info_cng = User.Info.mastodon_settings_update(user.info, settings)
|
info_cng = User.Info.mastodon_settings_update(user.info, settings)
|
||||||
|
|
||||||
with changeset <- User.update_changeset(user),
|
with changeset <- Ecto.Changeset.change(user),
|
||||||
changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng),
|
changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng),
|
||||||
{:ok, _user} <- User.update_and_set_cache(changeset) do
|
{:ok, _user} <- User.update_and_set_cache(changeset) do
|
||||||
json(conn, %{})
|
json(conn, %{})
|
||||||
else
|
else
|
||||||
e ->
|
e ->
|
||||||
json(conn, %{error: inspect(e)})
|
conn
|
||||||
|
|> put_resp_content_type("application/json")
|
||||||
|
|> send_resp(500, Jason.encode!(%{"error" => inspect(e)}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1415,4 +1415,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||||
assert result["stats"]["user_count"] == 2
|
assert result["stats"]["user_count"] == 2
|
||||||
assert result["stats"]["status_count"] == 1
|
assert result["stats"]["status_count"] == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "put settings", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, user)
|
||||||
|
|> put("/api/web/settings", %{"data" => %{"programming" => "socks"}})
|
||||||
|
|
||||||
|
assert result = json_response(conn, 200)
|
||||||
|
|
||||||
|
user = User.get_cached_by_ap_id(user.ap_id)
|
||||||
|
assert user.info.settings == %{"programming" => "socks"}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue