From 2ae1128d9f7a89aff6ba7fb3d486a00f76dbc28b Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 6 Dec 2018 17:42:07 +0300 Subject: [PATCH] MastoAPI: Fix put_settings --- lib/pleroma/user.ex | 4 ---- lib/pleroma/user/info.ex | 5 +++++ lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 8 +++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 74ae5ef0d..9da674982 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -62,10 +62,6 @@ defmodule Pleroma.User do |> validate_required([:following]) end - def info_changeset(struct, params \\ %{}) do - raise "NOT VALID ANYMORE" - end - def user_info(%User{} = user) do oneself = if user.local, do: 1, else: 0 diff --git a/lib/pleroma/user/info.ex b/lib/pleroma/user/info.ex index 7a99787f8..d81b45b8d 100644 --- a/lib/pleroma/user/info.ex +++ b/lib/pleroma/user/info.ex @@ -149,6 +149,11 @@ defmodule Pleroma.User.Info do ]) end + def mastodon_settings_update(info, params) do + info + |> cast(params, [:settings]) + end + def set_source_data(info, source_data) do params = %{source_data: source_data} diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index eecfc742b..e8dd9db15 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -970,9 +970,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def put_settings(%{assigns: %{user: user}} = conn, %{"data" => settings} = _params) do - with new_info <- Map.put(user.info, "settings", settings), - change <- User.info_changeset(user, %{info: new_info}), - {:ok, _user} <- User.update_and_set_cache(change) do + info_cng = User.Info.mastodon_settings_update(user.info, settings) + + with changeset <- User.update_changeset(user), + changeset <- Ecto.Changeset.put_embed(changeset, :info, info_cng), + {:ok, user} <- User.update_and_set_cache(changeset) do conn |> json(%{}) else -- 2.45.2