Skip to content

Commit

Permalink
[FIX] auth_signup: don't remove actual content from email templates
Browse files Browse the repository at this point in the history
such as auth_signup's invitation email.
  • Loading branch information
StefanRijnhart committed Dec 28, 2023
1 parent 0f0eb13 commit a6e39eb
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 29 deletions.
11 changes: 10 additions & 1 deletion mail_debrand/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Mail Debrand
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:59f886e3807a8cf39eefa8b132d491add7d1fa4ee7d383d6ab8bbedc315166c4
!! source digest: sha256:f4542ce5590883f0be2694527bd05fc39b3c6c9b9526d024df2760cfef90ee32
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
Expand Down Expand Up @@ -45,6 +45,15 @@ To use this module, you need to:
* Send an email.
* Nobody will know it comes from Odoo.

Known issues / Roadmap
======================

Known issues:

* Not all branding is removed from auth_signup's invitation email because it is a
longer, more complex snippet of HTML. Only the line containing the link to Odoo.com
is removed.

Changelog
=========

Expand Down
2 changes: 1 addition & 1 deletion mail_debrand/models/mail_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ class MailMail(models.AbstractModel):
def _send_prepare_body(self):
body_html = super()._send_prepare_body()
return self.env["mail.render.mixin"].remove_href_odoo(
body_html or "", remove_parent=0, to_keep=self.body
body_html or "", to_keep=self.body
)
18 changes: 8 additions & 10 deletions mail_debrand/models/mail_render_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class MailRenderMixin(models.AbstractModel):
_inherit = "mail.render.mixin"

def remove_href_odoo(self, value, remove_parent=True, to_keep=None):
def remove_href_odoo(self, value, to_keep=None):
if len(value) < 20:
return value
# value can be bytes or markup; ensure we get a proper string and preserve type
Expand All @@ -38,15 +38,13 @@ def remove_href_odoo(self, value, remove_parent=True, to_keep=None):
odoo_anchors = tree.xpath('//a[contains(@href,"odoo.com")]')
for elem in odoo_anchors:
parent = elem.getparent()
if remove_parent and parent.getparent() is not None:
# anchor <a href odoo has a parent powered by that must be removed
parent.getparent().remove(parent)
else:
previous = elem.getprevious()
if previous is not None:
# Remove "Powered by", "using" etc.
previous.tail = ""
parent.remove(elem)
# Remove "Powered by", "using" etc.
previous = elem.getprevious()
if previous is not None:
previous.tail = ""
elif parent.text:
parent.text = ""
parent.remove(elem)
value = etree.tostring(
tree, pretty_print=True, method="html", encoding="unicode"
)
Expand Down
5 changes: 5 additions & 0 deletions mail_debrand/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Known issues:

