From 5d2943e94b4e5edd0cf284f63959f082ba0cc0f0 Mon Sep 17 00:00:00 2001 From: andrepapoti Date: Mon, 11 Mar 2024 13:42:46 -0300 Subject: [PATCH] views: Add notes to patch-detail view The submission template now includes a section to display notes, these can be filtered out depending if the request user is a maintainer for the patch's project and on the note maintainer_only attribute Signed-off-by: andrepapoti --- patchwork/templates/patchwork/submission.html | 18 +++++++ patchwork/tests/views/test_patch.py | 50 +++++++++++++++++++ patchwork/views/patch.py | 10 ++++ 3 files changed, 78 insertions(+) diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html index 85e7be4b..b0371501 100644 --- a/patchwork/templates/patchwork/submission.html +++ b/patchwork/templates/patchwork/submission.html @@ -266,6 +266,24 @@

Message

+{% for note in notes %} +{% if forloop.first %} +

Notes

+{% endif %} + +
+
+ {{ note.patch.submitter|personify:project }} + + Last modified: {{ note.last_modified }} UTC + +
+
+    {{ note.content }}
+  
+
+{% endfor %} + {% for item in comments %} {% if forloop.first %}

Comments

diff --git a/patchwork/tests/views/test_patch.py b/patchwork/tests/views/test_patch.py index b34d4ed1..48f0bdb5 100644 --- a/patchwork/tests/views/test_patch.py +++ b/patchwork/tests/views/test_patch.py @@ -19,6 +19,7 @@ from patchwork.models import State from patchwork.tests.utils import create_check from patchwork.tests.utils import create_maintainer +from patchwork.tests.utils import create_note from patchwork.tests.utils import create_patch from patchwork.tests.utils import create_patch_comment from patchwork.tests.utils import create_patches @@ -247,6 +248,55 @@ def test_comment_redirect(self): response = self.client.get(requested_url) self.assertRedirects(response, redirect_url) + def test_show_note_for_maintainer(self): + project = create_project() + user = create_maintainer(project) + patch = create_patch(project=project) + note = create_note(patch=patch, submitter=user) + self.client.login(username=user.username, password=user.username) + requested_url = reverse( + 'patch-detail', + kwargs={ + 'project_id': patch.project.linkname, + 'msgid': patch.encoded_msgid, + }, + ) + response = self.client.get(requested_url) + self.assertIn('

Notes

'.encode('utf-8'), response.content) + self.assertIn(note.content.encode('utf-8'), response.content) + + def test_hide_private_note(self): + project = create_project() + user = create_maintainer(project) + patch = create_patch(project=project) + note = create_note(patch=patch, submitter=user) + requested_url = reverse( + 'patch-detail', + kwargs={ + 'project_id': patch.project.linkname, + 'msgid': patch.encoded_msgid, + }, + ) + response = self.client.get(requested_url) + self.assertNotIn('

Notes

'.encode('utf-8'), response.content) + self.assertNotIn(note.content.encode('utf-8'), response.content) + + def test_show_public_note(self): + project = create_project() + user = create_maintainer(project) + patch = create_patch(project=project) + note = create_note(patch=patch, submitter=user, maintainer_only=False) + requested_url = reverse( + 'patch-detail', + kwargs={ + 'project_id': patch.project.linkname, + 'msgid': patch.encoded_msgid, + }, + ) + response = self.client.get(requested_url) + self.assertIn('

Notes

'.encode('utf-8'), response.content) + self.assertIn(note.content.encode('utf-8'), response.content) + def test_old_detail_url(self): patch = create_patch() diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index 54cf992c..65b7f2c5 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -122,6 +122,15 @@ def patch_detail(request, project_id, msgid): 'submitter', 'date', 'id', 'content', 'patch', 'addressed' ) + if ( + request.user.is_superuser + or request.user.is_authenticated + and patch.project in request.user.profile.maintainer_projects.all() + ): + notes = patch.note.all() + else: + notes = patch.note.filter(maintainer_only=False) + if patch.related: related_same_project = patch.related.patches.only( 'name', 'msgid', 'project', 'related' @@ -136,6 +145,7 @@ def patch_detail(request, project_id, msgid): related_same_project = [] related_different_project = [] + context['notes'] = notes context['comments'] = comments context['checks'] = Patch.filter_unique_checks( patch.check_set.all().select_related('user'),