diff --git a/lib/pleroma/web/activity_pub/object_validators/bite_validator.ex b/lib/pleroma/web/activity_pub/object_validators/bite_validator.ex index a2e0bac85e..51e58640e3 100644 --- a/lib/pleroma/web/activity_pub/object_validators/bite_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/bite_validator.ex @@ -38,7 +38,7 @@ defp validate_data(cng) do |> validate_required([:id, :type, :actor, :to, :target]) |> validate_inclusion(:type, ["Bite"]) |> validate_actor_presence() - |> validate_actor_presence(field_name: :target) + |> validate_object_or_user_presence(field_name: :target) end def cast_and_validate(data) do diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index f130f1e484..8f242c58e2 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -487,8 +487,35 @@ def handle_incoming( end end + def handle_incoming( + %{"type" => "Bite", "target" => target_id} = data, + options + ) do + target_id = + cond do + %User{ap_id: actor_id} = User.get_by_ap_id(target_id) -> + actor_id + + %Object{data: data} = Object.get_by_ap_id(target_id) + when is_binary(data["actor"]) or is_binary(data["attributedTo"]) -> + data["actor"] || data["attributedTo"] + + _ -> + target_id + end + + with data = Map.put(data, "target", target_id), + :ok <- ObjectValidator.fetch_actor_and_object(data), + {:ok, activity, _meta} <- + Pipeline.common_pipeline(data, local: false) do + {:ok, activity} + else + e -> {:error, e} + end + end + def handle_incoming(%{"type" => type} = data, _options) - when type in ~w{Like EmojiReact Announce Add Remove Bite} do + when type in ~w{Like EmojiReact Announce Add Remove} do with :ok <- ObjectValidator.fetch_actor_and_object(data), {:ok, activity, _meta} <- Pipeline.common_pipeline(data, local: false) do diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index dac42b7948..65cdbdc55d 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -984,9 +984,10 @@ defp maybe_exclude_activity_id(query, %Activity{id: activity_id}) do end defp exclude_rejected(query) do - rejected_activities = "Reject" - |> Activity.Queries.by_type() - |> select([a], fragment("?->>'object'", a.data)) + rejected_activities = + "Reject" + |> Activity.Queries.by_type() + |> select([a], fragment("?->>'object'", a.data)) query |> where([a], fragment("?->>'id'", a.data) not in subquery(rejected_activities)) diff --git a/lib/pleroma/web/mastodon_api/controllers/bite_controller.ex b/lib/pleroma/web/mastodon_api/controllers/bite_controller.ex index 48552a8dac..b9b1310103 100644 --- a/lib/pleroma/web/mastodon_api/controllers/bite_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/bite_controller.ex @@ -15,7 +15,7 @@ defmodule Pleroma.Web.MastodonAPI.BiteController do plug(OAuthScopesPlug, %{scopes: ["write:bites"]} when action == :bite) - plug(RateLimiter, [name: :bites]) + plug(RateLimiter, name: :bites) plug(:assign_account_by_id) diff --git a/test/pleroma/web/mastodon_api/controllers/bite_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/bite_controller_test.exs index dff5d01a65..96cd38e762 100644 --- a/test/pleroma/web/mastodon_api/controllers/bite_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/bite_controller_test.exs @@ -16,7 +16,7 @@ test "bites a user", %{conn: conn} do |> post("/api/v1/bite?id=#{bitten_id}") |> json_response_and_validate_schema(200) - assert response == %{} + assert response == %{} end test "self harm is not supported", %{conn: conn, user: %{id: self_id}} do @@ -25,6 +25,6 @@ test "self harm is not supported", %{conn: conn, user: %{id: self_id}} do |> post("/api/v1/bite?id=#{self_id}") |> json_response_and_validate_schema(400) - assert %{"error" => "Can not bite yourself"} = response + assert %{"error" => "Can not bite yourself"} = response end end