Skip to content

Commit db670da

Browse files
committed
chore: continued refactor
1 parent 75d199f commit db670da

5 files changed

Lines changed: 34 additions & 49 deletions

File tree

ietf/submit/forms.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from ietf.doc.models import Document
2929
from ietf.group.models import Group
3030
from ietf.ietfauth.utils import has_role
31-
from ietf.doc.fields import SearchableDocAliasesField
31+
from ietf.doc.fields import SearchableDocumentsField
3232
from ietf.doc.models import DocAlias
3333
from ietf.ipr.mail import utc_from_string
3434
from ietf.meeting.models import Meeting
@@ -683,37 +683,32 @@ def clean(self):
683683
if self.cleaned_data['replaces']:
684684
names_replaced = [s.strip() for s in self.cleaned_data['replaces'].split(',')]
685685
self.cleaned_data['replaces'] = ','.join(names_replaced)
686-
aliases_replaced = DocAlias.objects.filter(name__in=names_replaced)
687-
if len(names_replaced) != len(aliases_replaced):
688-
known_names = aliases_replaced.values_list('name', flat=True)
686+
documents_replaced = Document.objects.filter(name__in=names_replaced)
687+
if len(names_replaced) != len(documents_replaced):
688+
known_names = documents_replaced.values_list('name', flat=True)
689689
unknown_names = [n for n in names_replaced if n not in known_names]
690690
self.add_error(
691691
'replaces',
692692
forms.ValidationError(
693693
'Unknown Internet-Draft name(s): ' + ', '.join(unknown_names)
694694
),
695695
)
696-
for alias in aliases_replaced:
697-
if alias.document.name == self.filename:
696+
for doc in documents_replaced:
697+
if doc.name == self.filename:
698698
self.add_error(
699699
'replaces',
700700
forms.ValidationError("An Internet-Draft cannot replace itself"),
701701
)
702-
elif alias.document.type_id != "draft":
702+
elif doc.type_id != "draft":
703703
self.add_error(
704704
'replaces',
705705
forms.ValidationError("An Internet-Draft can only replace another Internet-Draft"),
706706
)
707-
elif alias.document.get_state_slug() == "rfc":
708-
self.add_error(
709-
'replaces',
710-
forms.ValidationError("An Internet-Draft cannot replace an RFC"),
711-
)
712-
elif alias.document.get_state_slug('draft-iesg') in ('approved', 'ann', 'rfcqueue'):
707+
elif doc.get_state_slug('draft-iesg') in ('approved', 'ann', 'rfcqueue'):
713708
self.add_error(
714709
'replaces',
715710
forms.ValidationError(
716-
alias.name + " is approved by the IESG and cannot be replaced"
711+
doc.name + " is approved by the IESG and cannot be replaced"
717712
),
718713
)
719714
return cleaned_data
@@ -754,22 +749,20 @@ def cleaned_line(self):
754749
return line
755750

756751
class ReplacesForm(forms.Form):
757-
replaces = SearchableDocAliasesField(required=False, help_text="Any Internet-Drafts that this document replaces (approval required for replacing an Internet-Draft you are not the author of)")
752+
replaces = SearchableDocumentsField(required=False, help_text="Any Internet-Drafts that this document replaces (approval required for replacing an Internet-Draft you are not the author of)")
758753

759754
def __init__(self, *args, **kwargs):
760755
self.name = kwargs.pop("name")
761756
super(ReplacesForm, self).__init__(*args, **kwargs)
762757

763758
def clean_replaces(self):
764-
for alias in self.cleaned_data['replaces']:
765-
if alias.document.name == self.name:
759+
for doc in self.cleaned_data['replaces']:
760+
if doc.name == self.name:
766761
raise forms.ValidationError("An Internet-Draft cannot replace itself.")
767-
if alias.document.type_id != "draft":
762+
if doc.type_id != "draft":
768763
raise forms.ValidationError("An Internet-Draft can only replace another Internet-Draft")
769-
if alias.document.get_state_slug() == "rfc":
770-
raise forms.ValidationError("An Internet-Draft cannot replace an RFC")
771-
if alias.document.get_state_slug('draft-iesg') in ('approved','ann','rfcqueue'):
772-
raise forms.ValidationError(alias.name+" is approved by the IESG and cannot be replaced")
764+
if doc.get_state_slug('draft-iesg') in ('approved','ann','rfcqueue'):
765+
raise forms.ValidationError(doc.name+" is approved by the IESG and cannot be replaced")
773766
return self.cleaned_data['replaces']
774767

775768
class EditSubmissionForm(forms.ModelForm):

ietf/submit/tests.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ def test_submit_new_logged_in_with_extresources(self):
11421142
self.verify_bibxml_ids_creation(draft)
11431143

11441144
def test_submit_update_individual(self):
1145-
IndividualDraftFactory(name='draft-ietf-random-thing', states=[('draft','rfc')], other_aliases=['rfc9999',], pages=5)
1145+
IndividualDraftFactory(name='draft-ietf-random-thing', states=[('draft','active'),('draft-iesg','approved')], pages=5)
11461146
ad=Person.objects.get(user__username='ad')
11471147
# Group of None here does not reflect real individual submissions
11481148
draft = IndividualDraftFactory(group=None, ad = ad, authors=[ad,], notify='aliens@example.mars', pages=5)
@@ -1152,23 +1152,14 @@ def test_submit_update_individual(self):
11521152
status_url, author = self.do_submission(name,rev)
11531153
mailbox_before = len(outbox)
11541154

