ObjectAgePolicy: Fix pattern matching on published
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Tue, 10 Aug 2021 05:41:06 +0000 (07:41 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Fri, 13 Aug 2021 15:56:46 +0000 (17:56 +0200)
Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3500

CHANGELOG.md
lib/pleroma/web/activity_pub/mrf/object_age_policy.ex
test/pleroma/web/activity_pub/mrf/object_age_policy_test.exs

index d6bf12d4106e5d7a7fcaae7b1d4089f498966c29..0756d522381c22a36418ea8c8b326bb7527ac4ee 100644 (file)
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
 ### Fixed
 - MastodonAPI: Stream out Create activities
+- MRF ObjectAgePolicy: Fix pattern matching on "published"
 
 ## 2.4.0 - 2021-08-08
 
index 9a211fd447fc4d9020dd38f9e880b226c7344de7..02c9b18ed5eb5203f3496577e3ff4c9ad80c07d8 100644 (file)
@@ -49,6 +49,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do
           message
           |> Map.put("to", to)
           |> Map.put("cc", cc)
+          |> Kernel.put_in(["object", "to"], to)
+          |> Kernel.put_in(["object", "cc"], cc)
 
         {:ok, message}
       else
@@ -70,6 +72,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do
           message
           |> Map.put("to", to)
           |> Map.put("cc", cc)
+          |> Kernel.put_in(["object", "to"], to)
+          |> Kernel.put_in(["object", "cc"], cc)
 
         {:ok, message}
       else
@@ -82,7 +86,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy do
   end
 
   @impl true
-  def filter(%{"type" => "Create", "published" => _} = message) do
+  def filter(%{"type" => "Create", "object" => %{"published" => _}} = message) do
     with actions <- Config.get([:mrf_object_age, :actions]),
          {:reject, _} <- check_date(message),
          {:ok, message} <- check_reject(message, actions),
index 137aafd39ed62d2139ac7aec2baae17e0ea21421..2f649a0a4818e731fe7cc04944709331d14c261d 100644 (file)
@@ -22,6 +22,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
   defp get_old_message do
     File.read!("test/fixtures/mastodon-post-activity.json")
     |> Jason.decode!()
+    |> Map.drop(["published"])
   end
 
   defp get_new_message do