Skip to content

Commit a5f27b0

Browse files
authored
feat: show expired WG/RG drafts at WG/RG Documents page (ietf-tools#4252)
* Show expired WG/RG drafts. * Update 0009_add_group_exp_rule_to_groups.py fix dependency on migration file name * Update forms.py Simplify condition statements * Update views.py Fix - remove erroneous check (never happen) * Added tests for expired WG drafts filtering rule
1 parent b1aecf9 commit a5f27b0

9 files changed

Lines changed: 97 additions & 8 deletions

File tree

ietf/community/forms.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ def restrict_state(state_type, slug=None):
3838
f.initial = f.queryset[0].pk
3939
f.widget = forms.HiddenInput()
4040

41-
if rule_type in ['group', 'group_rfc', 'area', 'area_rfc']:
42-
restrict_state("draft", "rfc" if rule_type.endswith("rfc") else "active")
43-
41+
if rule_type in ["group", "group_rfc", "area", "area_rfc", "group_exp"]:
42+
if rule_type == "group_exp":
43+
restrict_state("draft", "expired")
44+
else:
45+
restrict_state("draft", "rfc" if rule_type.endswith("rfc") else "active")
46+
4447
if rule_type.startswith("area"):
4548
self.fields["group"].label = "Area"
4649
self.fields["group"].queryset = self.fields["group"].queryset.filter(Q(type="area") | Q(acronym="irtf")).order_by("acronym")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.2.28 on 2022-06-30 05:59
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('community', '0007_remove_docs2_m2m'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='searchrule',
15+
name='rule_type',
16+
field=models.CharField(choices=[('group', 'All I-Ds associated with a particular group'), ('area', 'All I-Ds associated with all groups in a particular Area'), ('group_rfc', 'All RFCs associated with a particular group'), ('area_rfc', 'All RFCs associated with all groups in a particular Area'), ('group_exp', 'All expired I-Ds of a particular group'), ('state_iab', 'All I-Ds that are in a particular IAB state'), ('state_iana', 'All I-Ds that are in a particular IANA state'), ('state_iesg', 'All I-Ds that are in a particular IESG state'), ('state_irtf', 'All I-Ds that are in a particular IRTF state'), ('state_ise', 'All I-Ds that are in a particular ISE state'), ('state_rfceditor', 'All I-Ds that are in a particular RFC Editor state'), ('state_ietf', 'All I-Ds that are in a particular Working Group state'), ('author', 'All I-Ds with a particular author'), ('author_rfc', 'All RFCs with a particular author'), ('ad', 'All I-Ds with a particular responsible AD'), ('shepherd', 'All I-Ds with a particular document shepherd'), ('name_contains', 'All I-Ds with particular text/regular expression in the name')], max_length=30),
17+
),
18+
]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 2.2.28 on 2022-06-30 23:15
2+
3+
4+
from django.db import migrations
5+
6+
7+
def forward(apps, schema_editor):
8+
SearchRule = apps.get_model('community', 'SearchRule')
9+
Group = apps.get_model('group', 'Group')
10+
State = apps.get_model('doc', 'State')
11+
for group in Group.objects.filter(type_id__in=['wg','rg'], state_id='active'):
12+
Rule = SearchRule.objects.filter(group = group)
13+
if Rule.exists():
14+
SearchRule.objects.create(community_list=Rule[0].community_list, rule_type="group_exp", group=group, state=State.objects.get(slug="expired", type="draft"),)
15+
16+
17+
def reverse(apps, schema_editor):
18+
SearchRule = apps.get_model('community', 'SearchRule')
19+
SearchRule.objects.filter(rule_type='group_exp').delete()
20+
21+
22+
class Migration(migrations.Migration):
23+
dependencies = [
24+
('community', '0008_add_group_exp_rule'),
25+
]
26+
27+
operations = [
28+
migrations.RunPython(forward, reverse),
29+
]

ietf/community/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class SearchRule(models.Model):
4545
('area', 'All I-Ds associated with all groups in a particular Area'),
4646
('group_rfc', 'All RFCs associated with a particular group'),
4747
('area_rfc', 'All RFCs associated with all groups in a particular Area'),
48+
('group_exp', 'All expired I-Ds of a particular group'),
4849

4950
('state_iab', 'All I-Ds that are in a particular IAB state'),
5051
('state_iana', 'All I-Ds that are in a particular IANA state'),

ietf/community/tests.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def test_rule_matching(self):
5252

5353
rule_shepherd = SearchRule.objects.create(rule_type="shepherd", state=State.objects.get(type="draft", slug="active"), person=draft.shepherd.person, community_list=clist)
5454

55+
rule_group_exp = SearchRule.objects.create(rule_type="group_exp", group=draft.group, state=State.objects.get(type="draft", slug="expired"), community_list=clist)
56+
5557
rule_name_contains = SearchRule.objects.create(rule_type="name_contains", state=State.objects.get(type="draft", slug="active"), text="draft-.*" + "-".join(draft.name.split("-")[2:]), community_list=clist)
5658
reset_name_contains_index_for_rule(rule_name_contains)
5759

@@ -65,6 +67,7 @@ def test_rule_matching(self):
6567
self.assertTrue(rule_ad in matching_rules)
6668
self.assertTrue(rule_shepherd in matching_rules)
6769
self.assertTrue(rule_name_contains in matching_rules)
70+
self.assertTrue(rule_group_exp not in matching_rules)
6871

