Merged in [19679] from jennifer@painless-security.com:
Include requester's last name as part of a bofreq document's name. Fixes #3377.
- Legacy-Id: 19722
Note: SVN reference [19679] has been migrated to Git commit 0d1aa09275
This commit is contained in:
commit
b7b8901d98
|
@ -464,11 +464,14 @@ class BofreqResponsibleDocEventFactory(DocEventFactory):
|
|||
class BofreqFactory(BaseDocumentFactory):
|
||||
type_id = 'bofreq'
|
||||
title = factory.Faker('sentence')
|
||||
name = factory.LazyAttribute(lambda o: 'bofreq-%s'%(xslugify(o.title)))
|
||||
name = factory.LazyAttribute(lambda o: 'bofreq-%s-%s'%(xslugify(o.requester_lastname), xslugify(o.title)))
|
||||
|
||||
bofreqeditordocevent = factory.RelatedFactory('ietf.doc.factories.BofreqEditorDocEventFactory','doc')
|
||||
bofreqresponsibledocevent = factory.RelatedFactory('ietf.doc.factories.BofreqResponsibleDocEventFactory','doc')
|
||||
|
||||
class Params:
|
||||
requester_lastname = factory.Faker('last_name')
|
||||
|
||||
@factory.post_generation
|
||||
def states(obj, create, extracted, **kwargs):
|
||||
if not create:
|
||||
|
|
|
@ -20,6 +20,7 @@ from ietf.doc.utils_bofreq import bofreq_editors, bofreq_responsible
|
|||
from ietf.person.factories import PersonFactory
|
||||
from ietf.utils.mail import outbox, empty_outbox
|
||||
from ietf.utils.test_utils import TestCase, reload_db_objects, unicontent, login_testing_unauthorized
|
||||
from ietf.utils.text import xslugify
|
||||
|
||||
|
||||
class BofreqTests(TestCase):
|
||||
|
@ -330,7 +331,7 @@ This test section has some text.
|
|||
empty_outbox()
|
||||
r = self.client.post(url, postdict)
|
||||
self.assertEqual(r.status_code,302)
|
||||
name = f"bofreq-{postdict['title']}".replace(' ','-')
|
||||
name = f"bofreq-{xslugify(nobody.last_name())[:64]}-{postdict['title']}".replace(' ','-')
|
||||
bofreq = Document.objects.filter(name=name,type_id='bofreq').first()
|
||||
self.assertIsNotNone(bofreq)
|
||||
self.assertIsNotNone(DocAlias.objects.filter(name=name).first())
|
||||
|
@ -342,7 +343,7 @@ This test section has some text.
|
|||
self.assertEqual(bofreq.text_or_error(), 'some stuff')
|
||||
self.assertEqual(len(outbox),1)
|
||||
os.unlink(file.name)
|
||||
existing_bofreq = BofreqFactory()
|
||||
existing_bofreq = BofreqFactory(requester_lastname=nobody.last_name())
|
||||
for postdict in [
|
||||
dict(title='', bofreq_submission='enter', bofreq_content='some stuff'),
|
||||
dict(title='a title', bofreq_submission='enter', bofreq_content=''),
|
||||
|
@ -351,9 +352,9 @@ This test section has some text.
|
|||
dict(title='a title', bofreq_submission='', bofreq_content='some stuff'),
|
||||
]:
|
||||
r = self.client.post(url,postdict)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(r.status_code, 200, f'Wrong status_code for {postdict}')
|
||||
q = PyQuery(r.content)
|
||||
self.assertTrue(q('form div.has-error'))
|
||||
self.assertTrue(q('form div.has-error'), f'Expected an error for {postdict}')
|
||||
|
||||
def test_post_proposed_restrictions(self):
|
||||
states = State.objects.filter(type_id='bofreq').exclude(slug='proposed')
|
||||
|
|
|
@ -113,14 +113,20 @@ class NewBofreqForm(BofreqUploadForm):
|
|||
title = forms.CharField(max_length=255)
|
||||
field_order = ['title','bofreq_submission','bofreq_file','bofreq_content']
|
||||
|
||||
def name_from_title(self,title):
|
||||
name = 'bofreq-' + xslugify(title).replace('_', '-')[:128]
|
||||
return name
|
||||
def __init__(self, requester, *args, **kwargs):
|
||||
self._requester = requester
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def name_from_title(self, title):
|
||||
requester_slug = xslugify(self._requester.last_name())
|
||||
title_slug = xslugify(title)
|
||||
name = f'bofreq-{requester_slug[:64]}-{title_slug[:128]}'
|
||||
return name.replace('_', '-')
|
||||
|
||||
def clean_title(self):
|
||||
title = self.cleaned_data['title']
|
||||
name = self.name_from_title(title)
|
||||
if name == 'bofreq-':
|
||||
if name == self.name_from_title(''):
|
||||
raise forms.ValidationError('The filename derived from this title is empty. Please include a few descriptive words using ascii or numeric characters')
|
||||
if Document.objects.filter(name=name).exists():
|
||||
raise forms.ValidationError('This title produces a filename already used by an existing BOF request')
|
||||
|
@ -130,7 +136,7 @@ class NewBofreqForm(BofreqUploadForm):
|
|||
def new_bof_request(request):
|
||||
|
||||
if request.method == 'POST':
|
||||
form = NewBofreqForm(request.POST, request.FILES)
|
||||
form = NewBofreqForm(request.user.person, request.POST, request.FILES)
|
||||
if form.is_valid():
|
||||
title = form.cleaned_data['title']
|
||||
name = form.name_from_title(title)
|
||||
|
@ -175,7 +181,7 @@ def new_bof_request(request):
|
|||
init = {'bofreq_content':render_to_string('doc/bofreq/bofreq_template.md',{}),
|
||||
'bofreq_submission':'enter',
|
||||
}
|
||||
form = NewBofreqForm(initial=init)
|
||||
form = NewBofreqForm(request.user.person, initial=init)
|
||||
return render(request, 'doc/bofreq/new_bofreq.html',
|
||||
{'form':form})
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% extends "base.html" %}
|
||||
{# Copyright The IETF Trust 2021, All Rights Reserved #}
|
||||
{% load origin bootstrap3 static %}
|
||||
{% load origin bootstrap3 static textfilters %}
|
||||
|
||||
{% block title %}Start a new BOF Request{% endblock %}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
|||
<h1>Start a new BOF Request</h1>
|
||||
|
||||
<p>Choose a short descriptive title for your request. Take time to choose a good initial title - it will be used to make the filename for your request's content. The title can be changed later, but the filename will not change.</p>
|
||||
<p>For example, a request with a title of "A new important bit" will be saved as "bofreq-a-new-important-bit-00.md".</p>
|
||||
<p>For example, a request with a title of "A new important bit" will be saved as "bofreq-{{ user.person.last_name|xslugify|slice:"64" }}-a-new-important-bit-00.md".</p>
|
||||
<form class="upload-content form-horizontal" method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
|
||||
|
|
Loading…
Reference in a new issue