Merge pull request #2641 from FinnStutzenstein/Issue2609
check if pdf is encrypted (closes #2609)
This commit is contained in:
commit
9b6fe6e3a2
@ -3,6 +3,7 @@ import mimetypes
|
||||
from django.conf import settings
|
||||
from django.db import models as dbmodels
|
||||
from PyPDF2 import PdfFileReader
|
||||
from PyPDF2.utils import PdfReadError
|
||||
|
||||
from ..utils.rest_api import FileField, ModelSerializer, SerializerMethodField
|
||||
from .models import Mediafile
|
||||
@ -29,6 +30,10 @@ class AngularCompatibleFileField(FileField):
|
||||
except FileNotFoundError:
|
||||
# File was deleted from server. Set 'pages' to 0.
|
||||
result['pages'] = 0
|
||||
except PdfReadError:
|
||||
# File could be encrypted but not be detected by PyPDF.
|
||||
result['pages'] = 0
|
||||
result['encrypted'] = True
|
||||
return result
|
||||
|
||||
|
||||
|
@ -53,7 +53,7 @@ angular.module('OpenSlidesApp.mediafiles', [])
|
||||
return _.includes(VIDEO_FILE_TYPES, filetype);
|
||||
}],
|
||||
is_presentable: ['is_pdf', 'is_image', 'is_video', function (is_pdf, is_image, is_video) {
|
||||
return is_pdf || is_image || is_video;
|
||||
return (is_pdf && !this.mediafile.encrypted) || is_image || is_video;
|
||||
}],
|
||||
mediafileUrl: [function () {
|
||||
return this.media_url_prefix + this.mediafile.name;
|
||||
|
@ -233,7 +233,9 @@
|
||||
<!-- mediafile data colums -->
|
||||
<td ng-mouseover="mediafile.hover=true" ng-mouseleave="mediafile.hover=false">
|
||||
<strong><a ng-href="{{ mediafile.mediafileUrl }}" target="_blank">{{ mediafile.title_or_filename }}</a></strong>
|
||||
<br><small><i class="fa fa-file"></i> {{ mediafile.filetype }}</small>
|
||||
<br><small><i class="fa fa-file"></i> {{ mediafile.filetype }}
|
||||
<span ng-if="mediafile.mediafile.encrypted">(<translate>Encrypted</translate>)</span>
|
||||
</small>
|
||||
<br><small><i class="fa fa-database"></i> {{ mediafile.filesize }}</small>
|
||||
<span ng-if="mediafile.private"><br><small><i class="fa fa-lock"></i> <translate>Private</translate></small></span>
|
||||
<div os-perms="mediafiles.can_manage" class="hoverActions" ng-class="{'hiddenDiv': !mediafile.hover}">
|
||||
|
Loading…
Reference in New Issue
Block a user