Skip to content

Commit 715edaf

Browse files
authored
fix: return to ballotpopup (ietf-tools#7858)
* fix: return to ballotpopup * fix: ballot position return to in modals * fix: ballot return to test * fix: ballot return to additional allow handlers * fix: ballot return to handler syntax error in test
1 parent bece8fd commit 715edaf

5 files changed

Lines changed: 42 additions & 16 deletions

File tree

ietf/doc/templatetags/ballot_icon.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,14 @@ def sort_key(t):
9696
positions = list(ballot.active_balloter_positions().items())
9797
positions.sort(key=sort_key)
9898

99+
request = context.get("request")
100+
ballot_edit_return_point_param = f"ballot_edit_return_point={request.path}"
101+
99102
right_click_string = ''
100103
if has_role(user, "Area Director"):
101-
right_click_string = 'oncontextmenu="window.location.href=\'%s\';return false;"' % urlreverse('ietf.doc.views_ballot.edit_position', kwargs=dict(name=doc.name, ballot_id=ballot.pk))
104+
right_click_string = 'oncontextmenu="window.location.href=\'{}?{}\';return false;"'.format(
105+
urlreverse('ietf.doc.views_ballot.edit_position', kwargs=dict(name=doc.name, ballot_id=ballot.pk)),
106+
ballot_edit_return_point_param)
102107

103108
my_blocking = False
104109
for i, (balloter, pos) in enumerate(positions):
@@ -113,10 +118,14 @@ def sort_key(t):
113118
typename = "RSAB"
114119
else:
115120
typename = "IESG"
121+
122+
modal_url = "{}?{}".format(
123+
urlreverse("ietf.doc.views_doc.ballot_popup", kwargs=dict(name=doc.name, ballot_id=ballot.pk)),
124+
ballot_edit_return_point_param)
116125

117126
res = ['<a %s href="%s" data-bs-toggle="modal" data-bs-target="#modal-%d" aria-label="%s positions" title="%s positions (click to show more)" class="ballot-icon"><table' % (
118127
right_click_string,
119-
urlreverse("ietf.doc.views_doc.ballot_popup", kwargs=dict(name=doc.name, ballot_id=ballot.pk)),
128+
modal_url,
120129
ballot.pk,
121130
typename,
122131
typename,)]

ietf/doc/tests_ballot.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,18 +1455,14 @@ def test_document_ballot_content_without_send_email_values(self):
14551455

14561456
class ReturnToUrlTests(TestCase):
14571457
def test_invalid_return_to_url(self):
1458-
self.assertRaises(
1459-
Exception,
1460-
lambda: parse_ballot_edit_return_point('/doc/', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718'),
1461-
)
1462-
self.assertRaises(
1463-
Exception,
1464-
lambda: parse_ballot_edit_return_point('/a-route-that-does-not-exist/', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718'),
1465-
)
1466-
self.assertRaises(
1467-
Exception,
1468-
lambda: parse_ballot_edit_return_point('https://example.com/phishing', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718'),
1469-
)
1458+
with self.assertRaises(ValueError):
1459+
parse_ballot_edit_return_point('/', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718')
1460+
1461+
with self.assertRaises(ValueError):
1462+
parse_ballot_edit_return_point('/a-route-that-does-not-exist/', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718')
1463+
1464+
with self.assertRaises(ValueError):
1465+
parse_ballot_edit_return_point('https://example.com/phishing', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718')
14701466

14711467
def test_valid_default_return_to_url(self):
14721468
self.assertEqual(parse_ballot_edit_return_point(

ietf/doc/views_ballot.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,10 +1314,23 @@ def rsab_ballot_status(request):
13141314
def parse_ballot_edit_return_point(path, doc_name, ballot_id):
13151315
get_default_path = lambda: urlreverse("ietf.doc.views_doc.document_ballot", kwargs=dict(name=doc_name, ballot_id=ballot_id))
13161316
allowed_path_handlers = {
1317+
"ietf.community.views.view_list",
13171318
"ietf.doc.views_doc.document_ballot",
13181319
"ietf.doc.views_doc.document_irsg_ballot",
13191320
"ietf.doc.views_doc.document_rsab_ballot",
1321+
"ietf.doc.views_ballot.irsg_ballot_status",
1322+
"ietf.doc.views_ballot.rsab_ballot_status",
1323+
"ietf.doc.views_search.search",
1324+
"ietf.doc.views_search.docs_for_ad",
1325+
"ietf.doc.views_search.drafts_in_last_call",
1326+
"ietf.doc.views_search.recent_drafts",
1327+
"ietf.group.views.chartering_groups",
1328+
"ietf.group.views.group_documents",
1329+
"ietf.group.views.stream_documents",
13201330
"ietf.iesg.views.agenda",
13211331
"ietf.iesg.views.agenda_documents",
1332+
"ietf.iesg.views.discusses",
1333+
"ietf.iesg.views.past_documents",
13221334
}
13231335
return validate_return_to_path(path, get_default_path, allowed_path_handlers)
1336+

ietf/doc/views_doc.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
from django.core.cache import caches
4545
from django.db.models import Max
46-
from django.http import HttpResponse, Http404
46+
from django.http import HttpResponse, Http404, HttpResponseBadRequest
4747
from django.shortcuts import render, get_object_or_404, redirect
4848
from django.template.loader import render_to_string
4949
from django.urls import reverse as urlreverse
@@ -73,6 +73,7 @@
7373
role_required, is_individual_draft_author, can_request_rfc_publication)
7474
from ietf.name.models import StreamName, BallotPositionName
7575
from ietf.utils.history import find_history_active_at
76+
from ietf.doc.views_ballot import parse_ballot_edit_return_point
7677
from ietf.doc.forms import InvestigateForm, TelechatForm, NotifyForm, ActionHoldersForm, DocAuthorForm, DocAuthorChangeBasisForm
7778
from ietf.doc.mails import email_comment, email_remind_action_holders
7879
from ietf.mailtrigger.utils import gather_relevant_expansions
@@ -1586,11 +1587,18 @@ def ballot_popup(request, name, ballot_id):
15861587
doc = get_object_or_404(Document, name=name)
15871588
c = document_ballot_content(request, doc, ballot_id=ballot_id, editable=False)
15881589
ballot = get_object_or_404(BallotDocEvent,id=ballot_id)
1590+
1591+
try:
1592+
return_to_url = parse_ballot_edit_return_point(request.GET.get('ballot_edit_return_point'), name, ballot_id)
1593+
except ValueError:
1594+
return HttpResponseBadRequest('ballot_edit_return_point is invalid')
1595+
15891596
return render(request, "doc/ballot_popup.html",
15901597
dict(doc=doc,
15911598
ballot_content=c,
15921599
ballot_id=ballot_id,
15931600
ballot_type_slug=ballot.ballot_type.slug,
1601+
ballot_edit_return_point=return_to_url,
15941602
editable=True,
15951603
))
15961604

ietf/templates/doc/ballot_popup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{% if editable and user|has_role:"Area Director,Secretariat,IRSG Member,RSAB Member" %}
2828
{% if user|can_ballot:doc %}
2929
<a class="btn btn-primary"
30-
href="{% url "ietf.doc.views_ballot.edit_position" name=doc.name ballot_id=ballot_id %}?ballot_edit_return_point={{ request.path|urlencode }}">
30+
href="{% url "ietf.doc.views_ballot.edit_position" name=doc.name ballot_id=ballot_id %}?ballot_edit_return_point={{ ballot_edit_return_point|urlencode }}">
3131
Edit position
3232
</a>
3333
{% endif %}

0 commit comments

Comments
 (0)