CommonValidations: Treat deactivated users as not present.
authorlain <lain@soykaf.club>
Tue, 4 Aug 2020 12:17:03 +0000 (14:17 +0200)
committerlain <lain@soykaf.club>
Tue, 4 Aug 2020 12:17:03 +0000 (14:17 +0200)
lib/pleroma/web/activity_pub/object_validators/common_validations.ex
test/web/activity_pub/transmogrifier/chat_message_test.exs

index aeef31945dab440ec462952a35cac3be8126bbe6..bd46f8034ddf4d2e26399c655413fad794e78730 100644 (file)
@@ -34,10 +34,15 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations do
 
     cng
     |> validate_change(field_name, fn field_name, actor ->
-      if User.get_cached_by_ap_id(actor) do
-        []
-      else
-        [{field_name, "can't find user"}]
+      case User.get_cached_by_ap_id(actor) do
+        %User{deactivated: true} ->
+          [{field_name, "user is deactivated"}]
+
+        %User{} ->
+          []
+
+        _ ->
+          [{field_name, "can't find user"}]
       end
     end)
   end
index d6736dc3e9c377a61c3318d39ddb107a5784b819..31274c067dc0d1941361f0b52cbf0789e83173b8 100644 (file)
@@ -124,6 +124,24 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
       {:ok, %Activity{} = _activity} = Transmogrifier.handle_incoming(data)
     end
 
+    test "it doesn't work for deactivated users" do
+      data =
+        File.read!("test/fixtures/create-chat-message.json")
+        |> Poison.decode!()
+
+      _author =
+        insert(:user,
+          ap_id: data["actor"],
+          local: false,
+          last_refreshed_at: DateTime.utc_now(),
+          deactivated: true
+        )
+
+      _recipient = insert(:user, ap_id: List.first(data["to"]), local: true)
+
+      assert {:error, _} = Transmogrifier.handle_incoming(data)
+    end
+
     test "it inserts it and creates a chat" do
       data =
         File.read!("test/fixtures/create-chat-message.json")