Repository: okfde/froide (language: python)

Issue:
Censor information in files names.



Discussion / hints:
Hi! 

I recently submitted my first FOI request via FdS.de. The answering body included my name in the "Eingangsbestätigung" PDF-File name. Hence, even after censoring the PDF, my name is still visible to the public through the file name. Could you introduce a feature that allows users to censor file names?

[Here](https://fragdenstaat.de/anfrage/mikrodaten-gleichwertigkeitsbericht-der-bundesregierung-2024/) is the request, for reference.

Best,

Felix

Fix patch:
diff --git a/froide/account/services.py b/froide/account/services.py
index eb3141931..ac5f1f91d 100644
--- a/froide/account/services.py
+++ b/froide/account/services.py
@@ -321,7 +321,13 @@ def apply_name_redaction(self, content, replacement=""):
             # No more info present about user to redact
             return content
 
-        needles = [self.user.last_name, self.user.first_name, self.user.get_full_name()]
+        needles = [
+            self.user.last_name,
+            self.user.first_name,
+            self.user.get_full_name(),
+            *self.user.first_name.split(),
+            *self.user.last_name.split(),
+        ]
         if self.user.organization_name:
             needles.append(self.user.organization_name)
 


Test patch:
diff --git a/froide/account/tests/test_account.py b/froide/account/tests/test_account.py
index dc36c327f..0d9eddcd4 100644
--- a/froide/account/tests/test_account.py
+++ b/froide/account/tests/test_account.py
@@ -802,3 +802,15 @@ def test_email_case_insensitive_unique():
     msg = 'duplicate key value violates unique constraint "account_user_username_key"'
     with pytest.raises(IntegrityError, match=msg):
         User.objects.create(email="hacker@example.com")
+
+
+@pytest.mark.django_db
+def test_multipart_name_redaction():
+    user = User.objects.create(
+        first_name="Alex", last_name="Random Example", private=True
+    )
+    account_service = AccountService(user)
+    name = "Reply-Alex-Random-Example.pdf"
+    repl = "NAME"
+    redacted_name = account_service.apply_name_redaction(name, repl)
+    assert redacted_name == "Reply-NAME-NAME-NAME.pdf"