forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews_doc.py
More file actions
1985 lines (1676 loc) · 90.4 KB
/
views_doc.py
File metadata and controls
1985 lines (1676 loc) · 90.4 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 2009-2020, All Rights Reserved
# -*- coding: utf-8 -*-
#
# Parts Copyright (C) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
# All rights reserved. Contact: Pasi Eronen <pasi.eronen@nokia.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# * Neither the name of the Nokia Corporation and/or its
# subsidiary(-ies) nor the names of its contributors may be used
# to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import datetime
import glob
import io
import json
import os
import re
from urllib.parse import quote
from django.http import HttpResponse, Http404
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
from django.conf import settings
from django import forms
import debug # pyflakes:ignore
from ietf.doc.models import ( Document, DocAlias, DocHistory, DocEvent, BallotDocEvent, BallotType,
ConsensusDocEvent, NewRevisionDocEvent, TelechatDocEvent, WriteupDocEvent, IanaExpertDocEvent,
IESG_BALLOT_ACTIVE_STATES, STATUSCHANGE_RELATIONS, DocumentActionHolder, DocumentAuthor,
RelatedDocument, RelatedDocHistory)
from ietf.doc.utils import (add_links_in_new_revision_events, augment_events_with_revision,
can_adopt_draft, can_unadopt_draft, get_chartering_type, get_tags_for_stream_id,
needed_ballot_positions, nice_consensus, prettify_std_name, update_telechat, has_same_ballot,
get_initial_notify, make_notify_changed_event, make_rev_history, default_consensus,
add_events_message_info, get_unicode_document_content, build_doc_meta_block,
augment_docs_and_user_with_user_info, irsg_needed_ballot_positions, add_action_holder_change_event,
build_doc_supermeta_block, build_file_urls, update_documentauthors, fuzzy_find_documents)
from ietf.doc.utils_bofreq import bofreq_editors, bofreq_responsible
from ietf.group.models import Role, Group
from ietf.group.utils import can_manage_all_groups_of_type, can_manage_materials, group_features_role_filter
from ietf.ietfauth.utils import ( has_role, is_authorized_in_doc_stream, user_is_person,
role_required, is_individual_draft_author)
from ietf.name.models import StreamName, BallotPositionName
from ietf.utils.history import find_history_active_at
from ietf.doc.forms import TelechatForm, NotifyForm, ActionHoldersForm, DocAuthorForm, DocAuthorChangeBasisForm
from ietf.doc.mails import email_comment, email_remind_action_holders
from ietf.mailtrigger.utils import gather_relevant_expansions
from ietf.meeting.models import Session
from ietf.meeting.utils import group_sessions, get_upcoming_manageable_sessions, sort_sessions, add_event_info_to_session_qs
from ietf.review.models import ReviewAssignment
from ietf.review.utils import can_request_review_of_doc, review_assignments_to_list_for_docs
from ietf.review.utils import no_review_from_teams_on_doc
from ietf.utils import markup_txt, log, markdown
from ietf.utils.draft import PlaintextDraft
from ietf.utils.response import permission_denied
from ietf.utils.text import maybe_split
def render_document_top(request, doc, tab, name):
tabs = []
tabs.append(("Status", "status", urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=name)), True, None))
iesg_type_slugs = set(BallotType.objects.values_list('slug',flat=True))
iesg_type_slugs.discard('irsg-approve')
iesg_ballot = doc.latest_event(BallotDocEvent, type="created_ballot", ballot_type__slug__in=iesg_type_slugs)
irsg_ballot = doc.latest_event(BallotDocEvent, type="created_ballot", ballot_type__slug='irsg-approve')
if doc.type_id == "draft" and doc.get_state("draft-stream-irtf"):
tabs.append(("IRSG Evaluation Record", "irsgballot", urlreverse("ietf.doc.views_doc.document_irsg_ballot", kwargs=dict(name=name)), irsg_ballot, None if irsg_ballot else "IRSG Evaluation Ballot has not been created yet"))
if doc.type_id in ("draft","conflrev", "statchg"):
tabs.append(("IESG Evaluation Record", "ballot", urlreverse("ietf.doc.views_doc.document_ballot", kwargs=dict(name=name)), iesg_ballot, None if iesg_ballot else "IESG Evaluation Ballot has not been created yet"))
elif doc.type_id == "charter" and doc.group.type_id == "wg":
tabs.append(("IESG Review", "ballot", urlreverse("ietf.doc.views_doc.document_ballot", kwargs=dict(name=name)), iesg_ballot, None if iesg_ballot else "IESG Review Ballot has not been created yet"))
if doc.type_id == "draft" or (doc.type_id == "charter" and doc.group.type_id == "wg"):
tabs.append(("IESG Writeups", "writeup", urlreverse('ietf.doc.views_doc.document_writeup', kwargs=dict(name=name)), True, None))
tabs.append(("Email expansions","email",urlreverse('ietf.doc.views_doc.document_email', kwargs=dict(name=name)), True, None))
tabs.append(("History", "history", urlreverse('ietf.doc.views_doc.document_history', kwargs=dict(name=name)), True, None))
if name.startswith("rfc"):
name = "RFC %s" % name[3:]
else:
name += "-" + doc.rev
return render_to_string("doc/document_top.html",
dict(doc=doc,
tabs=tabs,
selected=tab,
name=name))
def interesting_doc_relations(doc):
if isinstance(doc, Document):
cls = RelatedDocument
target = doc
elif isinstance(doc, DocHistory):
cls = RelatedDocHistory
target = doc.doc
else:
raise TypeError("Expected this method to be called with a Document or DocHistory object")
that_relationships = STATUSCHANGE_RELATIONS + ('conflrev', 'replaces', 'possibly_replaces', 'updates', 'obs')
that_doc_relationships = ('replaces', 'possibly_replaces', 'updates', 'obs')
interesting_relations_that = cls.objects.filter(target__docs=target, relationship__in=that_relationships).select_related('source')
interesting_relations_that_doc = cls.objects.filter(source=doc, relationship__in=that_doc_relationships).prefetch_related('target__docs')
return interesting_relations_that, interesting_relations_that_doc
def document_main(request, name, rev=None):
doc = get_object_or_404(Document.objects.select_related(), docalias__name=name)
# take care of possible redirections
aliases = DocAlias.objects.filter(docs=doc).values_list("name", flat=True)
if rev==None and doc.type_id == "draft" and not name.startswith("rfc"):
for a in aliases:
if a.startswith("rfc"):
return redirect("ietf.doc.views_doc.document_main", name=a)
revisions = []
for h in doc.history_set.order_by("time", "id"):
if h.rev and not h.rev in revisions:
revisions.append(h.rev)
if not doc.rev in revisions:
revisions.append(doc.rev)
latest_rev = doc.rev
snapshot = False
gh = None
if rev != None:
# find the entry in the history
for h in doc.history_set.order_by("-time"):
if rev == h.rev:
snapshot = True
doc = h
break
if not snapshot:
return redirect('ietf.doc.views_doc.document_main', name=name)
if doc.type_id == "charter":
# find old group, too
gh = find_history_active_at(doc.group, doc.time)
# set this after we've found the right doc instance
if gh:
group = gh
else:
group = doc.group
top = render_document_top(request, doc, "status", name)
telechat = doc.latest_event(TelechatDocEvent, type="scheduled_for_telechat")
if telechat and (not telechat.telechat_date or telechat.telechat_date < datetime.date.today()):
telechat = None
# specific document types
if doc.type_id == "draft":
split_content = request.COOKIES.get("full_draft", settings.USER_PREFERENCE_DEFAULTS["full_draft"]) == "off"
if request.GET.get('include_text') == "0":
split_content = True
elif request.GET.get('include_text') == "1":
split_content = False
else:
pass
interesting_relations_that, interesting_relations_that_doc = interesting_doc_relations(doc)
iesg_state = doc.get_state("draft-iesg")
if isinstance(doc, Document):
log.assertion('iesg_state', note="A document's 'draft-iesg' state should never be unset'. Failed for %s"%doc.name)
iesg_state_slug = iesg_state.slug if iesg_state else None
iesg_state_summary = doc.friendly_state()
irsg_state = doc.get_state("draft-stream-irtf")
can_edit = has_role(request.user, ("Area Director", "Secretariat"))
can_edit_authors = has_role(request.user, ("Secretariat"))
stream_slugs = StreamName.objects.values_list("slug", flat=True)
# For some reason, AnonymousUser has __iter__, but is not iterable,
# which causes problems in the filter() below. Work around this:
if request.user.is_authenticated:
roles = Role.objects.filter(group__acronym__in=stream_slugs, person__user=request.user)
roles = group_features_role_filter(roles, request.user.person, 'docman_roles')
else:
roles = []
can_change_stream = bool(can_edit or roles)
can_edit_iana_state = has_role(request.user, ("Secretariat", "IANA"))
can_edit_replaces = has_role(request.user, ("Area Director", "Secretariat", "IRTF Chair", "WG Chair", "RG Chair", "WG Secretary", "RG Secretary"))
is_author = request.user.is_authenticated and doc.documentauthor_set.filter(person__user=request.user).exists()
can_view_possibly_replaces = can_edit_replaces or is_author
rfc_number = name[3:] if name.startswith("") else None
draft_name = None
for a in aliases:
if a.startswith("draft"):
draft_name = a
rfc_aliases = [prettify_std_name(a) for a in aliases
if a.startswith("fyi") or a.startswith("std") or a.startswith("bcp")]
latest_revision = None
# Workaround to allow displaying last rev of draft that became rfc as a draft
# This should be unwound when RFCs become their own documents.
if snapshot:
doc.name = doc.doc.name
name = doc.doc.name
else:
name = doc.name
file_urls, found_types = build_file_urls(doc)
if not snapshot and doc.get_state_slug() == "rfc":
# content
content = doc.text_or_error() # pyflakes:ignore
content = markup_txt.markup(maybe_split(content, split=split_content))
content = doc.text_or_error() # pyflakes:ignore
content = markup_txt.markup(maybe_split(content, split=split_content))
if not snapshot and doc.get_state_slug() == "rfc":
if not found_types:
content = "This RFC is not currently available online."
split_content = False
elif "txt" not in found_types:
content = "This RFC is not available in plain text format."
split_content = False
else:
latest_revision = doc.latest_event(NewRevisionDocEvent, type="new_revision")
# ballot
iesg_ballot_summary = None
irsg_ballot_summary = None
due_date = None
if (iesg_state_slug in IESG_BALLOT_ACTIVE_STATES) or irsg_state:
active_ballot = doc.active_ballot()
if active_ballot:
if irsg_state:
irsg_ballot_summary = irsg_needed_ballot_positions(doc, list(active_ballot.active_balloter_positions().values()))
due_date=active_ballot.irsgballotdocevent.duedate
else:
iesg_ballot_summary = needed_ballot_positions(doc, list(active_ballot.active_balloter_positions().values()))
# submission
submission = ""
if group is None:
submission = "unknown"
elif group.type_id == "individ":
submission = "individual"
elif group.type_id == "area" and doc.stream_id == "ietf":
submission = "individual in %s area" % group.acronym
else:
if group.features.acts_like_wg:
submission = "%s %s" % (group.acronym, group.type)
else:
submission = group.acronym
submission = "<a href=\"%s\">%s</a>" % (group.about_url(), submission)
if doc.stream_id and doc.get_state_slug("draft-stream-%s" % doc.stream_id) == "c-adopt":
submission = "candidate for %s" % submission
# resurrection
resurrected_by = None
if doc.get_state_slug() == "expired":
e = doc.latest_event(type__in=("requested_resurrect", "completed_resurrect"))
if e and e.type == "requested_resurrect":
resurrected_by = e.by
# stream info
stream_state_type_slug = None
stream_state = None
if doc.stream:
stream_state_type_slug = "draft-stream-%s" % doc.stream_id
stream_state = doc.get_state(stream_state_type_slug)
stream_tags = doc.tags.filter(slug__in=get_tags_for_stream_id(doc.stream_id))
shepherd_writeup = doc.latest_event(WriteupDocEvent, type="changed_protocol_writeup")
is_shepherd = user_is_person(request.user, doc.shepherd and doc.shepherd.person)
can_edit_stream_info = is_authorized_in_doc_stream(request.user, doc)
can_edit_shepherd_writeup = can_edit_stream_info or is_shepherd or has_role(request.user, ["Area Director"])
can_edit_notify = can_edit_shepherd_writeup
can_edit_individual = is_individual_draft_author(request.user, doc)
can_edit_consensus = False
consensus = nice_consensus(default_consensus(doc))
if doc.stream_id == "ietf" and iesg_state:
show_in_states = set(IESG_BALLOT_ACTIVE_STATES)
show_in_states.update(('approved','ann','rfcqueue','pub'))
if iesg_state_slug in show_in_states:
can_edit_consensus = can_edit
e = doc.latest_event(ConsensusDocEvent, type="changed_consensus")
consensus = nice_consensus(e and e.consensus)
elif doc.stream_id in ("irtf", "iab"):
can_edit_consensus = can_edit or can_edit_stream_info
e = doc.latest_event(ConsensusDocEvent, type="changed_consensus")
consensus = nice_consensus(e and e.consensus)
can_request_review = can_request_review_of_doc(request.user, doc)
can_submit_unsolicited_review_for_teams = None
if request.user.is_authenticated:
can_submit_unsolicited_review_for_teams = Group.objects.filter(
reviewteamsettings__isnull=False, role__person__user=request.user, role__name='secr')
# mailing list search archive
search_archive = "www.ietf.org/mail-archive/web/"
if doc.stream_id == "ietf" and group.type_id == "wg" and group.list_archive:
search_archive = group.list_archive
search_archive = quote(search_archive, safe="~")
# conflict reviews
conflict_reviews = [r.source.name for r in interesting_relations_that.filter(relationship="conflrev")]
status_change_docs = interesting_relations_that.filter(relationship__in=STATUSCHANGE_RELATIONS)
status_changes = [ r.source for r in status_change_docs if r.source.get_state_slug() in ('appr-sent','appr-pend')]
proposed_status_changes = [ r.source for r in status_change_docs if r.source.get_state_slug() in ('needshep','adrev','iesgeval','defer','appr-pr')]
presentations = doc.future_presentations()
# remaining actions
actions = []
if can_adopt_draft(request.user, doc) and not doc.get_state_slug() in ["rfc"] and not snapshot:
if doc.group and doc.group.acronym != 'none': # individual submission
# already adopted in one group
button_text = "Change Document Adoption to other Group (now in %s)" % doc.group.acronym
else:
button_text = "Manage Document Adoption in Group"
actions.append((button_text, urlreverse('ietf.doc.views_draft.adopt_draft', kwargs=dict(name=doc.name))))
if can_unadopt_draft(request.user, doc) and not doc.get_state_slug() in ["rfc"] and not snapshot:
if doc.get_state_slug('draft-iesg') == 'idexists':
if doc.group and doc.group.acronym != 'none':
actions.append(("Release document from group", urlreverse('ietf.doc.views_draft.release_draft', kwargs=dict(name=doc.name))))
elif doc.stream_id == 'ise':
actions.append(("Release document from stream", urlreverse('ietf.doc.views_draft.release_draft', kwargs=dict(name=doc.name))))
else:
pass
if doc.get_state_slug() == "expired" and not resurrected_by and can_edit and not snapshot:
actions.append(("Request Resurrect", urlreverse('ietf.doc.views_draft.request_resurrect', kwargs=dict(name=doc.name))))
if doc.get_state_slug() == "expired" and has_role(request.user, ("Secretariat",)) and not snapshot:
actions.append(("Resurrect", urlreverse('ietf.doc.views_draft.resurrect', kwargs=dict(name=doc.name))))
if (doc.get_state_slug() not in ["rfc", "expired"] and doc.stream_id in ("irtf",) and not snapshot and not doc.ballot_open('irsg-approve') and can_edit_stream_info):
label = "Issue IRSG Ballot"
actions.append((label, urlreverse('ietf.doc.views_ballot.issue_irsg_ballot', kwargs=dict(name=doc.name))))
if (doc.get_state_slug() not in ["rfc", "expired"] and doc.stream_id in ("irtf",) and not snapshot and doc.ballot_open('irsg-approve') and can_edit_stream_info):
label = "Close IRSG Ballot"
actions.append((label, urlreverse('ietf.doc.views_ballot.close_irsg_ballot', kwargs=dict(name=doc.name))))
if (doc.get_state_slug() not in ["rfc", "expired"] and doc.stream_id in ("ise", "irtf")
and can_edit_stream_info and not conflict_reviews and not snapshot):
label = "Begin IETF Conflict Review"
if not doc.intended_std_level:
label += " (note that intended status is not set)"
actions.append((label, urlreverse('ietf.doc.views_conflict_review.start_review', kwargs=dict(name=doc.name))))
if (doc.get_state_slug() not in ["rfc", "expired"] and doc.stream_id in ("iab", "ise", "irtf")
and can_edit_stream_info and not snapshot):
if doc.get_state_slug('draft-stream-%s' % doc.stream_id) not in ('rfc-edit', 'pub', 'dead'):
label = "Request Publication"
if not doc.intended_std_level:
label += " (note that intended status is not set)"
if iesg_state and iesg_state_slug not in ('idexists','dead'):
label += " (Warning: the IESG state indicates ongoing IESG processing)"
actions.append((label, urlreverse('ietf.doc.views_draft.request_publication', kwargs=dict(name=doc.name))))
if doc.get_state_slug() not in ["rfc", "expired"] and doc.stream_id in ("ietf",) and not snapshot:
if iesg_state_slug == 'idexists' and can_edit:
actions.append(("Begin IESG Processing", urlreverse('ietf.doc.views_draft.edit_info', kwargs=dict(name=doc.name)) + "?new=1"))
elif can_edit_stream_info and (iesg_state_slug in ('idexists','watching')):
actions.append(("Submit to IESG for Publication", urlreverse('ietf.doc.views_draft.to_iesg', kwargs=dict(name=doc.name))))
augment_docs_and_user_with_user_info([doc], request.user)
published = doc.latest_event(type="published_rfc")
started_iesg_process = doc.latest_event(type="started_iesg_process")
review_assignments = review_assignments_to_list_for_docs([doc]).get(doc.name, [])
no_review_from_teams = no_review_from_teams_on_doc(doc, rev or doc.rev)
exp_comment = doc.latest_event(IanaExpertDocEvent,type="comment")
iana_experts_comment = exp_comment and exp_comment.desc
# See if we should show an Auth48 URL
auth48_url = None # stays None unless we are in the auth48 state
if doc.get_state_slug('draft-rfceditor') == 'auth48':
document_url = doc.documenturl_set.filter(tag_id='auth48').first()
auth48_url = document_url.url if document_url else ''
# Do not show the Auth48 URL in the "Additional URLs" section
additional_urls = doc.documenturl_set.exclude(tag_id='auth48')
# Stream description passing test
if doc.stream != None:
stream_desc = doc.stream.desc
else:
stream_desc = "(None)"
return render(request, "doc/document_draft.html",
dict(doc=doc,
group=group,
top=top,
name=name,
content=content,
split_content=split_content,
revisions=revisions,
snapshot=snapshot,
stream_desc=stream_desc,
latest_revision=latest_revision,
latest_rev=latest_rev,
can_edit=can_edit,
can_edit_authors=can_edit_authors,
can_change_stream=can_change_stream,
can_edit_stream_info=can_edit_stream_info,
can_edit_individual=can_edit_individual,
is_shepherd = is_shepherd,
can_edit_shepherd_writeup=can_edit_shepherd_writeup,
can_edit_notify=can_edit_notify,
can_edit_iana_state=can_edit_iana_state,
can_edit_consensus=can_edit_consensus,
can_edit_replaces=can_edit_replaces,
can_view_possibly_replaces=can_view_possibly_replaces,
can_request_review=can_request_review,
can_submit_unsolicited_review_for_teams=can_submit_unsolicited_review_for_teams,
rfc_number=rfc_number,
draft_name=draft_name,
telechat=telechat,
iesg_ballot_summary=iesg_ballot_summary,
# PEY: Currently not using irsg_ballot_summary in the template, but it should be. That will take a new box for IRSG data.
irsg_ballot_summary=irsg_ballot_summary,
submission=submission,
resurrected_by=resurrected_by,
replaces=interesting_relations_that_doc.filter(relationship="replaces"),
replaced_by=interesting_relations_that.filter(relationship="replaces"),
possibly_replaces=interesting_relations_that_doc.filter(relationship="possibly_replaces"),
possibly_replaced_by=interesting_relations_that.filter(relationship="possibly_replaces"),
updates=interesting_relations_that_doc.filter(relationship="updates"),
updated_by=interesting_relations_that.filter(relationship="updates"),
obsoletes=interesting_relations_that_doc.filter(relationship="obs"),
obsoleted_by=interesting_relations_that.filter(relationship="obs"),
conflict_reviews=conflict_reviews,
status_changes=status_changes,
proposed_status_changes=proposed_status_changes,
rfc_aliases=rfc_aliases,
has_errata=doc.tags.filter(slug="errata"),
published=published,
file_urls=file_urls,
additional_urls=additional_urls,
stream_state_type_slug=stream_state_type_slug,
stream_state=stream_state,
stream_tags=stream_tags,
milestones=doc.groupmilestone_set.filter(state="active"),
consensus=consensus,
iesg_state=iesg_state,
iesg_state_summary=iesg_state_summary,
rfc_editor_state=doc.get_state("draft-rfceditor"),
rfc_editor_auth48_url=auth48_url,
iana_review_state=doc.get_state("draft-iana-review"),
iana_action_state=doc.get_state("draft-iana-action"),
iana_experts_state=doc.get_state("draft-iana-experts"),
iana_experts_comment=iana_experts_comment,
started_iesg_process=started_iesg_process,
shepherd_writeup=shepherd_writeup,
search_archive=search_archive,
actions=actions,
presentations=presentations,
review_assignments=review_assignments,
no_review_from_teams=no_review_from_teams,
due_date=due_date,
))
if doc.type_id == "charter":
content = doc.text_or_error() # pyflakes:ignore
content = markup_txt.markup(content)
ballot_summary = None
if doc.get_state_slug() in ("intrev", "iesgrev"):
active_ballot = doc.active_ballot()
if active_ballot:
ballot_summary = needed_ballot_positions(doc, list(active_ballot.active_balloter_positions().values()))
else:
ballot_summary = "No active ballot found."
chartering = get_chartering_type(doc)
# inject milestones from group
milestones = None
if chartering and not snapshot:
milestones = doc.group.groupmilestone_set.filter(state="charter")
can_manage = can_manage_all_groups_of_type(request.user, doc.group.type_id)
return render(request, "doc/document_charter.html",
dict(doc=doc,
top=top,
chartering=chartering,
content=content,
txt_url=doc.get_href(),
revisions=revisions,
latest_rev=latest_rev,
snapshot=snapshot,
telechat=telechat,
ballot_summary=ballot_summary,
group=group,
milestones=milestones,
can_manage=can_manage,
))
if doc.type_id == "bofreq":
content = markdown.markdown(doc.text_or_error())
editors = bofreq_editors(doc)
responsible = bofreq_responsible(doc)
can_manage = has_role(request.user,['Secretariat', 'Area Director', 'IAB'])
editor_can_manage = doc.get_state_slug('bofreq')=='proposed' and request.user.is_authenticated and request.user.person in editors
return render(request, "doc/document_bofreq.html",
dict(doc=doc,
top=top,
revisions=revisions,
latest_rev=latest_rev,
content=content,
snapshot=snapshot,
can_manage=can_manage,
editors=editors,
responsible=responsible,
editor_can_manage=editor_can_manage,
))
if doc.type_id == "conflrev":
filename = "%s-%s.txt" % (doc.canonical_name(), doc.rev)
pathname = os.path.join(settings.CONFLICT_REVIEW_PATH,filename)
if doc.rev == "00" and not os.path.isfile(pathname):
# This could move to a template
content = "A conflict review response has not yet been proposed."
else:
content = doc.text_or_error() # pyflakes:ignore
content = markup_txt.markup(content)
ballot_summary = None
if doc.get_state_slug() in ("iesgeval", ) and doc.active_ballot():
ballot_summary = needed_ballot_positions(doc, list(doc.active_ballot().active_balloter_positions().values()))
conflictdoc = doc.related_that_doc('conflrev')[0].document
return render(request, "doc/document_conflict_review.html",
dict(doc=doc,
top=top,
content=content,
revisions=revisions,
latest_rev=latest_rev,
snapshot=snapshot,
telechat=telechat,
conflictdoc=conflictdoc,
ballot_summary=ballot_summary,
approved_states=('appr-reqnopub-pend','appr-reqnopub-sent','appr-noprob-pend','appr-noprob-sent'),
))
if doc.type_id == "statchg":
filename = "%s-%s.txt" % (doc.canonical_name(), doc.rev)
pathname = os.path.join(settings.STATUS_CHANGE_PATH,filename)
if doc.rev == "00" and not os.path.isfile(pathname):
# This could move to a template
content = "Status change text has not yet been proposed."
else:
content = doc.text_or_error() # pyflakes:ignore
ballot_summary = None
if doc.get_state_slug() in ("iesgeval"):
ballot_summary = needed_ballot_positions(doc, list(doc.active_ballot().active_balloter_positions().values()))
if isinstance(doc,Document):
sorted_relations=doc.relateddocument_set.all().order_by('relationship__name')
elif isinstance(doc,DocHistory):
sorted_relations=doc.relateddochistory_set.all().order_by('relationship__name')
else:
sorted_relations=None
return render(request, "doc/document_status_change.html",
dict(doc=doc,
top=top,
content=content,
revisions=revisions,
latest_rev=latest_rev,
snapshot=snapshot,
telechat=telechat,
ballot_summary=ballot_summary,
approved_states=('appr-pend','appr-sent'),
sorted_relations=sorted_relations,
))
# TODO : Add "recording", and "bluesheets" here when those documents are appropriately
# created and content is made available on disk
if doc.type_id in ("slides", "agenda", "minutes", "bluesheets","procmaterials",):
can_manage_material = can_manage_materials(request.user, doc.group)
presentations = doc.future_presentations()
if doc.uploaded_filename:
# we need to remove the extension for the globbing below to work
basename = os.path.splitext(doc.uploaded_filename)[0]
else:
basename = "%s-%s" % (doc.canonical_name(), doc.rev)
pathname = os.path.join(doc.get_file_path(), basename)
content = None
content_is_html = False
other_types = []
globs = glob.glob(pathname + ".*")
url = doc.get_href()
urlbase, urlext = os.path.splitext(url)
for g in globs:
extension = os.path.splitext(g)[1]
t = os.path.splitext(g)[1].lstrip(".")
if not url.endswith("/") and not url.endswith(extension):
url = urlbase + extension
if extension == ".txt":
content = doc.text_or_error()
t = "plain text"
elif extension == ".md":
content = markdown.markdown(doc.text_or_error())
content_is_html = True
t = "markdown"
other_types.append((t, url))
# determine whether uploads are allowed
can_upload = can_manage_material and not snapshot
if doc.group is None:
can_upload = can_upload and (doc.type_id == 'procmaterials')
else:
can_upload = (
can_upload
and doc.group.features.has_nonsession_materials
and doc.type_id in doc.group.features.material_types
)
return render(request, "doc/document_material.html",
dict(doc=doc,
top=top,
content=content,
content_is_html=content_is_html,
revisions=revisions,
latest_rev=latest_rev,
snapshot=snapshot,
can_manage_material=can_manage_material,
can_upload = can_upload,
other_types=other_types,
presentations=presentations,
))
if doc.type_id == "review":
basename = "{}.txt".format(doc.name)
pathname = os.path.join(doc.get_file_path(), basename)
content = get_unicode_document_content(basename, pathname)
# If we want to go back to using markup_txt.markup_unicode, call it explicitly here like this:
# content = markup_txt.markup_unicode(content, split=False, width=80)
assignments = ReviewAssignment.objects.filter(review__name=doc.name)
review_assignment = assignments.first()
other_reviews = []
if review_assignment:
other_reviews = [r for r in review_assignments_to_list_for_docs([review_assignment.review_request.doc]).get(doc.name, []) if r != review_assignment]
return render(request, "doc/document_review.html",
dict(doc=doc,
top=top,
content=content,
revisions=revisions,
latest_rev=latest_rev,
snapshot=snapshot,
review_req=review_assignment.review_request if review_assignment else None,
other_reviews=other_reviews,
assignments=assignments,
))
raise Http404("Document not found: %s" % (name + ("-%s"%rev if rev else "")))
def document_raw_id(request, name, rev=None, ext=None):
if not name.startswith('draft-'):
raise Http404
found = fuzzy_find_documents(name, rev)
num_found = found.documents.count()
if num_found == 0:
raise Http404("Document not found: %s" % name)
if num_found > 1:
raise Http404("Multiple documents matched: %s" % name)
doc = found.documents.get()
if found.matched_rev or found.matched_name.startswith('rfc'):
rev = found.matched_rev
else:
rev = doc.rev
if rev:
doc = doc.history_set.filter(rev=rev).first() or doc.fake_history_obj(rev)
base_path = os.path.join(settings.INTERNET_ALL_DRAFTS_ARCHIVE_DIR, doc.name + "-" + doc.rev + ".")
possible_types = settings.IDSUBMIT_FILE_TYPES
found_types=dict()
for t in possible_types:
if os.path.exists(base_path + t):
found_types[t]=base_path+t
if ext == None:
ext = 'txt'
if not ext in found_types:
raise Http404('dont have the file for that extension')
mimetypes = {'txt':'text/plain','html':'text/html','xml':'application/xml'}
try:
with open(found_types[ext],'rb') as f:
blob = f.read()
return HttpResponse(blob,content_type=f'{mimetypes[ext]};charset=utf-8')
except:
raise Http404
def document_html(request, name, rev=None):
found = fuzzy_find_documents(name, rev)
num_found = found.documents.count()
if num_found == 0:
raise Http404("Document not found: %s" % name)
if num_found > 1:
raise Http404("Multiple documents matched: %s" % name)
if found.matched_name.startswith('rfc') and name != found.matched_name:
return redirect('ietf.doc.views_doc.document_html', name=found.matched_name)
doc = found.documents.get()
if found.matched_rev or found.matched_name.startswith('rfc'):
rev = found.matched_rev
else:
rev = doc.rev
if rev:
doc = doc.history_set.filter(rev=rev).first() or doc.fake_history_obj(rev)
if not os.path.exists(doc.get_file_name()):
raise Http404("File not found: %s" % doc.get_file_name())
if doc.type_id in ['draft',]:
doc.supermeta = build_doc_supermeta_block(doc)
doc.meta = build_doc_meta_block(doc, settings.HTMLIZER_URL_PREFIX)
doccolor = 'bgwhite' # Unknown
if doc.type_id=='draft':
if doc.is_rfc():
if doc.related_that('obs'):
doccolor = 'bgbrown'
else:
doccolor = {
'ps' : 'bgblue',
'exp' : 'bgyellow',
'inf' : 'bgorange',
'ds' : 'bgcyan',
'hist' : 'bggrey',
'std' : 'bggreen',
'bcp' : 'bgmagenta',
'unkn' : 'bgwhite',
}.get(doc.std_level_id, 'bgwhite')
else:
doccolor = 'bgred' # Draft
return render(request, "doc/document_html.html", {"doc":doc, "doccolor":doccolor })
def document_pdfized(request, name, rev=None, ext=None):
found = fuzzy_find_documents(name, rev)
num_found = found.documents.count()
if num_found == 0:
raise Http404("Document not found: %s" % name)
if num_found > 1:
raise Http404("Multiple documents matched: %s" % name)
if found.matched_name.startswith('rfc') and name != found.matched_name:
return redirect('ietf.doc.views_doc.document_pdfized', name=found.matched_name)
doc = found.documents.get()
if found.matched_rev or found.matched_name.startswith('rfc'):
rev = found.matched_rev
else:
rev = doc.rev
if rev:
doc = doc.history_set.filter(rev=rev).first() or doc.fake_history_obj(rev)
if not os.path.exists(doc.get_file_name()):
raise Http404("File not found: %s" % doc.get_file_name())
pdf = doc.pdfized()
if pdf:
return HttpResponse(pdf,content_type='application/pdf;charset=utf-8')
else:
raise Http404
def check_doc_email_aliases():
pattern = re.compile(r'^expand-(.*?)(\..*?)?@.*? +(.*)$')
good_count = 0
tot_count = 0
with io.open(settings.DRAFT_VIRTUAL_PATH,"r") as virtual_file:
for line in virtual_file.readlines():
m = pattern.match(line)
tot_count += 1
if m:
good_count += 1
if good_count > 50 and tot_count < 3*good_count:
return True
return False
def get_doc_email_aliases(name):
if name:
pattern = re.compile(r'^expand-(%s)(\..*?)?@.*? +(.*)$'%name)
else:
pattern = re.compile(r'^expand-(.*?)(\..*?)?@.*? +(.*)$')
aliases = []
with io.open(settings.DRAFT_VIRTUAL_PATH,"r") as virtual_file:
for line in virtual_file.readlines():
m = pattern.match(line)
if m:
aliases.append({'doc_name':m.group(1),'alias_type':m.group(2),'expansion':m.group(3)})
return aliases
def document_email(request,name):
doc = get_object_or_404(Document, docalias__name=name)
top = render_document_top(request, doc, "email", name)
aliases = get_doc_email_aliases(name) if doc.type_id=='draft' else None
expansions = gather_relevant_expansions(doc=doc)
return render(request, "doc/document_email.html",
dict(doc=doc,
top=top,
aliases=aliases,
expansions=expansions,
ietf_domain=settings.IETF_DOMAIN,
)
)
def document_history(request, name):
doc = get_object_or_404(Document, docalias__name=name)
top = render_document_top(request, doc, "history", name)
# pick up revisions from events
diff_revisions = []
diffable = [ name.startswith(prefix) for prefix in ["rfc", "draft", "charter", "conflict-review", "status-change", ]]
if any(diffable):
diff_documents = [ doc ]
diff_documents.extend(Document.objects.filter(docalias__relateddocument__source=doc, docalias__relateddocument__relationship="replaces"))
if doc.get_state_slug() == "rfc":
e = doc.latest_event(type="published_rfc")
aliases = doc.docalias.filter(name__startswith="rfc")
if aliases:
name = aliases[0].name
diff_revisions.append((name, "", e.time if e else doc.time, name))
seen = set()
for e in NewRevisionDocEvent.objects.filter(type="new_revision", doc__in=diff_documents).select_related('doc').order_by("-time", "-id"):
if (e.doc.name, e.rev) in seen:
continue
seen.add((e.doc.name, e.rev))
url = ""
if name.startswith("charter"):
url = request.build_absolute_uri(urlreverse('ietf.doc.views_charter.charter_with_milestones_txt', kwargs=dict(name=e.doc.name, rev=e.rev)))
elif name.startswith("conflict-review"):
url = find_history_active_at(e.doc, e.time).get_href()
elif name.startswith("status-change"):
url = find_history_active_at(e.doc, e.time).get_href()
elif name.startswith("draft") or name.startswith("rfc"):
# rfcdiff tool has special support for IDs
url = e.doc.name + "-" + e.rev
diff_revisions.append((e.doc.name, e.rev, e.time, url))
# grab event history
events = doc.docevent_set.all().order_by("-time", "-id").select_related("by")
augment_events_with_revision(doc, events)
add_links_in_new_revision_events(doc, events, diff_revisions)
add_events_message_info(events)
# figure out if the current user can add a comment to the history
if doc.type_id == "draft" and doc.group != None:
can_add_comment = bool(has_role(request.user, ("Area Director", "Secretariat", "IRTF Chair", "IANA", "RFC Editor")) or (
request.user.is_authenticated and
Role.objects.filter(name__in=("chair", "secr"),
group__acronym=doc.group.acronym,
person__user=request.user)))
else:
can_add_comment = has_role(request.user, ("Area Director", "Secretariat", "IRTF Chair"))
return render(request, "doc/document_history.html",
dict(doc=doc,
top=top,
diff_revisions=diff_revisions,
events=events,
can_add_comment=can_add_comment,
))
def document_bibtex(request, name, rev=None):
# Make sure URL_REGEXPS did not grab too much for the rev number
if rev != None and len(rev) != 2:
mo = re.search(r"^(?P<m>[0-9]{1,2})-(?P<n>[0-9]{2})$", rev)
if mo:
name = name+"-"+mo.group(1)
rev = mo.group(2)
else:
name = name+"-"+rev
rev = None
doc = get_object_or_404(Document, docalias__name=name)
latest_revision = doc.latest_event(NewRevisionDocEvent, type="new_revision")
replaced_by = [d.name for d in doc.related_that("replaces")]
published = doc.latest_event(type="published_rfc")
rfc = latest_revision.doc if latest_revision and latest_revision.doc.get_state_slug() == "rfc" else None
if rev != None and rev != doc.rev:
# find the entry in the history
for h in doc.history_set.order_by("-time"):
if rev == h.rev:
doc = h
break
if doc.is_rfc():
# This needs to be replaced with a lookup, as the mapping may change
# over time. Probably by updating ietf/sync/rfceditor.py to add the
# as a DocAlias, and use a method on Document to retrieve it.
doi = "10.17487/RFC%04d" % int(doc.rfc_number())
else:
doi = None
return render(request, "doc/document_bibtex.bib",
dict(doc=doc,
replaced_by=replaced_by,
published=published,
rfc=rfc,
latest_revision=latest_revision,
doi=doi,
),
content_type="text/plain; charset=utf-8",
)
def document_bibxml_ref(request, name, rev=None):
if re.search(r'^rfc\d+$', name):
raise Http404()
if not name.startswith('draft-'):
name = 'draft-'+name
return document_bibxml(request, name, rev=rev)
def document_bibxml(request, name, rev=None):
# This only deals with drafts, as bibxml entries for RFCs should come from
# the RFC-Editor.