This commit is contained in:
parent
6216d0ed09
commit
c2e997a47f
|
@ -129,6 +129,10 @@ class Document(models.Model):
|
|||
self.content_hash = utils.sha256_of_file(self.content)
|
||||
if not self.mime_type:
|
||||
self.mime_type = utils.get_mime_type(self.content.file.name) or ''
|
||||
if self.content.name and len(self.content.name) > 200:
|
||||
file_root, file_ext = os.path.splitext(self.content.name)
|
||||
file_root, file_ext = file_root[:150], file_ext[:50]
|
||||
self.content.name = file_root + file_ext
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
@property
|
||||
|
|
|
@ -139,3 +139,22 @@ def test_push_document_slashed_name(app, admin_user, john_doe):
|
|||
assert doc.get_download_url() == '/%s/download/monfichier%%252018-06-2017.pdf' % doc.pk
|
||||
login(app, user=john_doe)
|
||||
app.get(doc.get_download_url(), status=200)
|
||||
|
||||
|
||||
def test_push_document_long_filename(app, admin_user, john_doe):
|
||||
login(app)
|
||||
url = '/api/documents/push/'
|
||||
data = {
|
||||
'user_email': john_doe.email,
|
||||
'origin': 'wcs',
|
||||
'file_b64_content': base64.b64encode(b'whatever').decode(),
|
||||
'file_name': '%s.pdf' % ('abc' * 100),
|
||||
}
|
||||
response = app.post_json(url, params=data, status=200)
|
||||
assert response.json['result'] == 1
|
||||
assert models.Document.objects.count() == 1
|
||||
doc = models.UserDocument.objects.first()
|
||||
assert doc.filename.startswith('abc') and doc.filename.endswith('.pdf')
|
||||
assert doc.get_download_url().endswith('.pdf')
|
||||
login(app, user=john_doe)
|
||||
app.get(doc.get_download_url(), status=200)
|
||||
|
|
Loading…
Reference in New Issue