Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4a2f807
fix: Enforce naming of charter docs in submit()
jennifer-richards Jun 13, 2023
2748f71
style: Reformat submit() with Black
jennifer-richards Jun 13, 2023
ff91389
refactor: Remove redundant check of charter name
jennifer-richards Jun 13, 2023
c0736ef
style: Reformat charter_with_milestones_txt with Black
jennifer-richards Jun 13, 2023
c971c6b
refactor: Drop canonical_name, use Path in charter_with_milestones_txt
jennifer-richards Jun 13, 2023
b2ea379
style: Reformat review_announcement_text() with Black
jennifer-richards Jun 13, 2023
7b9909e
style: Reformat action_announcement_text() with Black
jennifer-richards Jun 13, 2023
a35e5ed
refactor: Change uses of charter.canonical_name() to charter.name
jennifer-richards Jun 13, 2023
1812c68
refactor: Skip docialias when retrieving charter
jennifer-richards Jun 13, 2023
07388d2
refactor: Change canonical_name() to name in utils_charter.py
jennifer-richards Jun 13, 2023
90b0fd8
refactor: Use Path in read_charter_text()
jennifer-richards Jun 13, 2023
dc42f83
refactor: Drop canonical_name, minor refactor of tests_charter.py
jennifer-richards Jun 13, 2023
c6d5f0d
refactor: charter.name instead of canonical_name in milestones.py
jennifer-richards Jun 13, 2023
04c6520
refactor: charter.name instead of canonical_name in tests_info.py
jennifer-richards Jun 13, 2023
d646bb2
refactor: Remove unused functions in ietf/secr/utils/groups.py
jennifer-richards Jun 13, 2023
4ce4dc1
refactor: charter.canonical_name -> charter.name in templates
jennifer-richards Jun 13, 2023
be8d38f
refactor: Remove charter handling from canonical_name
jennifer-richards Jun 13, 2023
c002ca8
refactor: Refactor get_charter_text() without canonical_name
jennifer-richards Jun 13, 2023
a490d29
refactor: Remove raise when canonical_name called on a charter
jennifer-richards Jun 13, 2023
df9746e
fix: Add back missing ".txt" extension
jennifer-richards Jun 13, 2023
153c5ad
test: Test rejection of invalid charter names
jennifer-richards Jun 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions ietf/doc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,12 +856,6 @@ def canonical_name(self):
a = self.docalias.filter(name__startswith="rfc").order_by('-name').first()
if a:
name = a.name
elif self.type_id == "charter":
from ietf.doc.utils_charter import charter_name_for_group # Imported locally to avoid circular imports
try:
name = charter_name_for_group(self.chartered_group)
except Group.DoesNotExist:
pass
self._canonical_name = name
return self._canonical_name

Expand Down
32 changes: 26 additions & 6 deletions ietf/doc/tests_charter.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ class EditCharterTests(TestCase):
settings_temp_path_overrides = TestCase.settings_temp_path_overrides + ['CHARTER_PATH']

def write_charter_file(self, charter):
with (Path(settings.CHARTER_PATH) /
("%s-%s.txt" % (charter.canonical_name(), charter.rev))
).open("w") as f:
f.write("This is a charter.")
(Path(settings.CHARTER_PATH) / f"{charter.name}-{charter.rev}.txt").write_text("This is a charter.")

def test_startstop_process(self):
CharterFactory(group__acronym='mars')
Expand Down Expand Up @@ -509,8 +506,13 @@ def test_submit_charter(self):
self.assertEqual(charter.rev, next_revision(prev_rev))
self.assertTrue("new_revision" in charter.latest_event().type)

with (Path(settings.CHARTER_PATH) / (charter.canonical_name() + "-" + charter.rev + ".txt")).open(encoding='utf-8') as f:
self.assertEqual(f.read(), "Windows line\nMac line\nUnix line\n" + utf_8_snippet.decode('utf-8'))
file_contents = (
Path(settings.CHARTER_PATH) / (charter.name + "-" + charter.rev + ".txt")
).read_text("utf-8")
self.assertEqual(
file_contents,
"Windows line\nMac line\nUnix line\n" + utf_8_snippet.decode("utf-8"),
)

