Skip to content

Commit abb6933

Browse files
committed
Added a warning message for the user if ballot creation failed due to an already open ballot. This is a bad state, and should prevented by stricter checks before changing state, but is better than the current situation until we decide exactly which checks to implement.
- Legacy-Id: 14382
1 parent 999cd50 commit abb6933

5 files changed

Lines changed: 30 additions & 14 deletions

File tree

ietf/doc/utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from collections import defaultdict
99

1010
from django.conf import settings
11+
from django.contrib import messages
1112
from django.forms import ValidationError
1213
from django.utils.html import escape
1314
from django.urls import reverse as urlreverse
@@ -174,15 +175,21 @@ def needed_ballot_positions(doc, active_positions):
174175

175176
return " ".join(answer)
176177

177-
def create_ballot_if_not_open(doc, by, ballot_slug, time=None):
178+
def create_ballot_if_not_open(request, doc, by, ballot_slug, time=None):
179+
ballot_type = BallotType.objects.get(doc_type=doc.type, slug=ballot_slug)
178180
if not doc.ballot_open(ballot_slug):
179181
if time:
180182
e = BallotDocEvent(type="created_ballot", by=by, doc=doc, rev=doc.rev, time=time)
181183
else:
182184
e = BallotDocEvent(type="created_ballot", by=by, doc=doc, rev=doc.rev)
183-
e.ballot_type = BallotType.objects.get(doc_type=doc.type, slug=ballot_slug)
185+
e.ballot_type = ballot_type
184186
e.desc = u'Created "%s" ballot' % e.ballot_type.name
185187
e.save()
188+
return e
189+
else:
190+
if request:
191+
messages.warning(request, "There already exists an open '%s' ballot for %s. No new ballot created." % (ballot_type, doc.name))
192+
return None
186193

187194
def close_ballot(doc, by, ballot_slug):
188195
if doc.ballot_open(ballot_slug):

ietf/doc/views_ballot.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
from ietf.doc.lastcall import request_last_call
2424
from ietf.iesg.models import TelechatDate
2525
from ietf.ietfauth.utils import has_role, role_required, is_authorized_in_doc_stream
26+
from ietf.mailtrigger.utils import gather_address_lists
27+
from ietf.mailtrigger.forms import CcSelectForm
2628
from ietf.message.utils import infer_message
2729
from ietf.name.models import BallotPositionName
2830
from ietf.person.models import Person
31+
from ietf.utils import log
2932
from ietf.utils.mail import send_mail_text, send_mail_preformatted
30-
from ietf.mailtrigger.utils import gather_address_lists
31-
from ietf.mailtrigger.forms import CcSelectForm
3233

3334
BALLOT_CHOICES = (("yes", "Yes"),
3435
("noobj", "No Objection"),
@@ -233,7 +234,6 @@ def edit_position(request, name, ballot_id):
233234
blocking_positions=json.dumps(blocking_positions),
234235
))
235236

236-
237237
@role_required('Area Director','Secretariat')
238238
def send_ballot_comment(request, name, ballot_id):
239239
"""Email document ballot position discuss/comment for Area Director."""
@@ -329,7 +329,7 @@ def clear_ballot(request, name):
329329
by = request.user.person
330330
for t in BallotType.objects.filter(doc_type=doc.type_id):
331331
close_ballot(doc, by, t.slug)
332-
create_ballot_if_not_open(doc, by, t.slug)
332+
create_ballot_if_not_open(request, doc, by, t.slug)
333333
if doc.get_state('draft-iesg').slug == 'defer':
334334
do_undefer_ballot(request,doc)
335335
return redirect("ietf.doc.views_doc.document_main", name=doc.name)
@@ -533,9 +533,9 @@ def ballot_writeupnotes(request, name):
533533
existing.save()
534534

535535
if "issue_ballot" in request.POST:
536-
create_ballot_if_not_open(doc, login, "approve")
536+
e = create_ballot_if_not_open(request, doc, login, "approve") # pyflakes:ignore
537537
ballot = doc.latest_event(BallotDocEvent, type="created_ballot")
538-
538+
log.assertion('ballot == e')
539539
if has_role(request.user, "Area Director") and not doc.latest_event(BallotPositionDocEvent, ad=login, ballot=ballot):
540540
# sending the ballot counts as a yes
541541
pos = BallotPositionDocEvent(doc=doc, rev=doc.rev, by=login)

ietf/doc/views_charter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,16 @@ def change_state(request, name, option=None):
152152

