MastoAPI: Fix put_settings
authorrinpatch <rinpatch@sdf.org>
Thu, 6 Dec 2018 14:42:07 +0000 (17:42 +0300)
committerrinpatch <rinpatch@sdf.org>
Thu, 6 Dec 2018 14:42:07 +0000 (17:42 +0300)
lib/pleroma/user.ex
lib/pleroma/user/info.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex

index 74ae5ef0d7e30c9905fc32e1ddb21fc78e7d9aeb..9da674982a5e5a4ace8c0da87ab021c21f9b8bfe 100644 (file)
@@ -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
 
index 7a99787f81a78405e3253cbb07a290990fc68fff..d81b45b8d077322a3645d74442c82d638f8aed40 100644 (file)
@@ -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}
 
index eecfc742b2096cd3b0395684401cb6b5d2d41d04..e8dd9db158f9a4c00366d3387d69d25043deca52 100644 (file)
@@ -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