Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions ietf/liaisons/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,17 +939,34 @@ def test_liaison_add_attachment(self):
)

def test_liaison_edit_attachment(self):

attachment = LiaisonStatementAttachmentFactory(document__name='liaiatt-1')
url = urlreverse('ietf.liaisons.views.liaison_edit_attachment', kwargs=dict(object_id=attachment.statement_id,doc_id=attachment.document_id))
attachment = LiaisonStatementAttachmentFactory(document__name="liaiatt-1")
url = urlreverse(
"ietf.liaisons.views.liaison_edit_attachment",
kwargs=dict(
object_id=attachment.statement_id, doc_id=attachment.document_id
),
)
login_testing_unauthorized(self, "secretary", url)
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
post_data = dict(title='New Title')
r = self.client.post(url,post_data)
post_data = dict(title="New Title")
r = self.client.post(url, post_data)
attachment = LiaisonStatementAttachment.objects.get(pk=attachment.pk)
self.assertEqual(r.status_code, 302)
self.assertEqual(attachment.document.title,'New Title')
self.assertEqual(attachment.document.title, "New Title")

# ensure attempts to edit attachments not attached to this liaison statement fail
other_attachment = LiaisonStatementAttachmentFactory(document__name="liaiatt-2")
url = urlreverse(
"ietf.liaisons.views.liaison_edit_attachment",
kwargs=dict(
object_id=attachment.statement_id, doc_id=other_attachment.document_id
),
)
r = self.client.get(url)
self.assertEqual(r.status_code, 404)
r = self.client.post(url, dict(title="New Title"))
self.assertEqual(r.status_code, 404)

def test_liaison_delete_attachment(self):
attachment = LiaisonStatementAttachmentFactory(document__name='liaiatt-1')
Expand Down
11 changes: 7 additions & 4 deletions ietf/liaisons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

from django.contrib import messages
from django.urls import reverse as urlreverse
from django.core.exceptions import ValidationError
from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.core.validators import validate_email
from django.db.models import Q, Prefetch
from django.http import HttpResponse
from django.http import Http404, HttpResponse
from django.shortcuts import render, get_object_or_404, redirect

import debug # pyflakes:ignore

from ietf.doc.models import Document
from ietf.ietfauth.utils import role_required, has_role
from ietf.group.models import Group, Role
from ietf.liaisons.models import (LiaisonStatement,LiaisonStatementEvent,
Expand Down Expand Up @@ -444,7 +443,11 @@ def liaison_edit(request, object_id):
def liaison_edit_attachment(request, object_id, doc_id):
'''Edit the Liaison Statement attachment title'''
liaison = get_object_or_404(LiaisonStatement, pk=object_id)
doc = get_object_or_404(Document, pk=doc_id)
try:
doc = liaison.attachments.get(pk=doc_id)
except ObjectDoesNotExist:
raise Http404

if not can_edit_liaison(request.user, liaison):
permission_denied(request, "You are not authorized for this action.")

Expand Down
Loading