From 975a76daf468afa9fe9386086d966c1a58173d77 Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 18 Nov 2016 09:40:36 +0100 Subject: [PATCH] check if pdf is encrypted --- openslides/mediafiles/serializers.py | 5 +++++ openslides/mediafiles/static/js/mediafiles/base.js | 2 +- .../static/templates/mediafiles/mediafile-list.html | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/openslides/mediafiles/serializers.py b/openslides/mediafiles/serializers.py index 368404485..3eacc057b 100644 --- a/openslides/mediafiles/serializers.py +++ b/openslides/mediafiles/serializers.py @@ -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 diff --git a/openslides/mediafiles/static/js/mediafiles/base.js b/openslides/mediafiles/static/js/mediafiles/base.js index 736644988..534877d55 100644 --- a/openslides/mediafiles/static/js/mediafiles/base.js +++ b/openslides/mediafiles/static/js/mediafiles/base.js @@ -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; diff --git a/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html b/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html index a33805e95..cf9f5515f 100644 --- a/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html +++ b/openslides/mediafiles/static/templates/mediafiles/mediafile-list.html @@ -233,7 +233,9 @@ {{ mediafile.title_or_filename }} -
{{ mediafile.filetype }} +
{{ mediafile.filetype }} + (Encrypted) +
{{ mediafile.filesize }}
Private