Skip to content

Commit

Permalink
fix: return to ballotpopup (#7858)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
holloway committed Aug 28, 2024
1 parent bece8fd commit 715edaf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
13 changes: 11 additions & 2 deletions ietf/doc/templatetags/ballot_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,14 @@ def sort_key(t):
positions = list(ballot.active_balloter_positions().items())
positions.sort(key=sort_key)

request = context.get("request")
ballot_edit_return_point_param = f"ballot_edit_return_point={request.path}"

right_click_string = ''
if has_role(user, "Area Director"):
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))
right_click_string = 'oncontextmenu="window.location.href=\'{}?{}\';return false;"'.format(
urlreverse('ietf.doc.views_ballot.edit_position', kwargs=dict(name=doc.name, ballot_id=ballot.pk)),
ballot_edit_return_point_param)

my_blocking = False
for i, (balloter, pos) in enumerate(positions):
Expand All @@ -113,10 +118,14 @@ def sort_key(t):
typename = "RSAB"
else:
typename = "IESG"

modal_url = "{}?{}".format(
urlreverse("ietf.doc.views_doc.ballot_popup", kwargs=dict(name=doc.name, ballot_id=ballot.pk)),
ballot_edit_return_point_param)

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' % (
right_click_string,
urlreverse("ietf.doc.views_doc.ballot_popup", kwargs=dict(name=doc.name, ballot_id=ballot.pk)),
modal_url,
ballot.pk,
typename,
typename,)]
Expand Down
20 changes: 8 additions & 12 deletions ietf/doc/tests_ballot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,18 +1455,14 @@ def test_document_ballot_content_without_send_email_values(self):

class ReturnToUrlTests(TestCase):
def test_invalid_return_to_url(self):
self.assertRaises(
Exception,
lambda: parse_ballot_edit_return_point('/doc/', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718'),
)
self.assertRaises(
Exception,
lambda: parse_ballot_edit_return_point('/a-route-that-does-not-exist/', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718'),
)
self.assertRaises(
Exception,
lambda: parse_ballot_edit_return_point('https://example.com/phishing', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718'),
)
with self.assertRaises(ValueError):
parse_ballot_edit_return_point('/', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718')

with self.assertRaises(ValueError):
parse_ballot_edit_return_point('/a-route-that-does-not-exist/', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718')

with self.assertRaises(ValueError):
parse_ballot_edit_return_point('https://example.com/phishing', 'draft-ietf-opsawg-ipfix-tcpo-v6eh', '998718')

def test_valid_default_return_to_url(self):
self.assertEqual(parse_ballot_edit_return_point(
Expand Down
13 changes: 13 additions & 0 deletions ietf/doc/views_ballot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,23 @@ def rsab_ballot_status(request):
def parse_ballot_edit_return_point(path, doc_name, ballot_id):
get_default_path = lambda: urlreverse("ietf.doc.views_doc.document_ballot", kwargs=dict(name=doc_name, ballot_id=ballot_id))
allowed_path_handlers = {
"ietf.community.views.view_list",
"ietf.doc.views_doc.document_ballot",
"ietf.doc.views_doc.document_irsg_ballot",
"ietf.doc.views_doc.document_rsab_ballot",
"ietf.doc.views_ballot.irsg_ballot_status",
"ietf.doc.views_ballot.rsab_ballot_status",
"ietf.doc.views_search.search",
"ietf.doc.views_search.docs_for_ad",
"ietf.doc.views_search.drafts_in_last_call",
"ietf.doc.views_search.recent_drafts",
"ietf.group.views.chartering_groups",
"ietf.group.views.group_documents",
"ietf.group.views.stream_documents",
"ietf.iesg.views.agenda",
"ietf.iesg.views.agenda_documents",
"ietf.iesg.views.discusses",
"ietf.iesg.views.past_documents",
}
return validate_return_to_path(path, get_default_path, allowed_path_handlers)

10 changes: 9 additions & 1 deletion ietf/doc/views_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

from django.core.cache import caches
from django.db.models import Max
from django.http import HttpResponse, Http404
from django.http import HttpResponse, Http404, HttpResponseBadRequest
from django.shortcuts import render, get_object_or_404, redirect
from django.template.loader import render_to_string
from django.urls import reverse as urlreverse
Expand Down Expand Up @@ -73,6 +73,7 @@
role_required, is_individual_draft_author, can_request_rfc_publication)
from ietf.name.models import StreamName, BallotPositionName
from ietf.utils.history import find_history_active_at
from ietf.doc.views_ballot import parse_ballot_edit_return_point
from ietf.doc.forms import InvestigateForm, TelechatForm, NotifyForm, ActionHoldersForm, DocAuthorForm, DocAuthorChangeBasisForm
from ietf.doc.mails import email_comment, email_remind_action_holders
from ietf.mailtrigger.utils import gather_relevant_expansions
Expand Down Expand Up @@ -1586,11 +1587,18 @@ def ballot_popup(request, name, ballot_id):
doc = get_object_or_404(Document, name=name)
c = document_ballot_content(request, doc, ballot_id=ballot_id, editable=False)
ballot = get_object_or_404(BallotDocEvent,id=ballot_id)

try:
return_to_url = parse_ballot_edit_return_point(request.GET.get('ballot_edit_return_point'), name, ballot_id)
except ValueError:
return HttpResponseBadRequest('ballot_edit_return_point is invalid')

return render(request, "doc/ballot_popup.html",
dict(doc=doc,
ballot_content=c,
ballot_id=ballot_id,
ballot_type_slug=ballot.ballot_type.slug,
ballot_edit_return_point=return_to_url,
editable=True,
))

Expand Down
2 changes: 1 addition & 1 deletion ietf/templates/doc/ballot_popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% if editable and user|has_role:"Area Director,Secretariat,IRSG Member,RSAB Member" %}
{% if user|can_ballot:doc %}
<a class="btn btn-primary"
href="{% url "ietf.doc.views_ballot.edit_position" name=doc.name ballot_id=ballot_id %}?ballot_edit_return_point={{ request.path|urlencode }}">
href="{% url "ietf.doc.views_ballot.edit_position" name=doc.name ballot_id=ballot_id %}?ballot_edit_return_point={{ ballot_edit_return_point|urlencode }}">
Edit position
</a>
{% endif %}
Expand Down

0 comments on commit 715edaf

Please sign in to comment.