6972
# rule -> docs
7073
self.assertTrue(draft in list(docs_matching_community_list_rule(rule_group)))
@@ -75,6 +78,16 @@ def test_rule_matching(self):
7578
self.assertTrue(draft in list(docs_matching_community_list_rule(rule_ad)))
7679
self.assertTrue(draft in list(docs_matching_community_list_rule(rule_shepherd)))
7780
self.assertTrue(draft in list(docs_matching_community_list_rule(rule_name_contains)))
81+
self.assertTrue(draft not in list(docs_matching_community_list_rule(rule_group_exp)))
82+
83+
draft.set_state(State.objects.get(type='draft', slug='expired'))
84+
85+
# doc -> rules
86+
matching_rules = list(community_list_rules_matching_doc(draft))
87+
self.assertTrue(rule_group_exp in matching_rules)
88+
89+
# rule -> docs
90+
self.assertTrue(draft in list(docs_matching_community_list_rule(rule_group_exp)))
7891

7992
def test_view_list(self):
8093
PersonFactory(user__username='plain')

ietf/community/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def docs_matching_community_list_rule(rule):
7575
docs = Document.objects.all()
7676
if rule.rule_type in ['group', 'area', 'group_rfc', 'area_rfc']:
7777
return docs.filter(Q(group=rule.group_id) | Q(group__parent=rule.group_id), states=rule.state)
78+
elif rule.rule_type in ['group_exp']:
79+
return docs.filter(group=rule.group_id, states=rule.state)
7880
elif rule.rule_type.startswith("state_"):
7981
return docs.filter(states=rule.state)
8082
elif rule.rule_type in ["author", "author_rfc"]:
@@ -98,7 +100,7 @@ def community_list_rules_matching_doc(doc):
98100
if doc.group.parent_id:
99101
groups.append(doc.group.parent_id)
100102
rules |= SearchRule.objects.filter(
101-
rule_type__in=['group', 'area', 'group_rfc', 'area_rfc'],
103+
rule_type__in=['group', 'area', 'group_rfc', 'area_rfc', 'group_exp'],
102104
state__in=states,
103105
group__in=groups
104106
)

ietf/group/tests_info.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from ietf.community.models import CommunityList
2828
from ietf.community.utils import reset_name_contains_index_for_rule
29-
from ietf.doc.factories import WgDraftFactory, CharterFactory, BallotDocEventFactory
29+
from ietf.doc.factories import WgDraftFactory, IndividualDraftFactory, CharterFactory, BallotDocEventFactory
3030
from ietf.doc.models import Document, DocAlias, DocEvent, State
3131
from ietf.doc.utils_charter import charter_name_for_group
3232
from ietf.group.admin import GroupForm as AdminGroupForm
@@ -212,6 +212,17 @@ def test_group_documents(self):
212212
old_dah.time_added -= datetime.timedelta(days=173) # make an "old" action holder
213213
old_dah.save()
214214

215+
draft4 = WgDraftFactory(group=group)
216+
draft4.set_state(State.objects.get(type='draft', slug='expired')) # Expired WG draft
217+
draft5 = IndividualDraftFactory()
218+
draft5.set_state(State.objects.get(type='draft', slug='expired')) # Expired non-WG draft
219+
draft6 = WgDraftFactory(group=group)
220+
draft6.set_state(State.objects.get(type='draft', slug='expired'))
221+
draft6.set_state(State.objects.get(type='draft-iesg', slug='dead')) # Expired WG draft, marked as dead
222+
draft7 = WgDraftFactory(group=group)
223+
draft7.set_state(State.objects.get(type='draft', slug='expired'))
224+
draft7.set_state(State.objects.get(type='draft-stream-%s' % draft7.stream_id, slug='dead')) # Expired WG draft, marked as dead
225+
215226
clist = CommunityList.objects.get(group=group)
216227
related_docs_rule = clist.searchrule_set.get(rule_type='name_contains')
217228
reset_name_contains_index_for_rule(related_docs_rule)
@@ -229,6 +240,10 @@ def test_group_documents(self):
229240
for ah in draft3.action_holders.all():
230241
self.assertContains(r, escape(ah.name))
231242
self.assertContains(r, 'for 173 days', count=1) # the old_dah should be tagged
243+
self.assertContains(r, draft4.name)
244+
self.assertNotContains(r, draft5.name)
245+
self.assertNotContains(r, draft6.name)
246+
self.assertNotContains(r, draft7.name)
232247

233248
# Make sure that a logged in user is presented with an opportunity to add results to their community list
234249
self.client.login(username="secretary", password="secretary+password")

ietf/group/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ def setup_default_community_list_for_group(group):
193193
group=group,
194194
state=State.objects.get(slug="rfc", type="draft"),
195195
)
196+
SearchRule.objects.create(
197+
community_list=clist,
198+
rule_type="group_exp",
199+
group=group,
200+
state=State.objects.get(slug="expired", type="draft"),
201+
)
196202
related_docs_rule = SearchRule.objects.create(
197203
community_list=clist,
198204
rule_type="name_contains",

ietf/group/views.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,12 @@ def prepare_group_documents(request, group, clist):
452452
# non-WG drafts and call for WG adoption are considered related
453453
if (d.group != group
454454
or (d.stream_id and d.get_state_slug("draft-stream-%s" % d.stream_id) in ("c-adopt", "wg-cand"))):
455-
d.search_heading = "Related Internet-Draft"
456-
docs_related.append(d)
455+
if d.get_state_slug() != "expired":
456+
d.search_heading = "Related Internet-Draft"
457+
docs_related.append(d)
457458
else:
458-
docs.append(d)
459+
if not (d.get_state_slug('draft-iesg') == "dead" or (d.stream_id and d.get_state_slug("draft-stream-%s" % d.stream_id) == "dead")):
460+
docs.append(d)
459461

460462
meta_related = meta.copy()
461463

0 commit comments

Comments
 (0)