Skip to content

Commit ee346ed

Browse files
committed
Corrected the implementation of clear_ballot. Added a test for it. Restored functionality to ballot popups that was missing because a template variable was not passed in. Commit ready for merge.
- Legacy-Id: 15084
1 parent 1735f86 commit ee346ed

6 files changed

Lines changed: 27 additions & 8 deletions

File tree

ietf/doc/tests_ballot.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,23 @@ def test_disapprove_ballot(self):
644644
self.assertEqual(len(outbox), mailbox_before + 1)
645645
self.assertTrue("NOT be published" in str(outbox[-1]))
646646

647+
def test_clear_ballot(self):
648+
draft = make_test_data()
649+
ad = Person.objects.get(user__username="ad")
650+
ballot = create_ballot_if_not_open(None, draft, ad, 'approve')
651+
old_ballot_id = ballot.id
652+
draft.set_state(State.objects.get(used=True, type="draft-iesg", slug="iesg-eva"))
653+
url = urlreverse('ietf.doc.views_ballot.clear_ballot', kwargs=dict(name=draft.name,ballot_type_slug=draft.ballot_open('approve').ballot_type.slug))
654+
login_testing_unauthorized(self, "secretary", url)
655+
r = self.client.get(url)
656+
self.assertEqual(r.status_code, 200)
657+
r = self.client.post(url,{})
658+
self.assertEqual(r.status_code, 302)
659+
ballot = draft.ballot_open('approve')
660+
self.assertIsNotNone(ballot)
661+
self.assertEqual(ballot.ballotpositiondocevent_set.count(),0)
662+
self.assertNotEqual(old_ballot_id, ballot.id)
663+
647664
class MakeLastCallTests(TestCase):
648665
def test_make_last_call(self):
649666
draft = make_test_data()

ietf/doc/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
url(r'^%(name)s/edit/adopt/$' % settings.URL_REGEXPS, views_draft.adopt_draft),
109109
url(r'^%(name)s/edit/state/(?P<state_type>draft-stream-[a-z]+)/$' % settings.URL_REGEXPS, views_draft.change_stream_state),
110110

111-
url(r'^%(name)s/edit/clearballot/$' % settings.URL_REGEXPS, views_ballot.clear_ballot),
111+
url(r'^%(name)s/edit/clearballot/(?P<ballot_type_slug>[\w-]+)/$' % settings.URL_REGEXPS, views_ballot.clear_ballot),
112112
url(r'^%(name)s/edit/deferballot/$' % settings.URL_REGEXPS, views_ballot.defer_ballot),
113113
url(r'^%(name)s/edit/undeferballot/$' % settings.URL_REGEXPS, views_ballot.undefer_ballot),
114114
url(r'^%(name)s/edit/lastcalltext/$' % settings.URL_REGEXPS, views_ballot.lastcalltext),

ietf/doc/views_ballot.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import debug # pyflakes:ignore
1717

1818
from ietf.doc.models import ( Document, State, DocEvent, BallotDocEvent, BallotPositionDocEvent,
19-
BallotType, LastCallDocEvent, WriteupDocEvent, IESG_SUBSTATE_TAGS )
19+
LastCallDocEvent, WriteupDocEvent, IESG_SUBSTATE_TAGS )
2020
from ietf.doc.utils import ( add_state_change_event, close_ballot, close_open_ballots,
2121
create_ballot_if_not_open, update_telechat )
2222
from ietf.doc.mails import ( email_ballot_deferred, email_ballot_undeferred,
@@ -381,14 +381,13 @@ def send_ballot_comment(request, name, ballot_id):
381381
))
382382

383383
@role_required('Area Director','Secretariat')
384-
def clear_ballot(request, name):
384+
def clear_ballot(request, name, ballot_type_slug):
385385
"""Clear all positions and discusses on every open ballot for a document."""
386386
doc = get_object_or_404(Document, name=name)
387387
if request.method == 'POST':
388388
by = request.user.person
389-
for t in BallotType.objects.filter(doc_type=doc.type_id):
390-
close_ballot(doc, by, t.slug)
391-
create_ballot_if_not_open(request, doc, by, t.slug)
389+
if close_ballot(doc, by, ballot_type_slug):
390+
create_ballot_if_not_open(request, doc, by, ballot_type_slug)
392391
if doc.get_state('draft-iesg').slug == 'defer':
393392
do_undefer_ballot(request,doc)
394393
return redirect("ietf.doc.views_doc.document_main", name=doc.name)

ietf/doc/views_doc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,10 +964,13 @@ def document_ballot(request, name, ballot_id=None):
964964
def ballot_popup(request, name, ballot_id):
965965
doc = get_object_or_404(Document, docalias__name=name)
966966
c = document_ballot_content(request, doc, ballot_id=ballot_id, editable=False)
967+
ballot = get_object_or_404(BallotDocEvent,id=ballot_id)
967968
return render(request, "doc/ballot_popup.html",
968969
dict(doc=doc,
969970
ballot_content=c,
970971
ballot_id=ballot_id,
972+
ballot_type_slug=ballot.ballot_type.slug,
973+
editable=True,
971974
))
972975

973976

ietf/templates/doc/ballot_popup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ <h4 class="modal-title" id="modal-title-{{ ballot_id }}">Ballot for {{ doc.name
3838
{% endif %}
3939

4040
{% if user|has_role:"Secretariat" %}
41-
<a class="btn btn-danger" href="{% url 'ietf.doc.views_ballot.clear_ballot' name=doc.name %}">Clear ballot</a>
41+
<a class="btn btn-danger" href="{% url 'ietf.doc.views_ballot.clear_ballot' name=doc.name ballot_type_slug=ballot_type_slug %}">Clear ballot</a>
4242
{% endif %}
4343
{% endif %}
4444
{% endif %}

ietf/templates/doc/document_ballot_content.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ <h4><span class="label label-{{ n|pos_to_label }}"> {{ n.name }}</span></h4>
6767
{% endif %}
6868

6969
{% if user|has_role:"Area Director,Secretariat" %}
70-
<a class="btn btn-danger" href="{% url 'ietf.doc.views_ballot.clear_ballot' name=doc.name %}">Clear ballot</a>
70+
<a class="btn btn-danger" href="{% url 'ietf.doc.views_ballot.clear_ballot' name=doc.name ballot_type_slug=ballot.ballot_type.slug%}">Clear ballot</a>
7171
{% endif %}
7272
{% endif %}
7373
{% endif %}

0 commit comments

Comments
 (0)