From 2e277dd4ad96ef6f7ce3267eb05d0b84668df772 Mon Sep 17 00:00:00 2001 From: lain Date: Sun, 27 Jan 2019 21:03:15 +0100 Subject: [PATCH] Fix objects. --- lib/pleroma/spc_fixes/spc_fixes.ex | 21 +++++++++++++++++++++ test/spc_fixes_test.exs | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/lib/pleroma/spc_fixes/spc_fixes.ex b/lib/pleroma/spc_fixes/spc_fixes.ex index 41cf56fdd..86bbb7f6f 100644 --- a/lib/pleroma/spc_fixes/spc_fixes.ex +++ b/lib/pleroma/spc_fixes/spc_fixes.ex @@ -5,6 +5,7 @@ alias Pleroma.Repo alias Pleroma.User alias Pleroma.Activity +alias Pleroma.Object import Ecto.Query defmodule Pleroma.SpcFixes do @@ -87,6 +88,26 @@ def upgrade_users do ) Repo.update_all(query, []) + + # Fix objects + query = + from(a in Object, + where: fragment("?->>'actor' = ?", a.data, ^mapping[user.ap_id]), + update: [ + set: [ + data: + fragment( + "jsonb_set(jsonb_set(?, '{actor}', ?), '{to}', (?->'to')::jsonb || ?)", + a.data, + ^user.ap_id, + a.data, + ^[user.follower_address] + ) + ] + ] + ) + + Repo.update_all(query, []) end) end end diff --git a/test/spc_fixes_test.exs b/test/spc_fixes_test.exs index 76c081248..67ab54ccf 100644 --- a/test/spc_fixes_test.exs +++ b/test/spc_fixes_test.exs @@ -11,6 +11,7 @@ defmodule Pleroma.SpcFixesTest do alias Pleroma.User alias Pleroma.Activity alias Pleroma.Repo + alias Pleroma.Object import Pleroma.Factory @@ -62,5 +63,10 @@ test "resets the ap_id and follower_address of old spc users" do assert activity.data["actor"] == user.ap_id assert user.follower_address in activity.recipients assert user.follower_address in activity.data["to"] + + object = Object.get_by_ap_id(activity.data["object"]["id"]) + + assert object.data["actor"] == user.ap_id + assert user.follower_address in object.data["to"] end end