From d353e91c26a3895d458b1574d550613a16e5c86b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Warnon?= Date: Mon, 5 Jun 2023 08:36:51 +0000 Subject: [PATCH] [FIX] website_slides: failsafe when sharing content without a template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit implements a failsafe when trying to share a slide.slide by email using the "Share" button in the course view. Instead of a traceback, the user will now receive a clear error message. Complementary to odoo/odoo#117952 that only handled sharing courses. Task-3343052 closes odoo/odoo#127172 X-original-commit: 67a43047a0f81036abeae44c44ab05dd781238bb Signed-off-by: Thibault Delavallee (tde) Signed-off-by: Warnon Aurélien (awa) --- addons/website_slides/i18n/website_slides.pot | 9 ++++++ addons/website_slides/models/slide_slide.py | 5 +++- .../tests/test_slide_channel.py | 28 ++++++++++++++----- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/addons/website_slides/i18n/website_slides.pot b/addons/website_slides/i18n/website_slides.pot index 6aedc21ab34..2b0267a27b5 100644 --- a/addons/website_slides/i18n/website_slides.pot +++ b/addons/website_slides/i18n/website_slides.pot @@ -3317,6 +3317,15 @@ msgid "" "%(course_names)s first" msgstr "" +#. module: website_slides +#. odoo-python +#: code:addons/website_slides/models/slide_slide.py:0 +#, python-format +msgid "" +"Impossible to send emails. Select a \"Share Template\" for courses " +"%(course_names)s first" +msgstr "" + #. module: website_slides #: model:slide.answer,comment:website_slides.slide_slide_demo_1_4_question_0_1 #: model:slide.answer,comment:website_slides.slide_slide_demo_2_0_question_0_0 diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py index dc25c610d18..0042d0b5363 100644 --- a/addons/website_slides/models/slide_slide.py +++ b/addons/website_slides/models/slide_slide.py @@ -794,7 +794,10 @@ class Slide(models.Model): return self._sign_token(partner_id) def _send_share_email(self, email, fullscreen): - # TDE FIXME: template to check + courses_without_templates = self.channel_id.filtered(lambda channel: not channel.share_slide_template_id) + if courses_without_templates: + raise UserError(_('Impossible to send emails. Select a "Share Template" for courses %(course_names)s first', + course_names=', '.join(courses_without_templates.mapped('name')))) mail_ids = [] for record in self: template = record.channel_id.share_slide_template_id.with_context( diff --git a/addons/website_slides/tests/test_slide_channel.py b/addons/website_slides/tests/test_slide_channel.py index 192eab54a97..8374b3cbc39 100644 --- a/addons/website_slides/tests/test_slide_channel.py +++ b/addons/website_slides/tests/test_slide_channel.py @@ -205,18 +205,32 @@ class TestSlidesManagement(slides_common.SlidesCase): @users('user_officer') def test_share_without_template(self): channel_without_template = self.env['slide.channel'].create({ - 'name': 'Course Without Template 2', + 'name': 'Course Without Template', 'slide_ids': [(0, 0, { - 'name': 'Test Slide 2' + 'name': 'Test Slide' })], - 'share_channel_template_id': False + 'share_channel_template_id': False, + 'share_slide_template_id': False, }) all_channels = self.channel | channel_without_template - with self.assertRaises(UserError) as cm: + + # try sharing the course + with self.assertRaises(UserError) as user_error: all_channels._send_share_email("test@test.com") - self.assertEqual(cm.exception.args[0], - f'Impossible to send emails. Select a "Channel Share Template" for courses {channel_without_template.name} first' - ) + + self.assertEqual( + user_error.exception.args[0], + f'Impossible to send emails. Select a "Channel Share Template" for courses {channel_without_template.name} first' + ) + + # try sharing slides + with self.assertRaises(UserError) as user_error: + all_channels.slide_ids._send_share_email("test@test.com", False) + + self.assertEqual( + user_error.exception.args[0], + f'Impossible to send emails. Select a "Share Template" for courses {channel_without_template.name} first' + ) def test_unlink_slide_channel(self): self.assertTrue(self.channel.slide_content_ids.mapped('question_ids').exists(),