chore: continued refactoring

This commit is contained in:
Robert Sparks 2023-06-16 16:59:20 -05:00
parent d6f58b3e67
commit 8ff14419c2
No known key found for this signature in database
GPG key ID: 6E2A6A5775F91318
11 changed files with 40 additions and 41 deletions

View file

@ -969,7 +969,7 @@ class Document(DocumentInfo):
iprs = ( iprs = (
IprDocRel.objects.filter( IprDocRel.objects.filter(
document__in=list(self.docalias.all()) document__in=list(self.docalias.all())
+ [x.docalias.first() for x in self.all_related_that_doc(("obs", "replaces"))] + [x.docalias.first() for x in self.all_related_that_doc(("obs", "replaces"))] # this really is docalias until IprDocRel changes
) )
.filter(disclosure__state__in=("posted", "removed")) .filter(disclosure__state__in=("posted", "removed"))
.values_list("disclosure", flat=True) .values_list("disclosure", flat=True)

View file

@ -2034,7 +2034,7 @@ class ChangeReplacesTests(TestCase):
# Post that says replaceboth replaces both base a and base b # Post that says replaceboth replaces both base a and base b
url = urlreverse('ietf.doc.views_draft.replaces', kwargs=dict(name=self.replaceboth.name)) url = urlreverse('ietf.doc.views_draft.replaces', kwargs=dict(name=self.replaceboth.name))
self.assertEqual(self.baseb.get_state().slug,'expired') self.assertEqual(self.baseb.get_state().slug,'expired')
r = self.client.post(url, dict(replaces=[self.basea.docalias.first().pk, self.baseb.docalias.first().pk])) r = self.client.post(url, dict(replaces=[self.basea.pk, self.baseb.pk]))
self.assertEqual(r.status_code, 302) self.assertEqual(r.status_code, 302)
self.assertEqual(Document.objects.get(name='draft-test-base-a').get_state().slug,'repl') self.assertEqual(Document.objects.get(name='draft-test-base-a').get_state().slug,'repl')
self.assertEqual(Document.objects.get(name='draft-test-base-b').get_state().slug,'repl') self.assertEqual(Document.objects.get(name='draft-test-base-b').get_state().slug,'repl')
@ -2093,7 +2093,7 @@ class MoreReplacesTests(TestCase):
new_doc = IndividualDraftFactory(stream_id=stream) new_doc = IndividualDraftFactory(stream_id=stream)
url = urlreverse('ietf.doc.views_draft.replaces', kwargs=dict(name=new_doc.name)) url = urlreverse('ietf.doc.views_draft.replaces', kwargs=dict(name=new_doc.name))
r = self.client.post(url, dict(replaces=old_doc.docalias.first().pk)) r = self.client.post(url, dict(replaces=old_doc.pk))
self.assertEqual(r.status_code,302) self.assertEqual(r.status_code,302)
old_doc = Document.objects.get(name=old_doc.name) old_doc = Document.objects.get(name=old_doc.name)
self.assertEqual(old_doc.get_state_slug('draft'),'repl') self.assertEqual(old_doc.get_state_slug('draft'),'repl')

View file

@ -153,8 +153,8 @@ class ReviewTests(TestCase):
# check we can fish it out # check we can fish it out
old_doc = WgDraftFactory(name="draft-foo-mars-test") old_doc = WgDraftFactory(name="draft-foo-mars-test")
older_doc = WgDraftFactory(name="draft-older") older_doc = WgDraftFactory(name="draft-older")
RelatedDocument.objects.create(source=old_doc, target=older_doc.docalias.first(), relationship_id='replaces') RelatedDocument.objects.create(source=old_doc, target=older_doc, relationship_id='replaces')
RelatedDocument.objects.create(source=doc, target=old_doc.docalias.first(), relationship_id='replaces') RelatedDocument.objects.create(source=doc, target=old_doc, relationship_id='replaces')
review_req.doc = older_doc review_req.doc = older_doc
review_req.save() review_req.save()

View file

@ -15,7 +15,7 @@ from django.conf import settings
from django.urls import reverse as urlreverse from django.urls import reverse as urlreverse
from ietf.doc.factories import DocumentFactory, IndividualRfcFactory, WgRfcFactory from ietf.doc.factories import DocumentFactory, IndividualRfcFactory, WgRfcFactory
from ietf.doc.models import ( Document, DocAlias, State, DocEvent, from ietf.doc.models import ( Document, State, DocEvent,
BallotPositionDocEvent, NewRevisionDocEvent, TelechatDocEvent, WriteupDocEvent ) BallotPositionDocEvent, NewRevisionDocEvent, TelechatDocEvent, WriteupDocEvent )
from ietf.doc.utils import create_ballot_if_not_open from ietf.doc.utils import create_ballot_if_not_open
from ietf.doc.views_status_change import default_approval_text from ietf.doc.views_status_change import default_approval_text
@ -74,7 +74,7 @@ class StatusChangeTests(TestCase):
self.assertEqual(status_change.rev,'00') self.assertEqual(status_change.rev,'00')
self.assertEqual(status_change.ad.name,'Areað Irector') self.assertEqual(status_change.ad.name,'Areað Irector')
self.assertEqual(status_change.notify,'ipu@ietf.org') self.assertEqual(status_change.notify,'ipu@ietf.org')
self.assertTrue(status_change.relateddocument_set.filter(relationship__slug='tois',target__name='draft-ietf-random-thing')) self.assertTrue(status_change.relateddocument_set.filter(relationship__slug='tois',target__name='rfc9999'))
# Verify that it's possible to start a status change without a responsible ad. # Verify that it's possible to start a status change without a responsible ad.
r = self.client.post(url,dict( r = self.client.post(url,dict(
@ -159,8 +159,8 @@ class StatusChangeTests(TestCase):
self.assertTrue(doc.latest_event(DocEvent,type="added_comment").desc.startswith('Notification list changed')) self.assertTrue(doc.latest_event(DocEvent,type="added_comment").desc.startswith('Notification list changed'))
# Some additional setup so there's something to put in a generated notify list # Some additional setup so there's something to put in a generated notify list
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9999'),relationship_id='tois') doc.relateddocument_set.create(target=Document.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9998'),relationship_id='tohist') doc.relateddocument_set.create(target=Document.objects.get(name='rfc9998'),relationship_id='tohist')
# Ask the form to regenerate the list # Ask the form to regenerate the list
r = self.client.post(url,dict(regenerate_addresses="1")) r = self.client.post(url,dict(regenerate_addresses="1"))
@ -263,8 +263,8 @@ class StatusChangeTests(TestCase):
login_testing_unauthorized(self, "ad", url) login_testing_unauthorized(self, "ad", url)
# additional setup # additional setup
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9999'),relationship_id='tois') doc.relateddocument_set.create(target=Document.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9998'),relationship_id='tohist') doc.relateddocument_set.create(target=Document.objects.get(name='rfc9998'),relationship_id='tohist')
doc.ad = Person.objects.get(name='Ad No2') doc.ad = Person.objects.get(name='Ad No2')
doc.save_with_history([DocEvent.objects.create(doc=doc, rev=doc.rev, type="changed_document", by=Person.objects.get(user__username="secretary"), desc="Test")]) doc.save_with_history([DocEvent.objects.create(doc=doc, rev=doc.rev, type="changed_document", by=Person.objects.get(user__username="secretary"), desc="Test")])
@ -307,8 +307,8 @@ class StatusChangeTests(TestCase):
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
# Some additional setup # Some additional setup
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9999'),relationship_id='tois') doc.relateddocument_set.create(target=Document.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9998'),relationship_id='tohist') doc.relateddocument_set.create(target=Document.objects.get(name='rfc9998'),relationship_id='tohist')
create_ballot_if_not_open(None, doc, Person.objects.get(user__username="secretary"), "statchg") create_ballot_if_not_open(None, doc, Person.objects.get(user__username="secretary"), "statchg")
doc.set_state(State.objects.get(slug='appr-pend',type='statchg')) doc.set_state(State.objects.get(slug='appr-pend',type='statchg'))
@ -348,10 +348,10 @@ class StatusChangeTests(TestCase):
url = urlreverse('ietf.doc.views_status_change.change_state',kwargs=dict(name=doc.name)) url = urlreverse('ietf.doc.views_status_change.change_state',kwargs=dict(name=doc.name))
# Add some status change related documents # Add some status change related documents
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9999'),relationship_id='tois') doc.relateddocument_set.create(target=Document.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9998'),relationship_id='tohist') doc.relateddocument_set.create(target=Document.objects.get(name='rfc9998'),relationship_id='tohist')
# And a non-status change related document # And a non-status change related document
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc14'),relationship_id='updates') doc.relateddocument_set.create(target=Document.objects.get(name='rfc14'),relationship_id='updates')
login_testing_unauthorized(self, role, url) login_testing_unauthorized(self, role, url)
empty_outbox() empty_outbox()
@ -373,9 +373,9 @@ class StatusChangeTests(TestCase):
self.assertTrue(notification['Subject'].startswith('Approved:')) self.assertTrue(notification['Subject'].startswith('Approved:'))
notification_text = get_payload_text(notification) notification_text = get_payload_text(notification)
self.assertIn('The AD has approved changing the status', notification_text) self.assertIn('The AD has approved changing the status', notification_text)
self.assertIn(DocAlias.objects.get(name='rfc9999').document.canonical_name(), notification_text) self.assertIn(Document.objects.get(name='rfc9999').canonical_name(), notification_text)
self.assertIn(DocAlias.objects.get(name='rfc9998').document.canonical_name(), notification_text) self.assertIn(Document.objects.get(name='rfc9998').canonical_name(), notification_text)
self.assertNotIn(DocAlias.objects.get(name='rfc14').document.canonical_name(), notification_text) self.assertNotIn(Document.objects.get(name='rfc14').canonical_name(), notification_text)
self.assertNotIn('No value found for', notification_text) # make sure all interpolation values were set self.assertNotIn('No value found for', notification_text) # make sure all interpolation values were set
else: else:
self.assertEqual(len(outbox), 0) self.assertEqual(len(outbox), 0)
@ -395,8 +395,8 @@ class StatusChangeTests(TestCase):
login_testing_unauthorized(self, "secretary", url) login_testing_unauthorized(self, "secretary", url)
# Some additional setup # Some additional setup
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9999'),relationship_id='tois') doc.relateddocument_set.create(target=Document.objects.get(name='rfc9999'),relationship_id='tois')
doc.relateddocument_set.create(target=DocAlias.objects.get(name='rfc9998'),relationship_id='tohist') doc.relateddocument_set.create(target=Document.objects.get(name='rfc9998'),relationship_id='tohist')
# get # get
r = self.client.get(url) r = self.client.get(url)
@ -449,9 +449,9 @@ class StatusChangeTests(TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
IndividualRfcFactory(alias2__name='rfc14',name='draft-was-never-issued',std_level_id='unkn') IndividualRfcFactory(name='rfc14',std_level_id='unkn')
WgRfcFactory(alias2__name='rfc9999',name='draft-ietf-random-thing',std_level_id='ps') WgRfcFactory(name='rfc9999',std_level_id='ps')
WgRfcFactory(alias2__name='rfc9998',name='draft-ietf-random-other-thing',std_level_id='inf') WgRfcFactory(name='rfc9998',std_level_id='inf')
DocumentFactory(type_id='statchg',name='status-change-imaginary-mid-review',notify='notify@example.org') DocumentFactory(type_id='statchg',name='status-change-imaginary-mid-review',notify='notify@example.org')
class StatusChangeSubmitTests(TestCase): class StatusChangeSubmitTests(TestCase):

View file

@ -328,11 +328,11 @@ class RebuildReferenceRelationsTests(TestCase):
self.normative, self.informative, self.unknown = WgRfcFactory.create_batch(3) self.normative, self.informative, self.unknown = WgRfcFactory.create_batch(3)
for relationship in ['refnorm', 'refinfo', 'refunk', 'refold']: for relationship in ['refnorm', 'refinfo', 'refunk', 'refold']:
self.doc.relateddocument_set.create( self.doc.relateddocument_set.create(
target=WgRfcFactory().docalias.first(), target=WgRfcFactory(),
relationship_id=relationship, relationship_id=relationship,
) )
self.updated = WgRfcFactory() # related document that should be left alone self.updated = WgRfcFactory() # related document that should be left alone
self.doc.relateddocument_set.create(target=self.updated.docalias.first(), relationship_id='updates') self.doc.relateddocument_set.create(target=self.updated, relationship_id='updates')
self.assertCountEqual(self.doc.relateddocument_set.values_list('relationship__slug', flat=True), self.assertCountEqual(self.doc.relateddocument_set.values_list('relationship__slug', flat=True),
['refnorm', 'refinfo', 'refold', 'refunk', 'updates'], ['refnorm', 'refinfo', 'refold', 'refunk', 'updates'],
'Test conditions set up incorrectly: wrong prior document relationships') 'Test conditions set up incorrectly: wrong prior document relationships')
@ -389,7 +389,7 @@ class RebuildReferenceRelationsTests(TestCase):
(self.normative.canonical_name(), 'refnorm'), (self.normative.canonical_name(), 'refnorm'),
(self.informative.canonical_name(), 'refinfo'), (self.informative.canonical_name(), 'refinfo'),
(self.unknown.canonical_name(), 'refunk'), (self.unknown.canonical_name(), 'refunk'),
(self.updated.docalias.first().name, 'updates'), (self.updated.name, 'updates'),
] ]
) )
@ -420,7 +420,7 @@ class RebuildReferenceRelationsTests(TestCase):
(self.normative.canonical_name(), 'refnorm'), (self.normative.canonical_name(), 'refnorm'),
(self.informative.canonical_name(), 'refinfo'), (self.informative.canonical_name(), 'refinfo'),
(self.unknown.canonical_name(), 'refunk'), (self.unknown.canonical_name(), 'refunk'),
(self.updated.docalias.first().name, 'updates'), (self.updated.name, 'updates'),
] ]
) )
@ -452,6 +452,6 @@ class RebuildReferenceRelationsTests(TestCase):
(self.normative.canonical_name(), 'refnorm'), (self.normative.canonical_name(), 'refnorm'),
(self.informative.canonical_name(), 'refinfo'), (self.informative.canonical_name(), 'refinfo'),
(self.unknown.canonical_name(), 'refunk'), (self.unknown.canonical_name(), 'refunk'),
(self.updated.docalias.first().name, 'updates'), (self.updated.name, 'updates'),
] ]
) )

