forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews_ballot.py
More file actions
1384 lines (1144 loc) · 57.1 KB
/
views_ballot.py
File metadata and controls
1384 lines (1144 loc) · 57.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright The IETF Trust 2010-2020, All Rights Reserved
# -*- coding: utf-8 -*-
# ballot management (voting, commenting, writeups, ...) for Area
# Directors and Secretariat
import datetime
import json
from django import forms
from django.conf import settings
from django.http import HttpResponse, HttpResponseNotAllowed, HttpResponseRedirect, Http404, HttpResponseBadRequest
from django.shortcuts import render, get_object_or_404, redirect
from django.template.defaultfilters import striptags
from django.template.loader import render_to_string
from django.urls import reverse as urlreverse
from django.views.decorators.csrf import csrf_exempt
from django.utils.html import escape
import debug # pyflakes:ignore
from ietf.doc.models import ( Document, State, DocEvent, BallotDocEvent,
IRSGBallotDocEvent, BallotPositionDocEvent, LastCallDocEvent, WriteupDocEvent,
IESG_SUBSTATE_TAGS, RelatedDocument, BallotType )
from ietf.doc.utils import ( add_state_change_event, close_ballot, close_open_ballots,
create_ballot_if_not_open, update_telechat, update_action_holders )
from ietf.doc.mails import ( email_ballot_deferred, email_ballot_undeferred,
extra_automation_headers, generate_last_call_announcement,
generate_issue_ballot_mail, generate_ballot_writeup, generate_ballot_rfceditornote,
generate_approval_mail, email_irsg_ballot_closed, email_irsg_ballot_issued,
email_rsab_ballot_issued, email_rsab_ballot_closed,
email_lc_to_yang_doctors )
from ietf.doc.lastcall import request_last_call
from ietf.doc.templatetags.ietf_filters import can_ballot
from ietf.iesg.models import TelechatDate
from ietf.ietfauth.utils import has_role, role_required, is_authorized_in_doc_stream
from ietf.mailtrigger.models import Recipient
from ietf.mailtrigger.utils import gather_address_lists
from ietf.mailtrigger.forms import CcSelectForm
from ietf.message.utils import infer_message
from ietf.name.models import BallotPositionName, DocTypeName
from ietf.person.models import Person
from ietf.utils.fields import ModelMultipleChoiceField, MultiEmailField
from ietf.utils.http import validate_return_to_path
from ietf.utils.mail import decode_header_value, send_mail_text, send_mail_preformatted
from ietf.utils.decorators import require_api_key
from ietf.utils.response import permission_denied
from ietf.utils.timezone import date_today, datetime_from_date, DEADLINE_TZINFO
# -------------------------------------------------
# Helper Functions
# -------------------------------------------------
def do_undefer_ballot(request, doc):
'''
Helper function to perform undefer of ballot. Takes the Request object, for use in
logging, and the Document object.
'''
by = request.user.person
telechat_date = TelechatDate.objects.active().order_by("date")[0].date
new_state = doc.get_state()
prev_tags = []
new_tags = []
if doc.type_id == 'draft':
new_state = State.objects.get(used=True, type="draft-iesg", slug='iesg-eva')
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
elif doc.type_id in ['conflrev','statchg']:
new_state = State.objects.get(used=True, type=doc.type_id, slug='iesgeval')
prev_state = doc.get_state(new_state.type_id if new_state else None)
doc.set_state(new_state)
doc.tags.remove(*prev_tags)
events = []
e = add_state_change_event(doc, by, prev_state, new_state, prev_tags=prev_tags, new_tags=new_tags)
if e:
events.append(e)
e = update_action_holders(doc, prev_state, new_state, prev_tags=prev_tags, new_tags=new_tags)
if e:
events.append(e)
e = update_telechat(request, doc, by, telechat_date)
if e:
events.append(e)
if events:
doc.save_with_history(events)
email_ballot_undeferred(request, doc, by.plain_name(), telechat_date)
# -------------------------------------------------
class EditPositionForm(forms.Form):
position = forms.ModelChoiceField(queryset=BallotPositionName.objects.all(), widget=forms.RadioSelect, initial="norecord", required=True)
discuss = forms.CharField(required=False, widget=forms.Textarea, strip=False)
comment = forms.CharField(required=False, widget=forms.Textarea, strip=False)
def __init__(self, *args, **kwargs):
ballot_type = kwargs.pop("ballot_type")
super(EditPositionForm, self).__init__(*args, **kwargs)
self.fields['position'].queryset = ballot_type.positions.order_by('order')
if ballot_type.positions.filter(blocking=True).exists():
self.fields['discuss'].label = ballot_type.positions.get(blocking=True).name
def clean_discuss(self):
entered_discuss = self.cleaned_data["discuss"]
entered_pos = self.cleaned_data.get("position", BallotPositionName.objects.get(slug="norecord"))
if entered_pos.blocking and not entered_discuss:
raise forms.ValidationError("You must enter a non-empty discuss")
return entered_discuss
def save_position(form, doc, ballot, balloter, login=None, send_email=False):
# save the vote
if login is None:
login = balloter
clean = form.cleaned_data
old_pos = doc.latest_event(BallotPositionDocEvent, type="changed_ballot_position", balloter=balloter, ballot=ballot)
pos = BallotPositionDocEvent(doc=doc, rev=doc.rev, by=login)
pos.type = "changed_ballot_position"
pos.ballot = ballot
pos.balloter = balloter
pos.pos = clean["position"]
pos.comment = clean["comment"].rstrip()
pos.comment_time = old_pos.comment_time if old_pos else None
pos.discuss = clean["discuss"].rstrip()
pos.send_email = send_email
if not pos.pos.blocking:
pos.discuss = ""
pos.discuss_time = old_pos.discuss_time if old_pos else None
changes = []
added_events = []
# possibly add discuss/comment comments to history trail
# so it's easy to see what's happened
old_comment = old_pos.comment if old_pos else ""
if pos.comment != old_comment:
pos.comment_time = pos.time
changes.append("comment")
if pos.comment:
e = DocEvent(doc=doc, rev=doc.rev, by=balloter)
e.type = "added_comment"
e.desc = "[Ballot comment]\n" + pos.comment
added_events.append(e)
old_discuss = old_pos.discuss if old_pos else ""
if pos.discuss != old_discuss:
pos.discuss_time = pos.time
changes.append("discuss")
if pos.pos.blocking:
e = DocEvent(doc=doc, rev=doc.rev, by=balloter)
e.type = "added_comment"
e.desc = "[Ballot %s]\n" % pos.pos.name.lower()
e.desc += pos.discuss
added_events.append(e)
# figure out a description
if not old_pos and pos.pos.slug != "norecord":
pos.desc = "[Ballot Position Update] New position, %s, has been recorded for %s" % (pos.pos.name, pos.balloter.plain_name())
elif old_pos and pos.pos != old_pos.pos:
pos.desc = "[Ballot Position Update] Position for %s has been changed to %s from %s" % (pos.balloter.plain_name(), pos.pos.name, old_pos.pos.name)
if not pos.desc and changes:
pos.desc = "Ballot %s text updated for %s" % (" and ".join(changes), balloter.plain_name())
# only add new event if we actually got a change
if pos.desc:
if login != balloter:
pos.desc += " by %s" % login.plain_name()
pos.save()
for e in added_events:
e.save() # save them after the position is saved to get later id for sorting order
return pos
class AdditionalCCForm(forms.Form):
additional_cc = MultiEmailField(required=False)
@role_required("Area Director", "Secretariat", "IRSG Member", "RSAB Member")
def edit_position(request, name, ballot_id):
"""Vote and edit discuss and comment on document"""
doc = get_object_or_404(Document, name=name)
ballot = get_object_or_404(BallotDocEvent, type="created_ballot", pk=ballot_id, doc=doc)
balloter = login = request.user.person
try:
return_to_url = parse_ballot_edit_return_point(request.GET.get('ballot_edit_return_point'), doc.name, ballot_id)
except ValueError:
return HttpResponseBadRequest('ballot_edit_return_point is invalid')
# if we're in the Secretariat, we can select a balloter to act as stand-in for
if has_role(request.user, "Secretariat"):
balloter_id = request.GET.get('balloter')
if not balloter_id:
raise Http404
balloter = get_object_or_404(Person, pk=balloter_id)
if doc.stream_id == 'irtf':
mailtrigger_slug='irsg_ballot_saved'
elif doc.stream_id == 'editorial':
mailtrigger_slug='rsab_ballot_saved'
else:
mailtrigger_slug='iesg_ballot_saved'
if request.method == 'POST':
old_pos = None
if not has_role(request.user, "Secretariat") and not can_ballot(request.user, doc):
# prevent pre-ADs from taking a position
permission_denied(request, "Must be an active member (not a pre-AD for example) of the balloting body to take a position")
if request.POST.get("Defer") and doc.stream.slug != "irtf":
return redirect('ietf.doc.views_ballot.defer_ballot', name=doc)
elif request.POST.get("Undefer") and doc.stream.slug != "irtf":
return redirect('ietf.doc.views_ballot.undefer_ballot', name=doc)
form = EditPositionForm(request.POST, ballot_type=ballot.ballot_type)
cc_select_form = CcSelectForm(data=request.POST,mailtrigger_slug=mailtrigger_slug,mailtrigger_context={'doc':doc})
additional_cc_form = AdditionalCCForm(request.POST)
if form.is_valid() and cc_select_form.is_valid() and additional_cc_form.is_valid():
send_mail = True if request.POST.get("send_mail") else False
pos = save_position(form, doc, ballot, balloter, login, send_mail)
if send_mail:
addrs, frm, subject, body = build_position_email(balloter, doc, pos)
if doc.stream_id == 'irtf':
mailtrigger_slug='irsg_ballot_saved'
elif doc.stream_id == 'editorial':
mailtrigger_slug='rsab_ballot_saved'
else:
mailtrigger_slug='iesg_ballot_saved'
cc = []
cc.extend(cc_select_form.get_selected_addresses())
extra_cc = additional_cc_form.cleaned_data["additional_cc"]
if extra_cc:
cc.extend(extra_cc)
cc_set = set(cc)
cc_set.discard("")
cc = sorted(list(cc_set))
send_mail_text(request, addrs.to, frm, subject, body, cc=", ".join(cc))
return redirect(return_to_url)
else:
initial = {}
old_pos = doc.latest_event(BallotPositionDocEvent, type="changed_ballot_position", balloter=balloter, ballot=ballot)
if old_pos:
initial['position'] = old_pos.pos.slug
initial['discuss'] = old_pos.discuss
initial['comment'] = old_pos.comment
form = EditPositionForm(initial=initial, ballot_type=ballot.ballot_type)
cc_select_form = CcSelectForm(mailtrigger_slug=mailtrigger_slug,mailtrigger_context={'doc':doc})
additional_cc_form = AdditionalCCForm()
blocking_positions = dict((p.pk, p.name) for p in form.fields["position"].queryset.all() if p.blocking)
ballot_deferred = doc.active_defer_event()
return render(request, 'doc/ballot/edit_position.html',
dict(doc=doc,
form=form,
cc_select_form=cc_select_form,
additional_cc_form=additional_cc_form,
balloter=balloter,
return_to_url=return_to_url,
old_pos=old_pos,
ballot_deferred=ballot_deferred,
ballot = ballot,
show_discuss_text=old_pos and old_pos.pos.blocking,
blocking_positions=json.dumps(blocking_positions),
))
@require_api_key
@role_required('Area Director')
@csrf_exempt
def api_set_position(request):
def err(code, text):
return HttpResponse(
text,
status=code,
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
)
if request.method == 'POST':
ad = request.user.person
name = request.POST.get('doc')
if not name:
return err(400, "Missing document name")
try:
doc = Document.objects.get(name=name)
except Document.DoesNotExist:
return err(400, "Document not found")
position_names = BallotPositionName.objects.values_list('slug', flat=True)
position = request.POST.get('position')
if not position:
return err(400, "Missing parameter: position, one of: %s " % ','.join(position_names))
if not position in position_names:
return err(400, "Bad position name, must be one of: %s " % ','.join(position_names))
ballot = doc.active_ballot()
if not ballot:
return err(400, "No open ballot found")
form = EditPositionForm(request.POST, ballot_type=ballot.ballot_type)
if form.is_valid():
pos = save_position(form, doc, ballot, ad, send_email=True)
else:
errors = form.errors
summary = ','.join([ "%s: %s" % (f, striptags(errors[f])) for f in errors ])
return err(400, "Form not valid: %s" % summary)
else:
return err(405, "Method not allowed")
# send position email
addrs, frm, subject, body = build_position_email(ad, doc, pos)
send_mail_text(request, addrs.to, frm, subject, body, cc=addrs.cc)
return HttpResponse(
"Done",
status=200,
content_type=f"text/plain; charset={settings.DEFAULT_CHARSET}",
)
@role_required("Area Director", "Secretariat")
@csrf_exempt
def ajax_build_position_email(request):
if request.method != "POST":
return HttpResponseNotAllowed(["POST"])
errors = list()
try:
json_body = json.loads(request.body)
except json.decoder.JSONDecodeError:
errors.append("Post body is not valid json")
if len(errors) == 0:
post_data = json_body.get("post_data")
if post_data is None:
errors.append("post_data not provided")
else:
for key in [
"discuss",
"comment",
"position",
"balloter",
"docname",
"cc_choices",
"additional_cc",
]:
if key not in post_data:
errors.append(f"{key} not found in post_data")
if len(errors) == 0:
person = Person.objects.filter(pk=post_data.get("balloter")).first()
if person is None:
errors.append("No person found matching balloter")
doc = Document.objects.filter(name=post_data.get("docname")).first()
if doc is None:
errors.append("No document found matching docname")
if len(errors) > 0:
response = {
"success": False,
"errors": errors,
}
else:
wanted = dict() # consider named tuple instead
wanted["discuss"] = post_data.get("discuss")
wanted["comment"] = post_data.get("comment")
wanted["position_name"] = post_data.get("position")
wanted["balloter"] = person
wanted["doc"] = doc
addrs, frm, subject, body = build_position_email_from_dict(wanted)
recipient_slugs = post_data.get("cc_choices")
# Consider refactoring gather_address_lists so this isn't duplicated from there
cc_addrs = set()
for r in Recipient.objects.filter(slug__in=recipient_slugs):
cc_addrs.update(r.gather(doc=doc))
additional_cc = post_data.get("additional_cc")
for addr in additional_cc.split(","):
cc_addrs.add(addr.strip())
cc_addrs.discard("")
cc_addrs = sorted(list(cc_addrs))
response_text = "\n".join(
[
f"From: {decode_header_value(frm)}",
f"To: {', '.join([decode_header_value(addr) for addr in addrs.to])}",
f"Cc: {', '.join([decode_header_value(addr) for addr in cc_addrs])}",
f"Subject: {subject}",
"",
body,
]
)
response = {
"success": True,
"text": response_text,
}
return HttpResponse(json.dumps(response), content_type="application/json")
def build_position_email_from_dict(pos_dict):
doc = pos_dict["doc"]
subj = []
d = ""
blocking_name = "DISCUSS"
pos_name = BallotPositionName.objects.filter(slug=pos_dict["position_name"]).first()
if pos_name.blocking and pos_dict.get("discuss"):
d = pos_dict.get("discuss")
blocking_name = pos_name.name.upper()
subj.append(blocking_name)
c = ""
if pos_dict.get("comment"):
c = pos_dict.get("comment")
subj.append("COMMENT")
balloter = pos_dict.get("balloter")
balloter_name_genitive = balloter.plain_name() + "'" if balloter.plain_name().endswith('s') else balloter.plain_name() + "'s"
subject = "%s %s on %s" % (balloter_name_genitive, pos_name.name if pos_name else "No Position", doc.name + "-" + doc.rev)
if subj:
subject += ": (with %s)" % " and ".join(subj)
body = render_to_string("doc/ballot/ballot_comment_mail.txt",
dict(discuss=d,
comment=c,
balloter=balloter.plain_name(),
doc=doc,
pos=pos_name,
blocking_name=blocking_name,
settings=settings))
frm = balloter.role_email("ad").formatted_email()
if doc.stream_id == "irtf":
addrs = gather_address_lists('irsg_ballot_saved',doc=doc)
elif doc.stream_id == "editorial":
addrs = gather_address_lists('rsab_ballot_saved',doc=doc)
else:
addrs = gather_address_lists('iesg_ballot_saved',doc=doc)
return addrs, frm, subject, body
def build_position_email(balloter, doc, pos):
pos_dict=dict()
pos_dict["doc"]=doc
pos_dict["position_name"]=pos.pos.slug
pos_dict["discuss"]=pos.discuss
pos_dict["comment"]=pos.comment
pos_dict["balloter"]=balloter
return build_position_email_from_dict(pos_dict)
@role_required('Area Director','Secretariat')
def clear_ballot(request, name, ballot_type_slug):
"""Clear all positions and discusses on every open ballot for a document."""
doc = get_object_or_404(Document, name=name)
# If there's no appropriate ballot type state, clearing would be an invalid action.
# This will need to be updated if we ever allow defering IRTF ballots
if ballot_type_slug == "approve":
state_machine = "draft-iesg"
elif ballot_type_slug in ["statchg","conflrev"]:
state_machine = ballot_type_slug
else:
state_machine = None
state_slug = state_machine and doc.get_state_slug(state_machine)
if state_machine is None or state_slug is None:
raise Http404
if request.method == 'POST':
by = request.user.person
if close_ballot(doc, by, ballot_type_slug):
create_ballot_if_not_open(request, doc, by, ballot_type_slug)
if state_slug == "defer":
do_undefer_ballot(request,doc)
return redirect("ietf.doc.views_doc.document_main", name=doc.name)
return render(request, 'doc/ballot/clear_ballot.html',
dict(doc=doc,
back_url=doc.get_absolute_url()))
@role_required('Area Director','Secretariat')
def defer_ballot(request, name):
"""Signal post-pone of ballot, notifying relevant parties."""
doc = get_object_or_404(Document, name=name)
if doc.type_id not in ('draft','conflrev','statchg'):
raise Http404
interesting_state = dict(draft='draft-iesg',conflrev='conflrev',statchg='statchg')
state = doc.get_state(interesting_state[doc.type_id])
if not state or state.slug=='defer' or not doc.telechat_date():
raise Http404
login = request.user.person
telechat_date = TelechatDate.objects.active().order_by("date")[1].date
if request.method == 'POST':
new_state = doc.get_state()
prev_tags = []
new_tags = []
if doc.type_id == 'draft':
new_state = State.objects.get(used=True, type="draft-iesg", slug='defer')
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
elif doc.type_id in ['conflrev','statchg']:
new_state = State.objects.get(used=True, type=doc.type_id, slug='defer')
prev_state = doc.get_state(new_state.type_id if new_state else None)
doc.set_state(new_state)
doc.tags.remove(*prev_tags)
events = []
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=new_tags)
if e:
events.append(e)
e = update_action_holders(doc, prev_state, new_state, prev_tags=prev_tags, new_tags=new_tags)
if e:
events.append(e)
e = update_telechat(request, doc, login, telechat_date)
if e:
events.append(e)
doc.save_with_history(events)
email_ballot_deferred(request, doc, login.plain_name(), telechat_date)
return HttpResponseRedirect(doc.get_absolute_url())
return render(request, 'doc/ballot/defer_ballot.html',
dict(doc=doc,
telechat_date=telechat_date,
back_url=doc.get_absolute_url()))
@role_required('Area Director','Secretariat')
def undefer_ballot(request, name):
"""undo deferral of ballot ballot."""
doc = get_object_or_404(Document, name=name)
if doc.type_id not in ('draft','conflrev','statchg'):
raise Http404
if doc.type_id == 'draft' and not doc.get_state("draft-iesg"):
raise Http404
interesting_state = dict(draft='draft-iesg',conflrev='conflrev',statchg='statchg')
state = doc.get_state(interesting_state[doc.type_id])
if not state or state.slug!='defer':
raise Http404
telechat_date = TelechatDate.objects.active().order_by("date")[0].date
if request.method == 'POST':
do_undefer_ballot(request,doc)
return HttpResponseRedirect(doc.get_absolute_url())
return render(request, 'doc/ballot/undefer_ballot.html',
dict(doc=doc,
telechat_date=telechat_date,
back_url=doc.get_absolute_url()))
class LastCallTextForm(forms.Form):
last_call_text = forms.CharField(widget=forms.Textarea, required=True, strip=False)
def clean_last_call_text(self):
lines = self.cleaned_data["last_call_text"].split("\r\n")
for l, next in zip(lines, lines[1:]):
if l.startswith('Subject:') and next.strip():
raise forms.ValidationError("Subject line appears to have a line break, please make sure there is no line breaks in the subject line and that it is followed by an empty line.")
return self.cleaned_data["last_call_text"].replace("\r", "")
@role_required('Area Director','Secretariat')
def lastcalltext(request, name):
"""Editing of the last call text"""
doc = get_object_or_404(Document, name=name)
if not doc.get_state("draft-iesg"):
raise Http404
login = request.user.person
existing = doc.latest_event(WriteupDocEvent, type="changed_last_call_text")
if not existing:
existing = generate_last_call_announcement(request, doc)
form = LastCallTextForm(initial=dict(last_call_text=escape(existing.text)))
if request.method == 'POST':
if "save_last_call_text" in request.POST or "send_last_call_request" in request.POST:
form = LastCallTextForm(request.POST)
if form.is_valid():
t = form.cleaned_data['last_call_text']
if t != existing.text:
e = WriteupDocEvent(doc=doc, rev=doc.rev, by=login)
e.by = login
e.type = "changed_last_call_text"
e.desc = "Last call announcement was changed"
e.text = t
e.save()
elif existing.pk == None:
existing.save()
if "send_last_call_request" in request.POST:
prev_state = doc.get_state("draft-iesg")
new_state = State.objects.get(used=True, type="draft-iesg", slug='lc-req')
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
doc.set_state(new_state)
doc.tags.remove(*prev_tags)
events = []
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
if e:
events.append(e)
e = update_action_holders(doc, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
if e:
events.append(e)
if events:
doc.save_with_history(events)
request_last_call(request, doc)
return render(request, 'doc/draft/last_call_requested.html',
dict(doc=doc))
if "regenerate_last_call_text" in request.POST:
e = generate_last_call_announcement(request, doc)
e.save()
# make sure form has the updated text
form = LastCallTextForm(initial=dict(last_call_text=escape(e.text)))
s = doc.get_state("draft-iesg")
can_request_last_call = s.order < 27
can_make_last_call = s.order < 20
need_intended_status = ""
if not doc.intended_std_level:
need_intended_status = doc.file_tag()
return render(request, 'doc/ballot/lastcalltext.html',
dict(doc=doc,
back_url=doc.get_absolute_url(),
last_call_form=form,
can_request_last_call=can_request_last_call,
can_make_last_call=can_make_last_call,
need_intended_status=need_intended_status,
))
class BallotWriteupForm(forms.Form):
ballot_writeup = forms.CharField(widget=forms.Textarea, required=True, strip=False)
def clean_ballot_writeup(self):
return self.cleaned_data["ballot_writeup"].replace("\r", "")
@role_required('Area Director','Secretariat')
def ballot_writeupnotes(request, name):
"""Editing of ballot write-up and notes"""
doc = get_object_or_404(Document, name=name)
if doc.stream_id is None or doc.stream_id != 'ietf':
raise Http404("The requested operation is not allowed for this document.")
prev_state = doc.get_state("draft-iesg")
login = request.user.person
existing = doc.latest_event(WriteupDocEvent, type="changed_ballot_writeup_text")
if not existing:
existing = generate_ballot_writeup(request, doc)
form = BallotWriteupForm(initial=dict(ballot_writeup=escape(existing.text)))
if request.method == 'POST' and "save_ballot_writeup" in request.POST or "issue_ballot" in request.POST:
form = BallotWriteupForm(request.POST)
if form.is_valid():
if prev_state.slug in ['ann', 'approved', 'rfcqueue', 'pub']:
ballot_already_approved = True
else:
ballot_already_approved = False
t = form.cleaned_data["ballot_writeup"]
if t != existing.text:
e = WriteupDocEvent(doc=doc, rev=doc.rev, by=login)
e.by = login
e.type = "changed_ballot_writeup_text"
e.desc = "Ballot writeup was changed"
e.text = t
e.save()
elif existing.pk == None:
existing.save()
if "issue_ballot" in request.POST and not ballot_already_approved:
if prev_state.slug in ['writeupw', 'goaheadw']:
new_state = State.objects.get(used=True, type="draft-iesg", slug='iesg-eva')
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
doc.set_state(new_state)
doc.tags.remove(*prev_tags)
events = []
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
if e:
events.append(e)
e = update_action_holders(doc, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
if e:
events.append(e)
if events:
doc.save_with_history(events)
if not ballot_already_approved:
e = create_ballot_if_not_open(request, doc, login, "approve") # pyflakes:ignore
ballot = doc.latest_event(BallotDocEvent, type="created_ballot")
if has_role(request.user, "Area Director") and not doc.latest_event(BallotPositionDocEvent, balloter=login, ballot=ballot):
# sending the ballot counts as a yes
pos = BallotPositionDocEvent(doc=doc, rev=doc.rev, by=login)
pos.ballot = ballot
pos.type = "changed_ballot_position"
pos.balloter = login
pos.pos_id = "yes"
pos.desc = "[Ballot Position Update] New position, %s, has been recorded for %s" % (pos.pos.name, pos.balloter.plain_name())
pos.save()
# Consider mailing this position to 'iesg_ballot_saved'
approval = doc.latest_event(WriteupDocEvent, type="changed_ballot_approval_text")
if not approval:
approval = generate_approval_mail(request, doc)
approval.save()
msg = generate_issue_ballot_mail(request, doc, ballot)
addrs = gather_address_lists('iesg_ballot_issued',doc=doc).as_strings()
override = {'To':addrs.to}
if addrs.cc:
override['CC'] = addrs.cc
send_mail_preformatted(request, msg, override=override)
addrs = gather_address_lists('ballot_issued_iana',doc=doc).as_strings()
override={ "To": addrs.to, "Bcc": None , "Reply-To": [], "CC": addrs.cc or None }
send_mail_preformatted(request, msg, extra=extra_automation_headers(doc), override=override)
e = DocEvent(doc=doc, rev=doc.rev, by=login)
e.by = login
e.type = "sent_ballot_announcement"
e.desc = "Ballot has been issued"
e.save()
return render(request, 'doc/ballot/ballot_issued.html',
dict(doc=doc,
back_url=doc.get_absolute_url()))
need_intended_status = ""
if not doc.intended_std_level:
need_intended_status = doc.file_tag()
return render(request, 'doc/ballot/writeupnotes.html',
dict(doc=doc,
back_url=doc.get_absolute_url(),
ballot_issued=bool(doc.latest_event(type="sent_ballot_announcement")),
warn_lc = not doc.docevent_set.filter(lastcalldocevent__expires__date__lt=date_today(DEADLINE_TZINFO)).exists(),
warn_unexpected_state= prev_state if bool(prev_state.slug in ['ad-eval', 'lc']) else None,
ballot_writeup_form=form,
need_intended_status=need_intended_status,
))
class BallotRfcEditorNoteForm(forms.Form):
rfc_editor_note = forms.CharField(widget=forms.Textarea, label="RFC Editor Note", required=True, strip=False)
def clean_rfc_editor_note(self):
return self.cleaned_data["rfc_editor_note"].replace("\r", "")
@role_required('Area Director','Secretariat','IAB Chair','IRTF Chair','ISE')
def ballot_rfceditornote(request, name):
"""Editing of RFC Editor Note"""
doc = get_object_or_404(Document, name=name)
if not is_authorized_in_doc_stream(request.user, doc):
permission_denied(request, "You do not have the necessary permissions to change the RFC Editor Note for this document")
login = request.user.person
existing = doc.latest_event(WriteupDocEvent, type="changed_rfc_editor_note_text")
if not existing or (existing.text == ""):
existing = generate_ballot_rfceditornote(request, doc)
form = BallotRfcEditorNoteForm(auto_id=False, initial=dict(rfc_editor_note=escape(existing.text)))
if request.method == 'POST' and "save_ballot_rfceditornote" in request.POST:
form = BallotRfcEditorNoteForm(request.POST)
if form.is_valid():
t = form.cleaned_data["rfc_editor_note"]
if t != existing.text:
e = WriteupDocEvent(doc=doc, rev=doc.rev, by=login)
e.by = login
e.type = "changed_rfc_editor_note_text"
e.desc = f"RFC Editor Note was changed to \n{t}"
e.text = t.rstrip()
e.save()
if doc.get_state_slug('draft-iesg') in ['approved', 'ann', 'rfcqueue']:
(to, cc) = gather_address_lists('ballot_ednote_changed_late').as_strings()
msg = render_to_string(
'doc/ballot/ednote_changed_late.txt',
context = dict(
to = to,
cc = cc,
event = e,
settings = settings,
)
)
send_mail_preformatted(request, msg)
return redirect('ietf.doc.views_doc.document_writeup', name=doc.name)
if request.method == 'POST' and "clear_ballot_rfceditornote" in request.POST:
e = WriteupDocEvent(doc=doc, rev=doc.rev, by=login)
e.by = login
e.type = "changed_rfc_editor_note_text"
e.desc = "RFC Editor Note was cleared"
e.text = ""
e.save()
# make sure form shows a blank RFC Editor Note
form = BallotRfcEditorNoteForm(initial=dict(rfc_editor_note=" "))
return render(request, 'doc/ballot/rfceditornote.html',
dict(doc=doc,
back_url=doc.get_absolute_url(),
ballot_rfceditornote_form=form,
))
class ApprovalTextForm(forms.Form):
approval_text = forms.CharField(widget=forms.Textarea, required=True, strip=False)
def clean_approval_text(self):
return self.cleaned_data["approval_text"].replace("\r", "")
@role_required('Area Director','Secretariat')
def ballot_approvaltext(request, name):
"""Editing of approval text"""
doc = get_object_or_404(Document, name=name)
if not doc.get_state("draft-iesg"):
raise Http404
login = request.user.person
existing = doc.latest_event(WriteupDocEvent, type="changed_ballot_approval_text")
if not existing:
existing = generate_approval_mail(request, doc)
form = ApprovalTextForm(initial=dict(approval_text=escape(existing.text)))
if request.method == 'POST':
if "save_approval_text" in request.POST:
form = ApprovalTextForm(request.POST)
if form.is_valid():
t = form.cleaned_data['approval_text']
if t != existing.text:
e = WriteupDocEvent(doc=doc, rev=doc.rev, by=login)
e.by = login
e.type = "changed_ballot_approval_text"
e.desc = "Ballot approval text was changed"
e.text = t
e.save()
elif existing.pk == None:
existing.save()
if "regenerate_approval_text" in request.POST:
e = generate_approval_mail(request, doc)
e.save()
# make sure form has the updated text
form = ApprovalTextForm(initial=dict(approval_text=escape(e.text)))
can_announce = doc.get_state("draft-iesg").order > 19
need_intended_status = ""
if not doc.intended_std_level:
need_intended_status = doc.file_tag()
return render(request, 'doc/ballot/approvaltext.html',
dict(doc=doc,
back_url=doc.get_absolute_url(),
approval_text_form=form,
can_announce=can_announce,
need_intended_status=need_intended_status,
))
@role_required('Secretariat')
def approve_ballot(request, name):
"""Approve ballot, sending out announcement, changing state."""
doc = get_object_or_404(Document, name=name)
if not doc.get_state("draft-iesg"):
raise Http404
login = request.user.person
approval_mail_event = doc.latest_event(WriteupDocEvent, type="changed_ballot_approval_text")
if not approval_mail_event:
approval_mail_event = generate_approval_mail(request, doc)
approval_text = approval_mail_event.text
ballot_writeup_event = doc.latest_event(WriteupDocEvent, type="changed_ballot_writeup_text")
if not ballot_writeup_event:
ballot_writeup_event = generate_ballot_writeup(request, doc)
ballot_writeup = ballot_writeup_event.text
error_duplicate_rfc_editor_note = False
e = doc.latest_event(WriteupDocEvent, type="changed_rfc_editor_note_text")
if e and (e.text != ""):
if "RFC Editor Note" in ballot_writeup:
error_duplicate_rfc_editor_note = True
ballot_writeup += "\n\n" + e.text
if error_duplicate_rfc_editor_note:
return render(request, 'doc/draft/rfceditor_note_duplicate_error.html', {'doc': doc})
if "NOT be published" in approval_text:
action = "do_not_publish"
elif "To: RFC Editor" in approval_text:
action = "to_rfc_editor"
else:
action = "to_announcement_list"
# NOTE: according to Michelle Cotton <michelle.cotton@icann.org>
# (as per 2011-10-24) IANA is scraping these messages for
# information so would like to know beforehand if the format
# changes
announcement = approval_text + "\n\n" + ballot_writeup
if request.method == 'POST':
if action == "do_not_publish":
new_state = State.objects.get(used=True, type="draft-iesg", slug="dead")
else:
new_state = State.objects.get(used=True, type="draft-iesg", slug="ann")
prev_state = doc.get_state("draft-iesg")
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
events = []
if approval_mail_event.pk == None:
approval_mail_event.save()
if ballot_writeup_event.pk == None:
ballot_writeup_event.save()
if new_state.slug == "ann" and new_state.slug != prev_state.slug:
# start by notifying the RFC Editor
import ietf.sync.rfceditor
response, error = ietf.sync.rfceditor.post_approved_draft(settings.RFC_EDITOR_SYNC_NOTIFICATION_URL, doc.name)
if error:
return render(request, 'doc/draft/rfceditor_post_approved_draft_failed.html',
dict(name=doc.name,
response=response,
error=error))
doc.set_state(new_state)
doc.tags.remove(*prev_tags)
# fixup document
close_open_ballots(doc, login)
e = DocEvent(doc=doc, rev=doc.rev, by=login)
if action == "do_not_publish":
e.type = "iesg_disapproved"
e.desc = "Do Not Publish note has been sent to the RFC Editor"
else:
e.type = "iesg_approved"
e.desc = "IESG has approved the document"
e.save()
events.append(e)
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
if e:
events.append(e)
e = update_action_holders(doc, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
if e:
events.append(e)
doc.save_with_history(events)
# send announcement
send_mail_preformatted(request, announcement)
if action == "to_announcement_list":
addrs = gather_address_lists('ballot_approved_ietf_stream_iana').as_strings(compact=False)
send_mail_preformatted(request, announcement, extra=extra_automation_headers(doc),
override={ "To": addrs.to, "CC": addrs.cc, "Bcc": None, "Reply-To": []})
msg = infer_message(announcement)
msg.by = login
msg.save()
msg.related_docs.add(doc)
downrefs = [rel for rel in doc.relateddocument_set.all() if rel.is_downref() and not rel.is_approved_downref()]
if not downrefs:
return HttpResponseRedirect(doc.get_absolute_url())
else:
return HttpResponseRedirect(doc.get_absolute_url()+'edit/approvedownrefs/')
return render(request, 'doc/ballot/approve_ballot.html',
dict(doc=doc,
action=action,
announcement=announcement))