make bulk user creation from admin works as a transaction
[akkoma] / lib / pleroma / web / activity_pub / mrf / tag_policy.ex
index dd3129707c28b21c441c6910f1c948cfa2ddd834..b52be30e72c2553b375cf1b17ca4b6064247b650 100644 (file)
@@ -5,6 +5,19 @@
 defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
   alias Pleroma.User
   @behaviour Pleroma.Web.ActivityPub.MRF
+  @moduledoc """
+     Apply policies based on user tags
+
+     This policy applies policies on a user activities depending on their tags
+     on your instance.
+
+     - `mrf_tag:media-force-nsfw`: Mark as sensitive on presence of attachments
+     - `mrf_tag:media-strip`: Remove attachments
+     - `mrf_tag:force-unlisted`: Mark as unlisted (removes from the federated timeline)
+     - `mrf_tag:sandbox`: Remove from public (local and federated) timelines
+     - `mrf_tag:disable-remote-subscription`: Reject non-local follow requests
+     - `mrf_tag:disable-any-subscription`: Reject any follow requests
+  """
 
   defp get_tags(%User{tags: tags}) when is_list(tags), do: tags
   defp get_tags(_), do: []
@@ -50,10 +63,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
       cc =
         List.delete(cc, user.follower_address) ++ ["https://www.w3.org/ns/activitystreams#Public"]
 
+      object =
+        message["object"]
+        |> Map.put("to", to)
+        |> Map.put("cc", cc)
+
       message =
         message
         |> Map.put("to", to)
         |> Map.put("cc", cc)
+        |> Map.put("object", object)
 
       {:ok, message}
     else
@@ -74,10 +93,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
 
       cc = List.delete(cc, "https://www.w3.org/ns/activitystreams#Public")
 
+      object =
+        message["object"]
+        |> Map.put("to", to)
+        |> Map.put("cc", cc)
+
       message =
         message
         |> Map.put("to", to)
         |> Map.put("cc", cc)
+        |> Map.put("object", object)
 
       {:ok, message}
     else
@@ -85,6 +110,21 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicy do
     end
   end
 
+  defp process_tag(
+         "mrf_tag:disable-remote-subscription",
+         %{"type" => "Follow", "actor" => actor} = message
+       ) do
+    user = User.get_cached_by_ap_id(actor)
+
+    if user.local == true do
+      {:ok, message}
+    else
+      {:reject, nil}
+    end
+  end
+
+  defp process_tag("mrf_tag:disable-any-subscription", %{"type" => "Follow"}), do: {:reject, nil}
+
   defp process_tag(_, message), do: {:ok, message}
 
   def filter_message(actor, message) do