forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
153 lines (123 loc) · 4.85 KB
/
utils.py
File metadata and controls
153 lines (123 loc) · 4.85 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
# Copyright The IETF Trust 2015-2023, All Rights Reserved
from collections import namedtuple
import debug # pyflakes:ignore
from ietf.mailtrigger.models import MailTrigger, Recipient
from ietf.submit.models import Submission
from ietf.utils.mail import excludeaddrs
class AddrLists(namedtuple("AddrLists", ["to", "cc"])):
__slots__ = ()
def as_strings(self, compact=True):
separator = ", " if compact else ",\n "
to_string = separator.join(self.to)
cc_string = separator.join(self.cc)
return namedtuple("AddrListsAsStrings", ["to", "cc"])(
to=to_string, cc=cc_string
)
def gather_address_lists(
slug,
skipped_recipients=None,
create_from_slug_if_not_exists=None,
desc_if_not_exists=None,
**kwargs
):
mailtrigger = get_mailtrigger(
slug, create_from_slug_if_not_exists, desc_if_not_exists
)
to = set()
for recipient in mailtrigger.to.all():
to.update(recipient.gather(**kwargs))
to.discard("")
if skipped_recipients:
to = excludeaddrs(to, skipped_recipients)
cc = set()
for recipient in mailtrigger.cc.all():
cc.update(recipient.gather(**kwargs))
cc.discard("")
if skipped_recipients:
cc = excludeaddrs(cc, skipped_recipients)
return AddrLists(to=sorted(list(to)), cc=sorted(list(cc)))
def get_mailtrigger(slug, create_from_slug_if_not_exists, desc_if_not_exists):
try:
mailtrigger = MailTrigger.objects.get(slug=slug)
except MailTrigger.DoesNotExist:
if create_from_slug_if_not_exists and desc_if_not_exists:
template = MailTrigger.objects.get(slug=create_from_slug_if_not_exists)
mailtrigger = MailTrigger.objects.create(slug=slug, desc=desc_if_not_exists)
mailtrigger.to.set(template.to.all())
mailtrigger.cc.set(template.cc.all())
if slug.startswith("review_completed") and slug.endswith("early"):
mailtrigger.cc.remove("ietf_last_call")
else:
raise
return mailtrigger
def gather_relevant_expansions(**kwargs):
def starts_with(prefix):
return MailTrigger.objects.filter(slug__startswith=prefix).values_list(
"slug", flat=True
)
relevant = set()
if "doc" in kwargs:
doc = kwargs["doc"]
relevant.add("doc_state_edited")
if not doc.type_id in ["bofreq", "statement", "rfc"]:
relevant.update(
["doc_telechat_details_changed", "ballot_deferred", "iesg_ballot_saved"]
)
if doc.type_id in ["draft", "statchg"]:
relevant.update(starts_with("last_call_"))
if doc.type_id == "rfc":
relevant.update(
[
"doc_added_comment",
"doc_external_resource_change_requested",
"doc_state_edited",
"ipr_posted_on_doc",
]
)
if doc.type_id == "draft":
relevant.update(starts_with("doc_"))
relevant.update(starts_with("resurrection_"))
relevant.update(
[
"ipr_posted_on_doc",
]
)
if doc.stream_id == "ietf":
relevant.update(["ballot_approved_ietf_stream", "pubreq_iesg"])
else:
relevant.update(["pubreq_rfced"])
last_submission = (
Submission.objects.filter(name=doc.name, state="posted")
.order_by("-rev")
.first()
)
if last_submission and "submission" not in kwargs:
kwargs["submission"] = last_submission
if doc.type_id == "conflrev":
relevant.update(["conflrev_requested", "ballot_approved_conflrev"])
if doc.type_id == "charter":
relevant.update(["charter_external_review", "ballot_approved_charter"])
if doc.type_id == "bofreq":
relevant.update(starts_with("bofreq"))
if "group" in kwargs:
relevant.update(starts_with("group_"))
relevant.update(starts_with("milestones_"))
group = kwargs["group"]
if group.features.acts_like_wg:
relevant.update(starts_with("session_"))
if group.features.has_chartering_process:
relevant.update(
[
"charter_external_review",
]
)
if "submission" in kwargs:
relevant.update(starts_with("sub_"))
rule_list = []
for mailtrigger in MailTrigger.objects.filter(slug__in=relevant):
addrs = gather_address_lists(mailtrigger.slug, **kwargs)
if addrs.to or addrs.cc:
rule_list.append((mailtrigger.slug, mailtrigger.desc, addrs.to, addrs.cc))
return sorted(rule_list)
def get_base_ipr_request_address():
return Recipient.objects.get(slug="ipr_requests").gather()[0]