From 8eac410996bd9813cf1972ac6e71560ddb582775 Mon Sep 17 00:00:00 2001 From: "Nasreddin Boulif (bon)" <bon@odoo.com> Date: Fri, 17 Sep 2021 12:22:22 +0000 Subject: [PATCH] [FIX] website_slides: Don't set completion_time for encrypt/corrupt PDF Steps to reproduce: - Install eLearning module - Go to eLearning, open course Basics of Gardening and edit it - Click on `How to Grow and Harvest The Best Strawberries | Basics` - Upload an encrypted PDF as Attachement Issue: Traceback is raised : utils.PdfReadError("File has not been decrypted") Cause: When trying to calculate `completion_time` to read pages, we try to get the number of pages of the pdf but an error will be raised if the pdf is encrypted. Solution: If not possible to get number of pages, we dont set/update the completion_time. opw-2612529 closes odoo/odoo#76745 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com> --- addons/website_slides/models/slide_slide.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py index ea05c3c2d5ca..5f2483579068 100644 --- a/addons/website_slides/models/slide_slide.py +++ b/addons/website_slides/models/slide_slide.py @@ -352,6 +352,10 @@ class Slide(models.Model): data = base64.b64decode(self.datas) if data.startswith(b'%PDF-'): pdf = PyPDF2.PdfFileReader(io.BytesIO(data), overwriteWarnings=False, strict=False) + try: + pdf.getNumPages() + except PyPDF2.utils.PdfReadError: + return self.completion_time = (5 * len(pdf.pages)) / 60 @api.depends('name', 'channel_id.website_id.domain') -- GitLab