* Not all branding is removed from auth_signup's invitation email because it is a
longer, more complex snippet of HTML. Only the line containing the link to Odoo.com
is removed.
44 changes: 27 additions & 17 deletions mail_debrand/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Mail Debrand</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:59f886e3807a8cf39eefa8b132d491add7d1fa4ee7d383d6ab8bbedc315166c4
!! source digest: sha256:f4542ce5590883f0be2694527bd05fc39b3c6c9b9526d024df2760cfef90ee32
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/16.0/mail_debrand"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_debrand"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module modifies the functionality of emails to remove the Odoo branding,
Expand All @@ -376,16 +376,17 @@ <h1 class="title">Mail Debrand</h1>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
<li><a class="reference internal" href="#changelog" id="toc-entry-2">Changelog</a><ul>
<li><a class="reference internal" href="#section-1" id="toc-entry-3">15.0.1.2.3 (2022-07-19)</a></li>
<li><a class="reference internal" href="#section-2" id="toc-entry-4">12.0.1.0.0 (2018-11-06)</a></li>
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-2">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#changelog" id="toc-entry-3">Changelog</a><ul>
<li><a class="reference internal" href="#section-1" id="toc-entry-4">15.0.1.2.3 (2022-07-19)</a></li>
<li><a class="reference internal" href="#section-2" id="toc-entry-5">12.0.1.0.0 (2018-11-06)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-5">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-6">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-7">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-8">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-9">Maintainers</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-6">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-7">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-8">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-9">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-10">Maintainers</a></li>
</ul>
</li>
</ul>
Expand All @@ -399,34 +400,43 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<li>Nobody will know it comes from Odoo.</li>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
<p>Known issues:</p>
<ul class="simple">
<li>Not all branding is removed from auth_signup’s invitation email because it is a
longer, more complex snippet of HTML. Only the line containing the link to Odoo.com
is removed.</li>
</ul>
</div>
<div class="section" id="changelog">
<h1><a class="toc-backref" href="#toc-entry-2">Changelog</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Changelog</a></h1>
<div class="section" id="section-1">
<h2><a class="toc-backref" href="#toc-entry-3">15.0.1.2.3 (2022-07-19)</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">15.0.1.2.3 (2022-07-19)</a></h2>
<ul class="simple">
<li>[FIX] <a class="reference external" href="https://github.com/OCA/social/issues/915">https://github.com/OCA/social/issues/915</a></li>
<li>[FIX] <a class="reference external" href="https://github.com/OCA/social/issues/936">https://github.com/OCA/social/issues/936</a></li>
</ul>
</div>
<div class="section" id="section-2">
<h2><a class="toc-backref" href="#toc-entry-4">12.0.1.0.0 (2018-11-06)</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">12.0.1.0.0 (2018-11-06)</a></h2>
<ul class="simple">
<li>[NEW] Initial V12 version. Complete rewrite from v11.</li>
</ul>
</div>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-5">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mail_debrand%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-6">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-7">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-7">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-8">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
<li>ForgeFlow</li>
Expand All @@ -436,7 +446,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Authors</a></h2>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-9">Contributors</a></h2>
<ul class="simple">
<li>Lois Rilo &lt;<a class="reference external" href="mailto:lois.rilo&#64;forgeflow.com">lois.rilo&#64;forgeflow.com</a>&gt;</li>
<li>Graeme Gellatly &lt;<a class="reference external" href="mailto:graeme&#64;o4sb.com">graeme&#64;o4sb.com</a>&gt;</li>
Expand All @@ -449,7 +459,7 @@ <h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
Expand Down
1 change: 1 addition & 0 deletions mail_debrand/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import test_mail_debrand
from . import test_mail_debrand_digest
from . import test_mail_debrand_signup
28 changes: 28 additions & 0 deletions mail_debrand/tests/test_mail_debrand_signup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from odoo.tests import TransactionCase, tagged


@tagged("-at_install", "post_install")
class TestMailDebrandSignup(TransactionCase):
def _has_module(self):
module = self.env["ir.module.module"].search([("name", "=", "auth_signup")])
self.assertTrue(module)
return module.state == "installed"

def test_debrand_auth_signup_set_password_email(self):
if not self._has_module():
return

Check warning on line 13 in mail_debrand/tests/test_mail_debrand_signup.py

View check run for this annotation

Codecov / codecov/patch

mail_debrand/tests/test_mail_debrand_signup.py#L13

Added line #L13 was not covered by tests
template = self.env.ref(
"auth_signup.set_password_email",
)
self.assertIn("www.odoo.com", template.body_html)
self.assertIn("Accept invitation", template.body_html)
self.assertIn("to discover the tool", template.body_html)

mail_id = template.send_mail(self.env.user.id)
body = self.env["mail.mail"].browse(mail_id).body_html

# The essential button is preserved
self.assertIn("Accept invitation", body)
# But at least part of the branding was removed
self.assertNotIn("www.odoo.com", body)
self.assertNotIn("to discover the tool", body)

0 comments on commit a6e39eb

Please sign in to comment.