def test_submit_initial_charter(self):
group = GroupFactory(type_id='wg',acronym='mars',list_email='mars-wg@ietf.org')
Expand Down Expand Up @@ -538,6 +540,24 @@ def test_submit_initial_charter(self):
group = Group.objects.get(pk=group.pk)
self.assertEqual(group.charter, charter)

def test_submit_charter_with_invalid_name(self):
self.client.login(username="secretary", password="secretary+password")
ietf_group = GroupFactory(type_id="wg")
for bad_name in ("charter-irtf-{}", "charter-randomjunk-{}", "charter-ietf-thisisnotagroup"):
url = urlreverse("ietf.doc.views_charter.submit", kwargs={"name": bad_name.format(ietf_group.acronym)})
r = self.client.get(url)
self.assertEqual(r.status_code, 404, f"GET of charter named {bad_name} should 404")
r = self.client.post(url, {})
self.assertEqual(r.status_code, 404, f"POST of charter named {bad_name} should 404")

irtf_group = GroupFactory(type_id="rg")
for bad_name in ("charter-ietf-{}", "charter-whatisthis-{}", "charter-irtf-thisisnotagroup"):
url = urlreverse("ietf.doc.views_charter.submit", kwargs={"name": bad_name.format(irtf_group.acronym)})
r = self.client.get(url)
self.assertEqual(r.status_code, 404, f"GET of charter named {bad_name} should 404")
r = self.client.post(url, {})
self.assertEqual(r.status_code, 404, f"POST of charter named {bad_name} should 404")

def test_edit_review_announcement_text(self):
area = GroupFactory(type_id='area')
RoleFactory(name_id='ad',group=area,person=Person.objects.get(user__username='ad'))
Expand Down
14 changes: 7 additions & 7 deletions ietf/doc/utils_charter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@


import datetime
import io
import os
import re
import shutil

from pathlib import Path

from django.conf import settings
from django.urls import reverse as urlreverse
from django.template.loader import render_to_string
Expand Down Expand Up @@ -62,10 +63,9 @@ def next_approved_revision(rev):
return "%#02d" % (int(m.group('major')) + 1)

def read_charter_text(doc):
filename = os.path.join(settings.CHARTER_PATH, '%s-%s.txt' % (doc.canonical_name(), doc.rev))
filename = Path(settings.CHARTER_PATH) / f"{doc.name}-{doc.rev}.txt"
try:
with io.open(filename, 'r') as f:
return f.read()
return filename.read_text()
except IOError:
return "Error: couldn't read charter text"

Expand All @@ -92,16 +92,16 @@ def change_group_state_after_charter_approval(group, by):
def fix_charter_revision_after_approval(charter, by):
# according to spec, 00-02 becomes 01, so copy file and record new revision
try:
old = os.path.join(charter.get_file_path(), '%s-%s.txt' % (charter.canonical_name(), charter.rev))
new = os.path.join(charter.get_file_path(), '%s-%s.txt' % (charter.canonical_name(), next_approved_revision(charter.rev)))
old = os.path.join(charter.get_file_path(), '%s-%s.txt' % (charter.name, charter.rev))
new = os.path.join(charter.get_file_path(), '%s-%s.txt' % (charter.name, next_approved_revision(charter.rev)))
shutil.copy(old, new)
except IOError:
log("There was an error copying %s to %s" % (old, new))

events = []
e = NewRevisionDocEvent(doc=charter, by=by, type="new_revision")
e.rev = next_approved_revision(charter.rev)
e.desc = "New version available: <b>%s-%s.txt</b>" % (charter.canonical_name(), e.rev)
e.desc = "New version available: <b>%s-%s.txt</b>" % (charter.name, e.rev)
e.save()
events.append(e)

Expand Down
Loading