Fix user updating from AP.
authorlain <lain@soykaf.club>
Sun, 18 Nov 2018 21:15:03 +0000 (22:15 +0100)
committerlain <lain@soykaf.club>
Sun, 18 Nov 2018 21:15:03 +0000 (22:15 +0100)
lib/pleroma/user.ex
lib/pleroma/user/info.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
test/user_test.exs

index e71b33304f4f16e65ad0f3481cc9f0eeef6e71e4..565218b4cbe175c232fa071d9b901631d0536ef9 100644 (file)
@@ -128,12 +128,17 @@ defmodule Pleroma.User do
       params
       |> Map.put(:last_refreshed_at, NaiveDateTime.utc_now())
 
+    info_cng =
+      struct.info
+      |> User.Info.user_upgrade(params[:info])
+
     struct
-    |> cast(params, [:bio, :name, :info, :follower_address, :avatar, :last_refreshed_at])
+    |> cast(params, [:bio, :name, :follower_address, :avatar, :last_refreshed_at])
     |> unique_constraint(:nickname)
     |> validate_format(:nickname, ~r/^[a-zA-Z\d]+$/)
     |> validate_length(:bio, max: 5000)
     |> validate_length(:name, max: 100)
+    |> put_embed(:info, info_cng)
   end
 
   def password_update_changeset(struct, params) do
index 4a4c620ed3facc3b80bc0522aafedbb34fd7647b..b664af81c033022ad15e326aca873946e0cf129f 100644 (file)
@@ -90,4 +90,10 @@ defmodule Pleroma.User.Info do
     info
     |> cast(params, [:source_data])
   end
+
+  # Receives data from user_data_from_user_object
+  def user_upgrade(info, params) do
+    info
+    |> cast(params, [:ap_enabled, :source_data, :banner, :locked])
+  end
 end
index 5864855b0bb8a8f420ec90c2fa3adc00f4b621ec..2d11c40c5396c80419b3410332f4b0a7a0bc0755 100644 (file)
@@ -850,10 +850,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   def upgrade_user_from_ap_id(ap_id, async \\ true) do
     with %User{local: false} = user <- User.get_by_ap_id(ap_id),
          {:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id) do
-      data =
-        data
-        |> Map.put(:info, Map.merge(user.info, data[:info]))
-
       already_ap = User.ap_enabled?(user)
 
       {:ok, user} =
index f37f4521d4de48c82882209c6df13381731f8706..f345f001f058ade6b95eaf691d8d374f40dc0499 100644 (file)
@@ -185,12 +185,14 @@ defmodule Pleroma.UserTest do
           local: false,
           nickname: "admin@mastodon.example.org",
           ap_id: "http://mastodon.example.org/users/admin",
-          last_refreshed_at: a_week_ago
+          last_refreshed_at: a_week_ago,
+          info: %{}
         )
 
       assert orig_user.last_refreshed_at == a_week_ago
 
       user = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
+      assert user.info.source_data["endpoints"]
 
       refute user.last_refreshed_at == orig_user.last_refreshed_at
     end