1155-
replaced_alias = draft.docalias.first()
1156-
r = self.supply_extra_metadata(name, status_url, "Submitter Name", "author@example.com", replaces=[str(replaced_alias.pk)])
1155+
r = self.supply_extra_metadata(name, status_url, "Submitter Name", "author@example.com", replaces=[str(draft.pk)])
11571156
self.assertEqual(r.status_code, 200)
11581157
self.assertContains(r, 'cannot replace itself')
11591158
self._assert_extresources_in_table(r, [])
11601159
self._assert_extresources_form(r, [])
11611160

1162-
replaced_alias = DocAlias.objects.get(name='draft-ietf-random-thing')
1163-
r = self.supply_extra_metadata(name, status_url, "Submitter Name", "author@example.com", replaces=[str(replaced_alias.pk)])
1164-
self.assertEqual(r.status_code, 200)
1165-
self.assertContains(r, 'cannot replace an RFC')
1166-
self._assert_extresources_in_table(r, [])
1167-
self._assert_extresources_form(r, [])
1168-
1169-
replaced_alias.document.set_state(State.objects.get(type='draft-iesg',slug='approved'))
1170-
replaced_alias.document.set_state(State.objects.get(type='draft',slug='active'))
1171-
r = self.supply_extra_metadata(name, status_url, "Submitter Name", "author@example.com", replaces=[str(replaced_alias.pk)])
1161+
replaced = Document.objects.get(name='draft-ietf-random-thing')
1162+
r = self.supply_extra_metadata(name, status_url, "Submitter Name", "author@example.com", replaces=[str(replaced.pk)])
11721163
self.assertEqual(r.status_code, 200)
11731164
self.assertContains(r, 'approved by the IESG and cannot')
11741165
self._assert_extresources_in_table(r, [])
@@ -3105,7 +3096,7 @@ def test_replaces_field(self):
31053096
files=files_dict,
31063097
)
31073098
self.assertFalse(form.is_valid())
3108-
self.assertIn('An Internet-Draft cannot replace an RFC', form.errors['replaces'])
3099+
self.assertIn('An Internet-Draft can only replace another Internet-Draft', form.errors['replaces'])
31093100

31103101
# can't replace draft approved by iesg
31113102
existing_drafts[0].set_state(State.objects.get(type='draft-iesg', slug='approved'))

ietf/submit/utils.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def update_replaces_from_submission(request, submission, draft):
504504
if request.user.is_authenticated:
505505
is_chair_of = list(Group.objects.filter(role__person__user=request.user, role__name="chair"))
506506

507-
replaces = DocAlias.objects.filter(name__in=submission.replaces.split(",")).prefetch_related("docs", "docs__group")
507+
replaces = Document.objects.filter(name__in=submission.replaces.split(",")).prefetch_related("group")
508508
existing_replaces = list(draft.related_that_doc("replaces"))
509509
existing_suggested = set(draft.related_that_doc("possibly-replaces"))
510510

@@ -516,14 +516,12 @@ def update_replaces_from_submission(request, submission, draft):
516516
if r in existing_replaces:
517517
continue
518518

519-
rdoc = r.document
520-
521-
if rdoc == draft:
519+
if r == draft:
522520
continue
523521

524522
if (is_secretariat
525-
or (draft.group in is_chair_of and (rdoc.group.type_id == "individ" or rdoc.group in is_chair_of))
526-
or (submitter_email and rdoc.documentauthor_set.filter(email__address__iexact=submitter_email).exists())):
523+
or (draft.group in is_chair_of and (r.group.type_id == "individ" or r.group in is_chair_of))
524+
or (submitter_email and r.documentauthor_set.filter(email__address__iexact=submitter_email).exists())):
527525
approved.append(r)
528526
else:
529527
if r not in existing_suggested:

ietf/sync/rfceditor.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,15 @@ def update_docs_from_rfc_index(index_data, errata_data, skip_older_than_date=Non
488488
def parse_relation_list(l):
489489
res = []
490490
for x in l:
491-
if x[:3] in ("NIC", "IEN", "STD", "RTR"):
492-
# try translating this to RFCs that we can handle
493-
# sensibly; otherwise we'll have to ignore them
494-
l = DocAlias.objects.filter(name__startswith="rfc", docs__docalias__name=x.lower())
495-
else:
496-
l = DocAlias.objects.filter(name=x.lower())
491+
# This lookup wasn't finding anything but maybe some STD and we know
492+
# if the STD had more than one RFC the wrong thing happens
493+
#
494+
#if x[:3] in ("NIC", "IEN", "STD", "RTR"):
495+
# # try translating this to RFCs that we can handle
496+
# # sensibly; otherwise we'll have to ignore them
497+
# l = DocAlias.objects.filter(name__startswith="rfc", docs__docalias__name=x.lower())
498+
#else:
499+
l = Document.objects.filter(name=x.lower())
497500

498501
for a in l:
499502
if a not in res:

ietf/utils/test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def make_test_data():
316316
doc_alias = DocAlias.objects.create(name=draft.name)
317317
doc_alias.docs.add(draft)
318318

319-
RelatedDocument.objects.create(source=draft, target=old_alias, relationship=DocRelationshipName.objects.get(slug='replaces'))
319+
RelatedDocument.objects.create(source=draft, target=old_draft, relationship=DocRelationshipName.objects.get(slug='replaces'))
320320
old_draft.set_state(State.objects.get(type='draft', slug='repl'))
321321

322322
DocumentAuthor.objects.create(

0 commit comments

Comments
 (0)