chore: continued refactor
This commit is contained in:
parent
75d199fe31
commit
db670dadc5
|
@ -28,7 +28,7 @@ import debug # pyflakes:ignore
|
|||
from ietf.doc.models import Document
|
||||
from ietf.group.models import Group
|
||||
from ietf.ietfauth.utils import has_role
|
||||
from ietf.doc.fields import SearchableDocAliasesField
|
||||
from ietf.doc.fields import SearchableDocumentsField
|
||||
from ietf.doc.models import DocAlias
|
||||
from ietf.ipr.mail import utc_from_string
|
||||
from ietf.meeting.models import Meeting
|
||||
|
@ -683,9 +683,9 @@ class SubmissionAutoUploadForm(SubmissionBaseUploadForm):
|
|||
if self.cleaned_data['replaces']:
|
||||
names_replaced = [s.strip() for s in self.cleaned_data['replaces'].split(',')]
|
||||
self.cleaned_data['replaces'] = ','.join(names_replaced)
|
||||
aliases_replaced = DocAlias.objects.filter(name__in=names_replaced)
|
||||
if len(names_replaced) != len(aliases_replaced):
|
||||
known_names = aliases_replaced.values_list('name', flat=True)
|
||||
documents_replaced = Document.objects.filter(name__in=names_replaced)
|
||||
if len(names_replaced) != len(documents_replaced):
|
||||
known_names = documents_replaced.values_list('name', flat=True)
|
||||
unknown_names = [n for n in names_replaced if n not in known_names]
|
||||
self.add_error(
|
||||
'replaces',
|
||||
|
@ -693,27 +693,22 @@ class SubmissionAutoUploadForm(SubmissionBaseUploadForm):
|
|||
'Unknown Internet-Draft name(s): ' + ', '.join(unknown_names)
|
||||
),
|
||||
)
|
||||
for alias in aliases_replaced:
|
||||
if alias.document.name == self.filename:
|
||||
for doc in documents_replaced:
|
||||
if doc.name == self.filename:
|
||||
self.add_error(
|
||||
'replaces',
|
||||
forms.ValidationError("An Internet-Draft cannot replace itself"),
|
||||
)
|
||||
elif alias.document.type_id != "draft":
|
||||
elif doc.type_id != "draft":
|
||||
self.add_error(
|
||||
'replaces',
|
||||
forms.ValidationError("An Internet-Draft can only replace another Internet-Draft"),
|
||||
)
|
||||
elif alias.document.get_state_slug() == "rfc":
|
||||
self.add_error(
|
||||
'replaces',
|
||||
forms.ValidationError("An Internet-Draft cannot replace an RFC"),
|
||||
)
|
||||
elif alias.document.get_state_slug('draft-iesg') in ('approved', 'ann', 'rfcqueue'):
|
||||
elif doc.get_state_slug('draft-iesg') in ('approved', 'ann', 'rfcqueue'):
|
||||
self.add_error(
|
||||
'replaces',
|
||||
forms.ValidationError(
|
||||
alias.name + " is approved by the IESG and cannot be replaced"
|
||||
doc.name + " is approved by the IESG and cannot be replaced"
|
||||
),
|
||||
)
|
||||
return cleaned_data
|
||||
|
@ -754,22 +749,20 @@ class SubmitterForm(NameEmailForm):
|
|||
return line
|
||||
|
||||
class ReplacesForm(forms.Form):
|
||||
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)")
|
||||
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)")
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.name = kwargs.pop("name")
|
||||
super(ReplacesForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def clean_replaces(self):
|
||||
for alias in self.cleaned_data['replaces']:
|
||||
if alias.document.name == self.name:
|
||||
for doc in self.cleaned_data['replaces']:
|
||||
if doc.name == self.name:
|
||||
raise forms.ValidationError("An Internet-Draft cannot replace itself.")
|
||||
if alias.document.type_id != "draft":
|
||||
if doc.type_id != "draft":
|
||||
raise forms.ValidationError("An Internet-Draft can only replace another Internet-Draft")
|
||||
if alias.document.get_state_slug() == "rfc":
|
||||
raise forms.ValidationError("An Internet-Draft cannot replace an RFC")
|
||||
if alias.document.get_state_slug('draft-iesg') in ('approved','ann','rfcqueue'):
|
||||
raise forms.ValidationError(alias.name+" is approved by the IESG and cannot be replaced")
|
||||
if doc.get_state_slug('draft-iesg') in ('approved','ann','rfcqueue'):
|
||||
raise forms.ValidationError(doc.name+" is approved by the IESG and cannot be replaced")
|
||||
return self.cleaned_data['replaces']
|
||||
|
||||
class EditSubmissionForm(forms.ModelForm):
|
||||
|
|
|
@ -1142,7 +1142,7 @@ class SubmitTests(BaseSubmitTestCase):
|
|||
self.verify_bibxml_ids_creation(draft)
|
||||
|
||||
def test_submit_update_individual(self):
|
||||
IndividualDraftFactory(name='draft-ietf-random-thing', states=[('draft','rfc')], other_aliases=['rfc9999',], pages=5)
|
||||
IndividualDraftFactory(name='draft-ietf-random-thing', states=[('draft','active'),('draft-iesg','approved')], pages=5)
|
||||
ad=Person.objects.get(user__username='ad')
|
||||
# Group of None here does not reflect real individual submissions
|
||||
draft = IndividualDraftFactory(group=None, ad = ad, authors=[ad,], notify='aliens@example.mars', pages=5)
|
||||
|
@ -1152,23 +1152,14 @@ class SubmitTests(BaseSubmitTestCase):
|
|||
status_url, author = self.do_submission(name,rev)
|
||||
mailbox_before = len(outbox)
|
||||
|
||||
replaced_alias = draft.docalias.first()
|
||||
r = self.supply_extra_metadata(name, status_url, "Submitter Name", "author@example.com", replaces=[str(replaced_alias.pk)])
|
||||
r = self.supply_extra_metadata(name, status_url, "Submitter Name", "author@example.com", replaces=[str(draft.pk)])
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertContains(r, 'cannot replace itself')
|
||||
self._assert_extresources_in_table(r, [])
|
||||
self._assert_extresources_form(r, [])
|
||||
|
||||
replaced_alias = DocAlias.objects.get(name='draft-ietf-random-thing')
|
||||
r = self.supply_extra_metadata(name, status_url, "Submitter Name", "author@example.com", replaces=[str(replaced_alias.pk)])
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertContains(r, 'cannot replace an RFC')
|
||||
self._assert_extresources_in_table(r, [])
|
||||
self._assert_extresources_form(r, [])
|
||||
|
||||
replaced_alias.document.set_state(State.objects.get(type='draft-iesg',slug='approved'))
|
||||
replaced_alias.document.set_state(State.objects.get(type='draft',slug='active'))
|
||||
r = self.supply_extra_metadata(name, status_url, "Submitter Name", "author@example.com", replaces=[str(replaced_alias.pk)])
|
||||
replaced = Document.objects.get(name='draft-ietf-random-thing')
|
||||
r = self.supply_extra_metadata(name, status_url, "Submitter Name", "author@example.com", replaces=[str(replaced.pk)])
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertContains(r, 'approved by the IESG and cannot')
|
||||
self._assert_extresources_in_table(r, [])
|
||||
|
@ -3105,7 +3096,7 @@ class SubmissionUploadFormTests(BaseSubmitTestCase):
|
|||
files=files_dict,
|
||||
)
|
||||
self.assertFalse(form.is_valid())
|
||||
self.assertIn('An Internet-Draft cannot replace an RFC', form.errors['replaces'])
|
||||
self.assertIn('An Internet-Draft can only replace another Internet-Draft', form.errors['replaces'])
|
||||
|
||||
# can't replace draft approved by iesg
|
||||
existing_drafts[0].set_state(State.objects.get(type='draft-iesg', slug='approved'))
|
||||
|
|
|
@ -504,7 +504,7 @@ def update_replaces_from_submission(request, submission, draft):
|
|||
if request.user.is_authenticated:
|
||||
is_chair_of = list(Group.objects.filter(role__person__user=request.user, role__name="chair"))
|
||||
|
||||
replaces = DocAlias.objects.filter(name__in=submission.replaces.split(",")).prefetch_related("docs", "docs__group")
|
||||
replaces = Document.objects.filter(name__in=submission.replaces.split(",")).prefetch_related("group")
|
||||
existing_replaces = list(draft.related_that_doc("replaces"))
|
||||
existing_suggested = set(draft.related_that_doc("possibly-replaces"))
|
||||
|
||||
|
@ -516,14 +516,12 @@ def update_replaces_from_submission(request, submission, draft):
|
|||
if r in existing_replaces:
|
||||
continue
|
||||
|
||||
rdoc = r.document
|
||||
|
||||
if rdoc == draft:
|
||||
if r == draft:
|
||||
continue
|
||||
|
||||
if (is_secretariat
|
||||
or (draft.group in is_chair_of and (rdoc.group.type_id == "individ" or rdoc.group in is_chair_of))
|
||||
or (submitter_email and rdoc.documentauthor_set.filter(email__address__iexact=submitter_email).exists())):
|
||||
or (draft.group in is_chair_of and (r.group.type_id == "individ" or r.group in is_chair_of))
|
||||
or (submitter_email and r.documentauthor_set.filter(email__address__iexact=submitter_email).exists())):
|
||||
approved.append(r)
|
||||
else:
|
||||
if r not in existing_suggested:
|
||||
|
|
|
@ -488,12 +488,15 @@ def update_docs_from_rfc_index(index_data, errata_data, skip_older_than_date=Non
|
|||
def parse_relation_list(l):
|
||||
res = []
|
||||
for x in l:
|
||||
if x[:3] in ("NIC", "IEN", "STD", "RTR"):
|
||||
# try translating this to RFCs that we can handle
|
||||
# sensibly; otherwise we'll have to ignore them
|
||||
l = DocAlias.objects.filter(name__startswith="rfc", docs__docalias__name=x.lower())
|
||||
else:
|
||||
l = DocAlias.objects.filter(name=x.lower())
|
||||
# This lookup wasn't finding anything but maybe some STD and we know
|
||||
# if the STD had more than one RFC the wrong thing happens
|
||||
#
|
||||
#if x[:3] in ("NIC", "IEN", "STD", "RTR"):
|
||||
# # try translating this to RFCs that we can handle
|
||||
# # sensibly; otherwise we'll have to ignore them
|
||||
# l = DocAlias.objects.filter(name__startswith="rfc", docs__docalias__name=x.lower())
|
||||
#else:
|
||||
l = Document.objects.filter(name=x.lower())
|
||||
|
||||
for a in l:
|
||||
if a not in res:
|
||||
|
|
|
@ -316,7 +316,7 @@ def make_test_data():
|
|||
doc_alias = DocAlias.objects.create(name=draft.name)
|
||||
doc_alias.docs.add(draft)
|
||||
|
||||
RelatedDocument.objects.create(source=draft, target=old_alias, relationship=DocRelationshipName.objects.get(slug='replaces'))
|
||||
RelatedDocument.objects.create(source=draft, target=old_draft, relationship=DocRelationshipName.objects.get(slug='replaces'))
|
||||
old_draft.set_state(State.objects.get(type='draft', slug='repl'))
|
||||
|
||||
DocumentAuthor.objects.create(
|
||||
|
|
Loading…
Reference in a new issue