View file

@ -31,7 +31,7 @@ from ietf.community.models import CommunityList
from ietf.community.utils import docs_tracked_by_community_list from ietf.community.utils import docs_tracked_by_community_list
from ietf.doc.models import Document, DocHistory, State, DocumentAuthor, DocHistoryAuthor from ietf.doc.models import Document, DocHistory, State, DocumentAuthor, DocHistoryAuthor
from ietf.doc.models import DocAlias, RelatedDocument, RelatedDocHistory, BallotType, DocReminder from ietf.doc.models import RelatedDocument, RelatedDocHistory, BallotType, DocReminder
from ietf.doc.models import DocEvent, ConsensusDocEvent, BallotDocEvent, IRSGBallotDocEvent, NewRevisionDocEvent, StateDocEvent from ietf.doc.models import DocEvent, ConsensusDocEvent, BallotDocEvent, IRSGBallotDocEvent, NewRevisionDocEvent, StateDocEvent
from ietf.doc.models import TelechatDocEvent, DocumentActionHolder, EditedAuthorsDocEvent from ietf.doc.models import TelechatDocEvent, DocumentActionHolder, EditedAuthorsDocEvent
from ietf.name.models import DocReminderTypeName, DocRelationshipName from ietf.name.models import DocReminderTypeName, DocRelationshipName
@ -771,9 +771,9 @@ def rebuild_reference_relations(doc, filenames):
errors = [] errors = []
unfound = set() unfound = set()
for ( ref, refType ) in refs.items(): for ( ref, refType ) in refs.items():
refdoc = DocAlias.objects.filter(name=ref) refdoc = Document.objects.filter(name=ref)
if not refdoc and re.match(r"^draft-.*-\d{2}$", ref): if not refdoc and re.match(r"^draft-.*-\d{2}$", ref):
refdoc = DocAlias.objects.filter(name=ref[:-3]) refdoc = Document.objects.filter(name=ref[:-3])
count = refdoc.count() count = refdoc.count()
# As of Dec 2021, DocAlias has a unique constraint on the name field, so count > 1 should not occur # As of Dec 2021, DocAlias has a unique constraint on the name field, so count > 1 should not occur
if count == 0: if count == 0:

