Skip to content

Commit bd47834

Browse files
committed
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 <[email protected]>
1 parent d6c5538 commit bd47834

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

patchwork/templates/patchwork/submission.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,24 @@ <h2>Message</h2>
187187
</pre>
188188
</div>
189189

190+
{% for note in notes %}
191+
{% if forloop.first %}
192+
<h2>Notes</h2>
193+
{% endif %}
194+
<a name="{{ item.id }}"></a>
195+
<div class="submission-message">
196+
<div class="meta">
197+
{{ note.patch.submitter|personify:project }}
198+
<span class="message-date">
199+
Last modified: {{ note.last_modified }} UTC
200+
</span>
201+
</div>
202+
<pre class="content">
203+
{{ note.content }}
204+
</pre>
205+
</div>
206+
{% endfor %}
207+
190208
{% for item in comments %}
191209
{% if forloop.first %}
192210
<h2>Comments</h2>

patchwork/tests/views/test_patch.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from patchwork.models import State
2020
from patchwork.tests.utils import create_check
2121
from patchwork.tests.utils import create_maintainer
22+
from patchwork.tests.utils import create_note
2223
from patchwork.tests.utils import create_patch
2324
from patchwork.tests.utils import create_patch_comment
2425
from patchwork.tests.utils import create_patches
@@ -247,6 +248,55 @@ def test_comment_redirect(self):
247248
response = self.client.get(requested_url)
248249
self.assertRedirects(response, redirect_url)
249250

251+
def test_show_note_for_maintainer(self):
252+
project = create_project()
253+
user = create_maintainer(project)
254+
patch = create_patch(project=project)
255+
note = create_note(patch=patch, submitter=user)
256+
self.client.login(username=user.username, password=user.username)
257+
requested_url = reverse(
258+
'patch-detail',
259+
kwargs={
260+
'project_id': patch.project.linkname,
261+
'msgid': patch.encoded_msgid,
262+
},
263+
)
264+
response = self.client.get(requested_url)
265+
self.assertIn('<h2>Notes</h2>'.encode('utf-8'), response.content)
266+
self.assertIn(note.content.encode('utf-8'), response.content)
267+
268+
def test_hide_private_note(self):
269+
project = create_project()
270+
user = create_maintainer(project)
271+
patch = create_patch(project=project)
272+
note = create_note(patch=patch, submitter=user)
273+
requested_url = reverse(
274+
'patch-detail',
275+
kwargs={
276+
'project_id': patch.project.linkname,
277+
'msgid': patch.encoded_msgid,
278+
},
279+
)
280+
response = self.client.get(requested_url)
281+
self.assertNotIn('<h2>Notes</h2>'.encode('utf-8'), response.content)
282+
self.assertNotIn(note.content.encode('utf-8'), response.content)
283+
284+
def test_show_public_note(self):
285+
project = create_project()
286+
user = create_maintainer(project)
287+
patch = create_patch(project=project)
288+
note = create_note(patch=patch, submitter=user, maintainer_only=False)
289+
requested_url = reverse(
290+
'patch-detail',
291+
kwargs={
292+
'project_id': patch.project.linkname,
293+
'msgid': patch.encoded_msgid,
294+
},
295+
)
296+
response = self.client.get(requested_url)
297+
self.assertIn('<h2>Notes</h2>'.encode('utf-8'), response.content)
298+
self.assertIn(note.content.encode('utf-8'), response.content)
299+
250300
def test_old_detail_url(self):
251301
patch = create_patch()
252302

patchwork/views/patch.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ def patch_detail(request, project_id, msgid):
9999
'submitter', 'date', 'id', 'content', 'patch', 'addressed'
100100
)
101101

102+
if (
103+
request.user.is_superuser
104+
or request.user.is_authenticated
105+
and patch.project in request.user.profile.maintainer_projects.all()
106+
):
107+
notes = patch.note.all()
108+
else:
109+
notes = patch.note.filter(maintainer_only=False)
110+
102111
if patch.related:
103112
related_same_project = patch.related.patches.only(
104113
'name', 'msgid', 'project', 'related'
@@ -113,6 +122,7 @@ def patch_detail(request, project_id, msgid):
113122
related_same_project = []
114123
related_different_project = []
115124

125+
context['notes'] = notes
116126
context['comments'] = comments
117127
context['checks'] = Patch.filter_unique_checks(
118128
patch.check_set.all().select_related('user'),

0 commit comments

Comments
 (0)