From f236dea0bfbeeae6204e5841cace99e4e170fe66 Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Mon, 15 Apr 2024 19:47:30 +0200 Subject: [PATCH] Don't allow newly created empty comments --- issues/views.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/issues/views.py b/issues/views.py index c0997c4..1d25aea 100644 --- a/issues/views.py +++ b/issues/views.py @@ -422,10 +422,14 @@ def history_comment_new(request, issue): form = CommentForm(request.POST) assert form.is_valid() # we have only a textfield with no validation properties; also: no html-side handling - TurningPoint.objects.create( - issue=issue, kind=TurningPointKind.MANUAL_ANNOTATION, user=request.user, - comment=form.cleaned_data["comment"], - timestamp=timezone.now()) + if form.cleaned_data["comment"] != "": + # one special case: we simply ignore newly created comments without any contents as a (presumed) mistake. I + # think that's amount of magic to have: it still allows one to erase comments (possibly for non-manual + # kinds) but it saves you from what is obviously a mistake (without complaining with a red box or something) + TurningPoint.objects.create( + issue=issue, kind=TurningPointKind.MANUAL_ANNOTATION, user=request.user, + comment=form.cleaned_data["comment"], + timestamp=timezone.now()) return redirect(issue_history, issue_pk=issue.pk)