From a003bdc30af6cd77b36c7f2c32c60b32e084cf80 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 26 May 2018 15:03:32 +0000 Subject: [PATCH 1/4] activitypub transmogrifier: learn locked state in Update messages --- lib/pleroma/web/activity_pub/transmogrifier.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 3c9377be9..4e07dffe0 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -252,11 +252,12 @@ def handle_incoming( {:ok, new_user_data} = ActivityPub.user_data_from_user_object(object) banner = new_user_data[:info]["banner"] + locked = new_user_data[:info]["manuallyApprovesFollowers"] || false update_data = new_user_data |> Map.take([:name, :bio, :avatar]) - |> Map.put(:info, Map.merge(actor.info, %{"banner" => banner})) + |> Map.put(:info, Map.merge(actor.info, %{"banner" => banner, "locked" => locked})) actor |> User.upgrade_changeset(update_data) From 47c7e259c4f9f57092a873830b668296f7bee450 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 8 Jun 2018 02:18:47 +0000 Subject: [PATCH 2/4] activitypub transmogrifier: fix locked account state from being clobbered --- lib/pleroma/web/activity_pub/transmogrifier.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 4e07dffe0..75ba36729 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -252,7 +252,7 @@ def handle_incoming( {:ok, new_user_data} = ActivityPub.user_data_from_user_object(object) banner = new_user_data[:info]["banner"] - locked = new_user_data[:info]["manuallyApprovesFollowers"] || false + locked = new_user_data[:info]["locked"] update_data = new_user_data From 299ef74f2e840ebdb79fce13a2f56c55563219a9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 8 Jun 2018 02:28:08 +0000 Subject: [PATCH 3/4] tests: add regression test for locking/unlocking account updates --- test/web/activity_pub/transmogrifier_test.exs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 384844095..7e771b9f8 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -266,6 +266,29 @@ test "it works for incoming update activities" do assert user.bio == "

Some bio

" end + test "it works for incoming update activities which lock the account" do + data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!() + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!() + + object = + update_data["object"] + |> Map.put("actor", data["actor"]) + |> Map.put("id", data["actor"]) + |> Map.put("manuallyApprovesFollowers", true) + + update_data = + update_data + |> Map.put("actor", data["actor"]) + |> Map.put("object", object) + + {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data) + + user = User.get_cached_by_ap_id(data["actor"]) + assert user.info["locked"] == true + end + test "it works for incoming deletes" do activity = insert(:note_activity) From 1e9dd6fbc2ecf0c3e7528c40f3145b2a9e591d7a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 8 Jun 2018 02:47:07 +0000 Subject: [PATCH 4/4] user: fix maybe_direct_follow() after user_info() refactoring broke it slightly --- lib/pleroma/user.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index b1b935a0f..828370cab 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -174,7 +174,7 @@ def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do should_direct_follow = cond do # if the account is locked, don't pre-create the relationship - user_info["locked"] == true -> + user_info[:locked] == true -> false # if the users are blocking each other, we shouldn't even be here, but check for it anyway @@ -193,7 +193,7 @@ def maybe_direct_follow(%User{} = follower, %User{info: info} = followed) do if should_direct_follow do follow(follower, followed) else - follower + {:ok, follower} end end