Skip to content

Commit e98fc38

Browse files
Merge branch 'main' into liaisondetailscope
2 parents d2a50f5 + 76f56ce commit e98fc38

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

ietf/liaisons/tests.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -942,17 +942,34 @@ def test_liaison_add_attachment(self):
942942
)
943943

944944
def test_liaison_edit_attachment(self):
945-
946-
attachment = LiaisonStatementAttachmentFactory(document__name='liaiatt-1')
947-
url = urlreverse('ietf.liaisons.views.liaison_edit_attachment', kwargs=dict(object_id=attachment.statement_id,doc_id=attachment.document_id))
945+
attachment = LiaisonStatementAttachmentFactory(document__name="liaiatt-1")
946+
url = urlreverse(
947+
"ietf.liaisons.views.liaison_edit_attachment",
948+
kwargs=dict(
949+
object_id=attachment.statement_id, doc_id=attachment.document_id
950+
),
951+
)
948952
login_testing_unauthorized(self, "secretary", url)
949953
r = self.client.get(url)
950954
self.assertEqual(r.status_code, 200)
951-
post_data = dict(title='New Title')
952-
r = self.client.post(url,post_data)
955+
post_data = dict(title="New Title")
956+
r = self.client.post(url, post_data)
953957
attachment = LiaisonStatementAttachment.objects.get(pk=attachment.pk)
954958
self.assertEqual(r.status_code, 302)
955-
self.assertEqual(attachment.document.title,'New Title')
959+
self.assertEqual(attachment.document.title, "New Title")
960+
961+
# ensure attempts to edit attachments not attached to this liaison statement fail
962+
other_attachment = LiaisonStatementAttachmentFactory(document__name="liaiatt-2")
963+
url = urlreverse(
964+
"ietf.liaisons.views.liaison_edit_attachment",
965+
kwargs=dict(
966+
object_id=attachment.statement_id, doc_id=other_attachment.document_id
967+
),
968+
)
969+
r = self.client.get(url)
970+
self.assertEqual(r.status_code, 404)
971+
r = self.client.post(url, dict(title="New Title"))
972+
self.assertEqual(r.status_code, 404)
956973

957974
def test_liaison_delete_attachment(self):
958975
attachment = LiaisonStatementAttachmentFactory(document__name='liaiatt-1')

ietf/liaisons/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
url(r'^(?P<object_id>\d+)/$', views.liaison_detail),
2727
url(r'^(?P<object_id>\d+)/addcomment/$', views.add_comment),
2828
url(r'^(?P<object_id>\d+)/edit/$', views.liaison_edit),
29-
url(r'^(?P<object_id>\d+)/edit-attachment/(?P<doc_id>[A-Za-z0-9._+-]+)$', views.liaison_edit_attachment),
30-
url(r'^(?P<object_id>\d+)/delete-attachment/(?P<attach_id>[A-Za-z0-9._+-]+)$', views.liaison_delete_attachment),
29+
url(r'^(?P<object_id>\d+)/edit-attachment/(?P<doc_id>[0-9]+)$', views.liaison_edit_attachment),
30+
url(r'^(?P<object_id>\d+)/delete-attachment/(?P<attach_id>[0-9]+)$', views.liaison_delete_attachment),
3131
url(r'^(?P<object_id>\d+)/history/$', views.liaison_history),
3232
url(r'^(?P<object_id>\d+)/reply/$', views.liaison_reply),
3333
url(r'^(?P<object_id>\d+)/resend/$', views.liaison_resend),

ietf/liaisons/views.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77

88
from django.contrib import messages
99
from django.urls import reverse as urlreverse
10-
from django.core.exceptions import ValidationError, PermissionDenied
10+
from django.core.exceptions import ValidationError, ObjectDoesNotExist, PermissionDenied
1111
from django.core.validators import validate_email
1212
from django.db.models import Q, Prefetch
13-
from django.http import HttpResponse
13+
from django.http import Http404, HttpResponse
1414
from django.shortcuts import render, get_object_or_404, redirect
1515

1616
import debug # pyflakes:ignore
1717

18-
from ietf.doc.models import Document
1918
from ietf.ietfauth.utils import role_required, has_role
2019
from ietf.group.models import Group, Role
2120
from ietf.liaisons.models import (LiaisonStatement,LiaisonStatementEvent,
@@ -450,7 +449,11 @@ def liaison_edit(request, object_id):
450449
def liaison_edit_attachment(request, object_id, doc_id):
451450
'''Edit the Liaison Statement attachment title'''
452451
liaison = get_object_or_404(LiaisonStatement, pk=object_id)
453-
doc = get_object_or_404(Document, pk=doc_id)
452+
try:
453+
doc = liaison.attachments.get(pk=doc_id)
454+
except ObjectDoesNotExist:
455+
raise Http404
456+
454457
if not can_edit_liaison(request.user, liaison):
455458
permission_denied(request, "You are not authorized for this action.")
456459

0 commit comments

Comments
 (0)