153153
if charter_state.slug == "intrev" and group.type_id == "wg":
154154
if request.POST.get("ballot_wo_extern"):
155-
create_ballot_if_not_open(charter, by, "r-wo-ext")
155+
create_ballot_if_not_open(request, charter, by, "r-wo-ext")
156156
else:
157-
create_ballot_if_not_open(charter, by, "r-extrev")
157+
create_ballot_if_not_open(request, charter, by, "r-extrev")
158158
(e1, e2) = default_review_text(group, charter, by)
159159
e1.save()
160160
e2.save()
161161
e = default_action_text(group, charter, by)
162162
e.save()
163163
elif charter_state.slug in ["extrev","iesgrev"]:
164-
create_ballot_if_not_open(charter, by, "approve")
164+
create_ballot_if_not_open(request, charter, by, "approve")
165165
elif charter_state.slug == "approved":
166166
change_group_state_after_charter_approval(group, by)
167167
fix_charter_revision_after_approval(charter, by)

ietf/doc/views_conflict_review.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from django.template.loader import render_to_string
88
from django.conf import settings
99

10+
import debug # pyflakes:ignore
11+
1012
from ietf.doc.models import ( BallotDocEvent, BallotPositionDocEvent, DocAlias, DocEvent,
1113
Document, NewRevisionDocEvent, State )
1214
from ietf.doc.utils import ( add_state_change_event, close_open_ballots,
@@ -17,6 +19,7 @@
1719
from ietf.iesg.models import TelechatDate
1820
from ietf.ietfauth.utils import has_role, role_required, is_authorized_in_doc_stream
1921
from ietf.person.models import Person
22+
from ietf.utils import log
2023
from ietf.utils.mail import send_mail_preformatted
2124
from ietf.utils.textupload import get_cleaned_text_file_content
2225
from ietf.mailtrigger.utils import gather_address_lists
@@ -55,8 +58,9 @@ def change_state(request, name, option=None):
5558
review.save_with_history(events)
5659

5760
if new_state.slug == "iesgeval":
58-
create_ballot_if_not_open(review, login, "conflrev")
61+
e = create_ballot_if_not_open(request, review, login, "conflrev") # pyflakes:ignore
5962
ballot = review.latest_event(BallotDocEvent, type="created_ballot")
63+
log.assertion('ballot == e')
6064
if has_role(request.user, "Area Director") and not review.latest_event(BallotPositionDocEvent, ad=login, ballot=ballot, type="changed_ballot_position"):
6165

6266
# The AD putting a conflict review into iesgeval who doesn't already have a position is saying "yes"

ietf/doc/views_status_change.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from django.template.loader import render_to_string
88
from django.conf import settings
99

10+
import debug # pyflakes:ignore
11+
1012
from ietf.doc.models import ( Document, DocAlias, State, DocEvent, BallotDocEvent,
1113
BallotPositionDocEvent, NewRevisionDocEvent, WriteupDocEvent, STATUSCHANGE_RELATIONS )
1214
from ietf.doc.forms import AdForm
@@ -16,11 +18,13 @@
1618
from ietf.group.models import Group
1719
from ietf.iesg.models import TelechatDate
1820
from ietf.ietfauth.utils import has_role, role_required
21+
from ietf.mailtrigger.utils import gather_address_lists
1922
from ietf.name.models import DocRelationshipName, StdLevelName
2023
from ietf.person.models import Person
24+
from ietf.utils import log
2125
from ietf.utils.mail import send_mail_preformatted
2226
from ietf.utils.textupload import get_cleaned_text_file_content
23-
from ietf.mailtrigger.utils import gather_address_lists
27+
2428

2529
class ChangeStateForm(forms.Form):
2630
new_state = forms.ModelChoiceField(State.objects.filter(type="statchg", used=True), label="Status Change Evaluation State", empty_label=None, required=True)
@@ -55,8 +59,9 @@ def change_state(request, name, option=None):
5559
status_change.save_with_history(events)
5660

5761
if new_state.slug == "iesgeval":
58-
create_ballot_if_not_open(status_change, login, "statchg", status_change.time)
62+
e = create_ballot_if_not_open(request, status_change, login, "statchg", status_change.time) # pyflakes:ignore
5963
ballot = status_change.latest_event(BallotDocEvent, type="created_ballot")
64+
log.assertion('ballot == e')
6065
if has_role(request.user, "Area Director") and not status_change.latest_event(BallotPositionDocEvent, ad=login, ballot=ballot, type="changed_ballot_position"):
6166

6267
# The AD putting a status change into iesgeval who doesn't already have a position is saying "yes"

0 commit comments

Comments
 (0)