check if pdf is encrypted

This commit is contained in:
FinnStutzenstein 2016-11-18 09:40:36 +01:00
parent f84c381f38
commit 975a76daf4
3 changed files with 9 additions and 2 deletions

View File

@ -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

View File

@ -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;

View File

@ -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}">