[FIX] website_slides: failsafe when sharing content without a template
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) <tde@openerp.com> Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user