From 67f0465818ce91857f5345f7d42add38049bc6b5 Mon Sep 17 00:00:00 2001 From: Raf Ven Date: Tue, 19 Jul 2022 12:29:02 +0200 Subject: [PATCH] [15.0-mail] [FIX] mail_debrand: text/plain issue + TypeError: object of type 'NoneType' has no len() --- mail_debrand/__manifest__.py | 2 +- mail_debrand/models/mail_render_mixin.py | 30 +++++++++++++++---- mail_debrand/readme/HISTORY.rst | 6 ++++ .../tests/test_mail_debrand_digest.py | 1 + 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/mail_debrand/__manifest__.py b/mail_debrand/__manifest__.py index 9b44e9e50..d57280c2a 100644 --- a/mail_debrand/__manifest__.py +++ b/mail_debrand/__manifest__.py @@ -12,7 +12,7 @@ ( for powerd by) form all the templates removes any 'odoo' that are in tempalte texts > 20characters """, - "version": "15.0.1.2.2", + "version": "15.0.1.2.3", "category": "Social Network", "website": "https://github.com/OCA/social", "author": """Tecnativa, ForgeFlow, Onestein, Sodexis, Nexterp Romania, diff --git a/mail_debrand/models/mail_render_mixin.py b/mail_debrand/models/mail_render_mixin.py index 4d3f15da1..39bb998bb 100644 --- a/mail_debrand/models/mail_render_mixin.py +++ b/mail_debrand/models/mail_render_mixin.py @@ -6,8 +6,9 @@ import re from lxml import etree, html +from markupsafe import Markup -from odoo import api, models +from odoo import api, models, tools class MailRenderMixin(models.AbstractModel): @@ -20,9 +21,15 @@ class MailRenderMixin(models.AbstractModel): return value # value can be bytes type; ensure we get a proper string if type(value) is bytes: + back_to_bytes = True value = value.decode() + else: + back_to_bytes = False + has_dev_odoo_link = re.search( + r" previous.tail = "" - if remove_parent and len(parent.getparent()): + if remove_parent and parent.getparent() is not None: # anchor ", to_keep) + if back_to_bytes: + value = value.encode() return value @api.model @@ -82,6 +92,7 @@ class MailRenderMixin(models.AbstractModel): res_ids, engine=engine, add_context=add_context, + options=options, post_process=post_process, ) @@ -91,8 +102,15 @@ class MailRenderMixin(models.AbstractModel): return orginal_rendered def _replace_local_links(self, html, base_url=None): - message = super()._replace_local_links(html) + message = super()._replace_local_links(html, base_url=base_url) + + wrapper = Markup if isinstance(message, Markup) else str + message = tools.ustr(message) + if isinstance(message, Markup): + wrapper = Markup + message = re.sub( r"""(Powered by\s(.*)Odoo)""", "
 
", message ) - return message + + return wrapper(message) diff --git a/mail_debrand/readme/HISTORY.rst b/mail_debrand/readme/HISTORY.rst index ad209cc2e..d2062c1b7 100644 --- a/mail_debrand/readme/HISTORY.rst +++ b/mail_debrand/readme/HISTORY.rst @@ -1,3 +1,9 @@ +15.0.1.2.3 (2022-07-19) +~~~~~~~~~~~~~~~~~~~~~~~ + +* [FIX] https://github.com/OCA/social/issues/915 +* [FIX] https://github.com/OCA/social/issues/936 + 12.0.1.0.0 (2018-11-06) ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/mail_debrand/tests/test_mail_debrand_digest.py b/mail_debrand/tests/test_mail_debrand_digest.py index 238b37716..807eecc61 100644 --- a/mail_debrand/tests/test_mail_debrand_digest.py +++ b/mail_debrand/tests/test_mail_debrand_digest.py @@ -68,3 +68,4 @@ class TestMailDebrandDigest(common.TransactionCase): self.assertNotEqual(rendered_body, None) self.assertNotEqual(rendered_body, False) self.assertNotEqual(rendered_body, "") + self.assertNotIn("Powered by", rendered_body)