ActivityPub.move(old_user, new_user)
end
end
+
+ describe "global activity expiration" do
+ clear_config([:instance, :rewrite_policy])
+
+ test "creates an activity expiration for local Create activities" do
+ Pleroma.Config.put(
+ [:instance, :rewrite_policy],
+ Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
+ )
+
+ {:ok, %{id: id_create}} = ActivityBuilder.insert(%{"type" => "Create", "context" => "3hu"})
+ {:ok, _follow} = ActivityBuilder.insert(%{"type" => "Follow", "context" => "3hu"})
+
+ assert [%{activity_id: ^id_create}] = Pleroma.ActivityExpiration |> Repo.all()
+ end
+ end
end
@id Pleroma.Web.Endpoint.url() <> "/activities/cofe"
test "adds `expires_at` property" do
- assert {:ok, %{"expires_at" => expires_at}} = ActivityExpirationPolicy.filter(%{"id" => @id})
+ assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
+ ActivityExpirationPolicy.filter(%{"id" => @id, "type" => "Create"})
assert Timex.diff(expires_at, NaiveDateTime.utc_now(), :days) == 364
end
test "keeps existing `expires_at` if it less than the config setting" do
expires_at = NaiveDateTime.utc_now() |> Timex.shift(days: 1)
- assert {:ok, %{"expires_at" => ^expires_at}} =
- ActivityExpirationPolicy.filter(%{"id" => @id, "expires_at" => expires_at})
+ assert {:ok, %{"type" => "Create", "expires_at" => ^expires_at}} =
+ ActivityExpirationPolicy.filter(%{
+ "id" => @id,
+ "type" => "Create",
+ "expires_at" => expires_at
+ })
end
test "overwrites existing `expires_at` if it greater than the config setting" do
too_distant_future = NaiveDateTime.utc_now() |> Timex.shift(years: 2)
- assert {:ok, %{"expires_at" => expires_at}} =
- ActivityExpirationPolicy.filter(%{"id" => @id, "expires_at" => too_distant_future})
+ assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
+ ActivityExpirationPolicy.filter(%{
+ "id" => @id,
+ "type" => "Create",
+ "expires_at" => too_distant_future
+ })
assert Timex.diff(expires_at, NaiveDateTime.utc_now(), :days) == 364
end
test "ignores remote activities" do
- assert {:ok, activity} = ActivityExpirationPolicy.filter(%{"id" => "https://example.com/123"})
+ assert {:ok, activity} =
+ ActivityExpirationPolicy.filter(%{
+ "id" => "https://example.com/123",
+ "type" => "Create"
+ })
+
+ refute Map.has_key?(activity, "expires_at")
+ end
+
+ test "ignores non-Create activities" do
+ assert {:ok, activity} =
+ ActivityExpirationPolicy.filter(%{
+ "id" => "https://example.com/123",
+ "type" => "Follow"
+ })
refute Map.has_key?(activity, "expires_at")
end
import ExUnit.CaptureLog
clear_config([ActivityExpiration, :enabled])
+ clear_config([:instance, :rewrite_policy])
test "deletes an expiration activity" do
Pleroma.Config.put([ActivityExpiration, :enabled], true)
refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)
end
+ test "works with ActivityExpirationPolicy" do
+ Pleroma.Config.put([ActivityExpiration, :enabled], true)
+
+ Pleroma.Config.put(
+ [:instance, :rewrite_policy],
+ Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
+ )
+
+ user = insert(:user)
+
+ days = Pleroma.Config.get([:mrf_activity_expiration, :days], 365)
+
+ {:ok, %{id: id} = activity} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofe"})
+
+ past_date =
+ NaiveDateTime.utc_now() |> Timex.shift(days: -days) |> NaiveDateTime.truncate(:second)
+
+ activity
+ |> Repo.preload(:expiration)
+ |> Map.get(:expiration)
+ |> Ecto.Changeset.change(%{scheduled_at: past_date})
+ |> Repo.update!()
+
+ Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
+
+ assert [%{data: %{"type" => "Delete", "deleted_activity_id" => ^id}}] =
+ Pleroma.Repo.all(Pleroma.Activity)
+ end
+
describe "delete_activity/1" do
test "adds log message if activity isn't find" do
assert capture_log([level: :error], fn ->