weaken the require image description mrf

This commit is contained in:
Charlotte 🦝 Delenk 2022-11-04 16:26:50 +01:00
parent 0939be5a64
commit 07086a5eeb
Signed by: darkkirb
GPG key ID: AB2BD8DAF2E37122

View file

@ -5,9 +5,18 @@ index 000000000..3550a30f2
+++ b/.envrc
@@ -0,0 +1 @@
+use flake
diff --git a/.gitignore b/.gitignore
index f9de4ed49..dc3db2257 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.direnv/
# App artifacts
docs/site
*.sw*
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 000000000..fcb32b26f
index 000000000..22ac3721f
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,42 @@
@ -15,11 +24,11 @@ index 000000000..fcb32b26f
+ "nodes": {
+ "flake-utils": {
+ "locked": {
+ "lastModified": 1659877975,
+ "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
+ "lastModified": 1667395993,
+ "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
+ "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
+ "type": "github"
+ },
+ "original": {
@ -30,11 +39,11 @@ index 000000000..fcb32b26f
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1663141849,
+ "narHash": "sha256-7c9PePBWzOSgiXiSaocvQ55egmc6tYULmRaRvCyIdqk=",
+ "lastModified": 1667573297,
+ "narHash": "sha256-nPPcRXXqovzJZZQtVJGujMAF+LGNoTp+Q/z5drq+rso=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "8614d1dd20e05abbc7fc7284bb7431c9e5ff2f37",
+ "rev": "dac8adf99ace8480b759dd24a16c9aad2507e6cb",
+ "type": "github"
+ },
+ "original": {
@ -55,10 +64,10 @@ index 000000000..fcb32b26f
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 000000000..4a0cdee4d
index 000000000..56ad90a4a
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,24 @@
@@ -0,0 +1,29 @@
+{
+ description = "Akkoma dev flake";
+
@ -67,21 +76,26 @@ index 000000000..4a0cdee4d
+ flake-utils.url = "github:numtide/flake-utils";
+ };
+
+ outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system:
+ let pkgs = import nixpkgs { inherit system; };
+ in
+ {
+ formatter = pkgs.alejandra;
+ devShells.default = pkgs.mkShell {
+ buildInputs = with pkgs; [
+ file
+ ];
+ nativeBuildInputs = with pkgs; [
+ elixir
+ cmake
+ ];
+ };
+ });
+ outputs = {
+ self,
+ nixpkgs,
+ flake-utils,
+ }:
+ flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = import nixpkgs {inherit system;};
+ in {
+ formatter = pkgs.alejandra;
+ devShells.default = pkgs.mkShell {
+ buildInputs = with pkgs; [
+ file
+ ];
+ nativeBuildInputs = with pkgs; [
+ elixir
+ cmake
+ libxcrypt
+ ];
+ };
+ });
+}
diff --git a/lib/mix/migrator.ex b/lib/mix/migrator.ex
new file mode 100644
@ -842,10 +856,10 @@ index 000000000..f3894c8ae
+end
diff --git a/lib/pleroma/web/activity_pub/mrf/require_image_description.ex b/lib/pleroma/web/activity_pub/mrf/require_image_description.ex
new file mode 100644
index 000000000..eaa3fe695
index 000000000..ea7c1ee68
--- /dev/null
+++ b/lib/pleroma/web/activity_pub/mrf/require_image_description.ex
@@ -0,0 +1,33 @@
@@ -0,0 +1,45 @@
+defmodule Pleroma.Web.ActivityPub.MRF.RequireImageDescription do
+ @moduledoc "MRF policy which removes media without image description"
+ @behaviour Pleroma.Web.ActivityPub.MRF.Policy
@ -855,20 +869,32 @@ index 000000000..eaa3fe695
+ ), do: is_binary(name) and !String.equivalent?(name, "")
+ def is_valid_attachment(_), do: false
+
+ def mark_sensitive(object) do
+ object |> Map.put("sensitive", true)
+ {:ok, object}
+ end
+
+ def correct_attachment(object) do
+ if is_valid_attachment(object) do
+ {:ok, object}
+ else
+ mark_sensitive(object)
+ end
+ end
+
+ @impl true
+ def filter(
+ %{"type" => "Create", "object" => %{"attachment" => attachments, "content" => content} = object } = message
+ ) when is_list(attachments) and length(attachments) > 0 and is_binary(content) do
+ old_length = attachments |> length()
+ attachments = attachments |> Enum.filter(fn(attach) -> is_valid_attachment(attach) end)
+ content = if old_length != attachments |> length() do
+ content <> "<br/><emph>This post contained media without content description. Offending media has been removed from this post.</emph>";
+ %{"type" => "Create", "object" => %{"attachment" => attachments} = object } = message
+ ) when is_list(attachments) and length(attachments) > 0 do
+ if attachments |> Enum.all?(fn(attach) -> is_valid_attachment(attach) end) do
+ {:ok, message}
+ else
+ content
+ attachments = attachments |> Enum.map(fn v -> correct_attachment(v) end)
+ object = object |> Map.update("summary", "Missing media descriptions", fn v -> v <> "; Missing media descriptions" end)
+ |> Map.put("attachment", attachments)
+ message = message |> Map.put("object", object)
+ {:ok, message}
+ end
+ object = object |> Map.put("content", content) |> Map.put("attachment", attachments)
+ message = message |> Map.put("object", object)
+ {:ok, message}
+ end
+
+ @impl true