View file

@ -23,7 +23,7 @@ from django.utils import timezone
import debug # pyflakes:ignore import debug # pyflakes:ignore
from ietf.doc.models import ( Document, DocAlias, RelatedDocument, State, from ietf.doc.models import ( Document, RelatedDocument, State,
StateType, DocEvent, ConsensusDocEvent, TelechatDocEvent, WriteupDocEvent, StateDocEvent, StateType, DocEvent, ConsensusDocEvent, TelechatDocEvent, WriteupDocEvent, StateDocEvent,
IanaExpertDocEvent, IESG_SUBSTATE_TAGS) IanaExpertDocEvent, IESG_SUBSTATE_TAGS)
from ietf.doc.mails import ( email_pulled_from_rfc_queue, email_resurrect_requested, from ietf.doc.mails import ( email_pulled_from_rfc_queue, email_resurrect_requested,

View file

@ -439,7 +439,7 @@ def clean_helper(form, formtype):
if not re.match(r'(?i)rfc\d{1,4}',key): if not re.match(r'(?i)rfc\d{1,4}',key):
errors.append(key+" is not a valid RFC - please use the form RFCn\n") errors.append(key+" is not a valid RFC - please use the form RFCn\n")
elif not DocAlias.objects.filter(name=key): elif not Document.objects.filter(name=key):
errors.append(key+" does not exist\n") errors.append(key+" does not exist\n")
if new_relations[key] not in STATUSCHANGE_RELATIONS: if new_relations[key] not in STATUSCHANGE_RELATIONS:
@ -564,10 +564,9 @@ def start_rfc_status_change(request, name=None):
DocAlias.objects.create( name= 'status-change-'+form.cleaned_data['document_name']).docs.add(status_change) DocAlias.objects.create( name= 'status-change-'+form.cleaned_data['document_name']).docs.add(status_change)
for key in form.cleaned_data['relations']: for key in form.cleaned_data['relations']:
status_change.relateddocument_set.create(target=DocAlias.objects.get(name=key), status_change.relateddocument_set.create(target=Document.objects.get(name=key),
relationship_id=form.cleaned_data['relations'][key]) relationship_id=form.cleaned_data['relations'][key])
tc_date = form.cleaned_data['telechat_date'] tc_date = form.cleaned_data['telechat_date']
if tc_date: if tc_date:
update_telechat(request, status_change, login, tc_date) update_telechat(request, status_change, login, tc_date)
@ -609,7 +608,7 @@ def edit_relations(request, name):
new_relations=form.cleaned_data['relations'] new_relations=form.cleaned_data['relations']
status_change.relateddocument_set.filter(relationship__slug__in=STATUSCHANGE_RELATIONS).delete() status_change.relateddocument_set.filter(relationship__slug__in=STATUSCHANGE_RELATIONS).delete()
for key in new_relations: for key in new_relations:
status_change.relateddocument_set.create(target=DocAlias.objects.get(name=key), status_change.relateddocument_set.create(target=Document.objects.get(name=key),
relationship_id=new_relations[key]) relationship_id=new_relations[key])
c = DocEvent(type="added_comment", doc=status_change, rev=status_change.rev, by=login) c = DocEvent(type="added_comment", doc=status_change, rev=status_change.rev, by=login)
c.desc = "Affected RFC list changed.\nOLD:" c.desc = "Affected RFC list changed.\nOLD:"

View file

@ -69,7 +69,7 @@ class GroupStatsTests(TestCase):
a = WgDraftFactory() a = WgDraftFactory()
b = WgDraftFactory() b = WgDraftFactory()
RelatedDocument.objects.create( RelatedDocument.objects.create(
source=a, target=b.docalias.first(), relationship_id="refnorm" source=a, target=b, relationship_id="refnorm"
) )
def test_group_stats(self): def test_group_stats(self):
@ -95,7 +95,7 @@ class GroupDocDependencyTests(TestCase):
a = WgDraftFactory() a = WgDraftFactory()
b = WgDraftFactory() b = WgDraftFactory()
RelatedDocument.objects.create( RelatedDocument.objects.create(
source=a, target=b.docalias.first(), relationship_id="refnorm" source=a, target=b, relationship_id="refnorm"
) )
def test_group_document_dependencies(self): def test_group_document_dependencies(self):

View file

@ -82,7 +82,7 @@ class StatisticsTests(TestCase):
DocAlias.objects.create(name=referencing_draft.name).docs.add(referencing_draft) DocAlias.objects.create(name=referencing_draft.name).docs.add(referencing_draft)
RelatedDocument.objects.create( RelatedDocument.objects.create(
source=referencing_draft, source=referencing_draft,
target=draft.docalias.first(), target=draft,
relationship=DocRelationshipName.objects.get(slug="refinfo") relationship=DocRelationshipName.objects.get(slug="refinfo")
) )
NewRevisionDocEvent.objects.create( NewRevisionDocEvent.objects.create(

View file

@ -371,7 +371,7 @@ class SubmitTests(BaseSubmitTestCase):
mailbox_before = len(outbox) mailbox_before = len(outbox)
replaced_alias = draft.docalias.first() replaced_alias = draft.docalias.first()
r = self.supply_extra_metadata(name, status_url, author.ascii, author.email().address.lower(), r = self.supply_extra_metadata(name, status_url, author.ascii, author.email().address.lower(),
replaces=[str(replaced_alias.pk), str(sug_replaced_alias.pk)]) replaces=[str(draft.pk), str(sug_replaced_draft.pk)])
self.assertEqual(r.status_code, 302) self.assertEqual(r.status_code, 302)
status_url = r["Location"] status_url = r["Location"]