From 1771cb59d47388f28e52e48137098b0548b65d2a Mon Sep 17 00:00:00 2001 From: Anton Springer Date: Mon, 4 May 2026 22:25:47 +0200 Subject: [PATCH 1/3] Anonymizeevaluationstaffnotes#2698 --- evap/evaluation/management/commands/anonymize.py | 10 +++++++++- evap/evaluation/tests/test_commands.py | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/evap/evaluation/management/commands/anonymize.py b/evap/evaluation/management/commands/anonymize.py index 682434ef1f..0d83531451 100644 --- a/evap/evaluation/management/commands/anonymize.py +++ b/evap/evaluation/management/commands/anonymize.py @@ -21,6 +21,7 @@ Semester, TextAnswer, UserProfile, + Evaluation ) from evap.tools import unordered_groupby @@ -69,7 +70,7 @@ def anonymize_data(self): self.anonymize_evaluations() self.anonymize_questionnaires() self.anonymize_answers(lorem_ipsum) - + self.anonymize_staff_notes(lorem_ipsum) self.stdout.write("") self.stdout.write("Done.") @@ -276,6 +277,13 @@ def anonymize_answers(self, lorem_ipsum): finally: self.stdout.ending = "\n" + def anonymize_staff_notes(self, lorem_ipsum): + self.stdout.write("Replacing text answers with fake ones...") + for evaluation in Evaluation.objects.all(): + if evaluation.staff_notes != "": + evaluation.staff_notes = self.lorem(evaluation.staff_notes, lorem_ipsum) + evaluation.save() + # Returns a string with the same number of lorem ipsum words as the given text @staticmethod def lorem(text, lorem_ipsum): diff --git a/evap/evaluation/tests/test_commands.py b/evap/evaluation/tests/test_commands.py index 8c57d62f8f..dcf5890e8d 100644 --- a/evap/evaluation/tests/test_commands.py +++ b/evap/evaluation/tests/test_commands.py @@ -89,6 +89,7 @@ def setUpTestData(cls): course=cls.course, name_de="Wie man Software testet", name_en="Testing your software", + staff_notes="This evaluation has dropout answers" ) baker.make( Evaluation, @@ -179,6 +180,10 @@ def test_user_with_password(self): baker.make(UserProfile, password=make_password("evap")) with self.assertRaises(AssertionError): management.call_command("anonymize", stdout=StringIO()) + + def test_staff_notes_are_anonymized(self): + management.call_command("anonymize", stdout=StringIO()) + self.assertEqual(Evaluation.objects.get(id=self.evaluation.id).staff_notes, "Lorem ipsum dolor sit amet,") class TestRefreshResultsCacheCommand(TestCase): From d47dd5067a719ae0fcc69224b92b6c3e9c556167 Mon Sep 17 00:00:00 2001 From: Anton Springer Date: Mon, 4 May 2026 22:36:52 +0200 Subject: [PATCH 2/3] Anonymize evaluation staff notes #2698 --- evap/evaluation/management/commands/anonymize.py | 14 +++++++------- evap/evaluation/tests/test_commands.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/evap/evaluation/management/commands/anonymize.py b/evap/evaluation/management/commands/anonymize.py index 0d83531451..e4be7ce27f 100644 --- a/evap/evaluation/management/commands/anonymize.py +++ b/evap/evaluation/management/commands/anonymize.py @@ -16,12 +16,12 @@ Contribution, Course, CourseType, + Evaluation, Program, RatingAnswerCounter, Semester, TextAnswer, UserProfile, - Evaluation ) from evap.tools import unordered_groupby @@ -278,12 +278,12 @@ def anonymize_answers(self, lorem_ipsum): self.stdout.ending = "\n" def anonymize_staff_notes(self, lorem_ipsum): - self.stdout.write("Replacing text answers with fake ones...") - for evaluation in Evaluation.objects.all(): - if evaluation.staff_notes != "": - evaluation.staff_notes = self.lorem(evaluation.staff_notes, lorem_ipsum) - evaluation.save() - + self.stdout.write("Replacing text answers with fake ones...") + for evaluation in Evaluation.objects.all(): + if evaluation.staff_notes != "": + evaluation.staff_notes = self.lorem(evaluation.staff_notes, lorem_ipsum) + evaluation.save() + # Returns a string with the same number of lorem ipsum words as the given text @staticmethod def lorem(text, lorem_ipsum): diff --git a/evap/evaluation/tests/test_commands.py b/evap/evaluation/tests/test_commands.py index dcf5890e8d..bdb6b2bb9a 100644 --- a/evap/evaluation/tests/test_commands.py +++ b/evap/evaluation/tests/test_commands.py @@ -89,7 +89,7 @@ def setUpTestData(cls): course=cls.course, name_de="Wie man Software testet", name_en="Testing your software", - staff_notes="This evaluation has dropout answers" + staff_notes="This evaluation has dropout answers", ) baker.make( Evaluation, @@ -180,7 +180,7 @@ def test_user_with_password(self): baker.make(UserProfile, password=make_password("evap")) with self.assertRaises(AssertionError): management.call_command("anonymize", stdout=StringIO()) - + def test_staff_notes_are_anonymized(self): management.call_command("anonymize", stdout=StringIO()) self.assertEqual(Evaluation.objects.get(id=self.evaluation.id).staff_notes, "Lorem ipsum dolor sit amet,") From cc61749dd1a662850614ae28c2449b5ec6d369cb Mon Sep 17 00:00:00 2001 From: Anton Springer Date: Mon, 27 Jul 2026 21:19:57 +0200 Subject: [PATCH 3/3] Update evap/evaluation/management/commands/anonymize.py Co-authored-by: Niklas Mohrin --- evap/evaluation/management/commands/anonymize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evap/evaluation/management/commands/anonymize.py b/evap/evaluation/management/commands/anonymize.py index e4be7ce27f..0d45bcfa3c 100644 --- a/evap/evaluation/management/commands/anonymize.py +++ b/evap/evaluation/management/commands/anonymize.py @@ -278,7 +278,7 @@ def anonymize_answers(self, lorem_ipsum): self.stdout.ending = "\n" def anonymize_staff_notes(self, lorem_ipsum): - self.stdout.write("Replacing text answers with fake ones...") + self.stdout.write("Replacing staff notes with fake ones...") for evaluation in Evaluation.objects.all(): if evaluation.staff_notes != "": evaluation.staff_notes = self.lorem(evaluation.staff_notes, lorem_ipsum)