[ADD] Customize notification appearance

Added settings to customize notification and translations to important parts of the message.

[FIX] Security fixes and simplified customization

Field `show_followers_partner_format` formatted with %(param)s
Removed CSS customizations

[FIX] README options

[FIX] Index.html configure

[FIX] Several changes

- Removed unnecesary properties on res_config_settings
- Markup safe on partner_format
- Use email_domain_extract instead own one
This commit is contained in:
Eduardo De Miguel 2022-03-18 14:21:16 +01:00
parent 5ee1f297b4
commit 59966f0f5d
9 changed files with 213 additions and 27 deletions

View File

@ -41,8 +41,11 @@ Configuration
To configure this module, you need to: To configure this module, you need to:
#. Go General settings/Discuss/Show Internal Users CC and set if want to show or not internal users in cc details. #. Go General settings/Discuss/Show Followers on mails/Show Internal Users CC and set if want to show or not internal users in cc details.
#. Go Settings/Users & Company salect any user in 'Preferences' check or not the 'Show in CC' field if this user need to appear in the cc note. #. Go Settings/Users & Company salect any user in 'Preferences' check or not the 'Show in CC' field if this user need to appear in the cc note.
#. Go General settings/Discuss/Show Followers on mails/Text 'Sent to' and set the initial part of the message.
#. Go General settings/Discuss/Show Followers on mails/Partner format and choose desired fields to show on CC recipients.
#. Go General settings/Discuss/Show Followers on mails/Text 'Replies' and choose desired warn message
Usage Usage
===== =====
@ -68,12 +71,14 @@ Authors
~~~~~~~ ~~~~~~~
* Sygel * Sygel
* Moduon
Contributors Contributors
~~~~~~~~~~~~ ~~~~~~~~~~~~
* Valentin Vinagre <valentin.vinagre@sygel.es> * Valentin Vinagre <valentin.vinagre@sygel.es>
* Lorenzo Battistini * Lorenzo Battistini
* Eduardo de Miguel <edu@moduon.team>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~

View File

@ -1,13 +1,14 @@
# Copyright 2020 Valentin Vinagre <valentin.vinagre@sygel.es> # Copyright 2020 Valentin Vinagre <valentin.vinagre@sygel.es>
# Copyright 2022 Eduardo de Miguel <edu@moduon.team>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{ {
"name": "Mail Show Follower", "name": "Mail Show Follower",
"summary": "Show CC document followers in mails.", "summary": "Show CC document followers in mails.",
"version": "15.0.1.0.0", "version": "15.0.1.1.0",
"category": "Mail", "category": "Mail",
"website": "https://github.com/OCA/social", "website": "https://github.com/OCA/social",
"author": "Sygel, Odoo Community Association (OCA)", "author": "Sygel, Moduon, Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"application": False, "application": False,
"installable": True, "installable": True,

View File

@ -1,16 +1,64 @@
from odoo import models from markupsafe import Markup
from odoo import api, models, tools
class MailMail(models.Model): class MailMail(models.Model):
_inherit = "mail.mail" _inherit = "mail.mail"
def _send(self, auto_commit=False, raise_exception=False, smtp_session=None): @api.model
plain_text = ( def _build_cc_text(self, partners):
'<div summary="o_mail_notification" style="padding: 0px; ' if not partners:
'font-size: 10px;"><b>CC</b>: %s<hr style="background-color:' return ""
"rgb(204,204,204);border:medium none;clear:both;display:block;"
'font-size:0px;min-height:1px;line-height:0; margin:4px 0 12px 0;"></div>' def get_ctx_param(ctx_key, default_parm):
if ctx_key in self.env.context:
return self.env.context[ctx_key]
return default_parm
def remove_p(markup_txt):
if markup_txt.startswith("<p>") and markup_txt.endswith("</p>"):
return markup_txt[3:-4]
return markup_txt
company = self.env.company
partner_format = get_ctx_param(
"partner_format", company.show_followers_partner_format
) )
msg_sent_to = get_ctx_param(
"msg_sent_to", company.show_followers_message_sent_to
)
msg_warn = get_ctx_param(
"msg_warn", company.show_followers_message_response_warning
)
partner_message = ", ".join(
[
partner_format
% {
# Supported parameters
"partner_name": p.name,
"partner_email": p.email,
"partner_email_domain": tools.email_domain_extract(p.email),
}
for p in partners
]
)
full_text = """
<div summary='o_mail_notification' style='padding:5px;
margin:10px 0px 10px 0px;font-size:13px;border-radius:5px;
font-family:Arial;border:1px solid #E0E2E6;background-color:#EBEBEB;'>
{msg_sent_to} {partner_message}
{rc}{msg_warn}
</div>
""".format(
msg_sent_to=remove_p(msg_sent_to),
partner_message=Markup.escape(partner_message),
rc=msg_warn.striptags() and "<br/>" or "",
msg_warn=msg_warn.striptags() and remove_p(msg_warn) or "",
)
return full_text
def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
group_portal = self.env.ref("base.group_portal") group_portal = self.env.ref("base.group_portal")
for mail_id in self.ids: for mail_id in self.ids:
mail = self.browse(mail_id) mail = self.browse(mail_id)
@ -73,13 +121,21 @@ class MailMail(models.Model):
or x.user_ids # otherwise, email is not sent or x.user_ids # otherwise, email is not sent
and "email" in x.user_ids.mapped("notification_type") and "email" in x.user_ids.mapped("notification_type")
) )
# get names and emails # set proper lang for recipients
final_cc = None langs = list(
mails = "" filter(
for p in partners: bool,
mails += "%s &lt;%s&gt;, " % (p.name, p.email) mail.mapped("recipient_ids.lang")
# join texts + [
final_cc = plain_text % (mails[:-2]) mail.author_id.lang,
self.env.company.partner_id.lang,
],
)
)
# get show follower text
final_cc = mail.with_context(
lang=langs and langs[0]
)._build_cc_text(partners)
# it is saved in the body_html field so that it does # it is saved in the body_html field so that it does
# not appear in the odoo log # not appear in the odoo log
mail.body_html = final_cc + mail.body_html mail.body_html = final_cc + mail.body_html

View File

@ -5,5 +5,24 @@ class ResCompany(models.Model):
_inherit = "res.company" _inherit = "res.company"
show_internal_users_cc = fields.Boolean( show_internal_users_cc = fields.Boolean(
string="Show Internal Users CC", default=True string="Show Internal Users CC",
default=True,
)
show_followers_message_sent_to = fields.Html(
string="Text 'Sent to'",
translate=True,
default="This message has been sent to",
)
show_followers_partner_format = fields.Char(
string="Partner format",
default="%(partner_name)s",
help="Supported parameters:\n"
"%(partner_name)s = Partner Name\n"
"%(partner_email)s = Partner Email\n"
"%(partner_email_domain)s = Partner Email Domain",
)
show_followers_message_response_warning = fields.Html(
string="Text 'Replies'",
translate=True,
default="Notice: Replies to this email will be sent to all recipients",
) )

View File

@ -1,11 +1,51 @@
from odoo import fields, models from odoo import api, fields, models
class ResConfigSettings(models.TransientModel): class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings" _inherit = "res.config.settings"
show_internal_users_cc = fields.Boolean( show_internal_users_cc = fields.Boolean(
string="Show Internal Users CC",
related="company_id.show_internal_users_cc", related="company_id.show_internal_users_cc",
readonly=False, readonly=False,
) )
show_followers_message_sent_to = fields.Html(
related="company_id.show_followers_message_sent_to",
readonly=False,
)
show_followers_partner_format = fields.Char(
related="company_id.show_followers_partner_format",
readonly=False,
help="Supported parameters:\n"
"%(partner_name)s = Partner Name\n"
"%(partner_email)s = Partner Email\n"
"%(partner_email_domain)s = Partner Email Domain",
)
show_followers_message_response_warning = fields.Html(
related="company_id.show_followers_message_response_warning",
readonly=False,
)
show_followers_message_preview = fields.Html(
string="Message preview",
readonly=True,
store=False,
)
@api.onchange(
"show_followers_message_sent_to",
"show_followers_partner_format",
"show_followers_message_response_warning",
)
def onchange_show_followers_message_preview(self):
self.show_followers_message_preview = (
self.env["mail.mail"]
.with_context(
# Use current data before
partner_format=self.show_followers_partner_format or "",
msg_sent_to=self.show_followers_message_sent_to or "",
msg_warn=self.show_followers_message_response_warning or "",
)
._build_cc_text(
# Sample partners
self.env["res.partner"].search([("email", "!=", False)], limit=3),
)
)

View File

@ -1,4 +1,7 @@
To configure this module, you need to: To configure this module, you need to:
#. Go General settings/Discuss/Show Internal Users CC and set if want to show or not internal users in cc details. #. Go General settings/Discuss/Show Followers on mails/Show Internal Users CC and set if want to show or not internal users in cc details.
#. Go Settings/Users & Company salect any user in 'Preferences' check or not the 'Show in CC' field if this user need to appear in the cc note. #. Go Settings/Users & Company salect any user in 'Preferences' check or not the 'Show in CC' field if this user need to appear in the cc note.
#. Go General settings/Discuss/Show Followers on mails/Text 'Sent to' and set the initial part of the message.
#. Go General settings/Discuss/Show Followers on mails/Partner format and choose desired fields to show on CC recipients.
#. Go General settings/Discuss/Show Followers on mails/Text 'Replies' and choose desired warn message

View File

@ -1,2 +1,3 @@
* Valentin Vinagre <valentin.vinagre@sygel.es> * Valentin Vinagre <valentin.vinagre@sygel.es>
* Lorenzo Battistini * Lorenzo Battistini
* Eduardo de Miguel <edu@moduon.team>

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" /> <meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Mail Show Follower</title> <title>Mail Show Follower</title>
<style type="text/css"> <style type="text/css">
@ -392,8 +392,11 @@ In the cc, only appear when:</p>
<h1><a class="toc-backref" href="#id1">Configuration</a></h1> <h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<p>To configure this module, you need to:</p> <p>To configure this module, you need to:</p>
<ol class="arabic simple"> <ol class="arabic simple">
<li>Go General settings/Discuss/Show Internal Users CC and set if want to show or not internal users in cc details.</li> <li>Go General settings/Discuss/Show Followers on mails/Show Internal Users CC and set if want to show or not internal users in cc details.</li>
<li>Go Settings/Users &amp; Company salect any user in Preferences check or not the Show in CC field if this user need to appear in the cc note.</li> <li>Go Settings/Users &amp; Company salect any user in Preferences check or not the Show in CC field if this user need to appear in the cc note.</li>
<li>Go General settings/Discuss/Show Followers on mails/Text Sent to and set the initial part of the message.</li>
<li>Go General settings/Discuss/Show Followers on mails/Partner format and choose desired fields to show on CC recipients.</li>
<li>Go General settings/Discuss/Show Followers on mails/Text Replies and choose desired warn message</li>
</ol> </ol>
</div> </div>
<div class="section" id="usage"> <div class="section" id="usage">
@ -417,6 +420,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<h2><a class="toc-backref" href="#id5">Authors</a></h2> <h2><a class="toc-backref" href="#id5">Authors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Sygel</li> <li>Sygel</li>
<li>Moduon</li>
</ul> </ul>
</div> </div>
<div class="section" id="contributors"> <div class="section" id="contributors">
@ -424,6 +428,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<ul class="simple"> <ul class="simple">
<li>Valentin Vinagre &lt;<a class="reference external" href="mailto:valentin.vinagre&#64;sygel.es">valentin.vinagre&#64;sygel.es</a>&gt;</li> <li>Valentin Vinagre &lt;<a class="reference external" href="mailto:valentin.vinagre&#64;sygel.es">valentin.vinagre&#64;sygel.es</a>&gt;</li>
<li>Lorenzo Battistini</li> <li>Lorenzo Battistini</li>
<li>Eduardo de Miguel &lt;<a class="reference external" href="mailto:edu&#64;moduon.team">edu&#64;moduon.team</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">

View File

@ -10,12 +10,68 @@
<div id="emails" position="inside"> <div id="emails" position="inside">
<div class="col-12 col-lg-6 o_setting_box"> <div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane"> <div class="o_setting_left_pane">
<field name="show_internal_users_cc" />
</div> </div>
<div class="o_setting_right_pane"> <div class="o_setting_right_pane">
<label for="show_internal_users_cc" /> <div class="content-group">
<div class="text-muted" id="show_internal_users_cc"> <label
Add internal users in cc mails details for="show_internal_users_cc"
string="Show Followers on mails"
/>
<div>
<div>
<label
for="show_internal_users_cc"
class="o_light_label"
string="Show Internal Users on CC"
/>
<field name="show_internal_users_cc" />
</div>
<div>
<label
for="show_followers_message_sent_to"
class="o_light_label"
style="vertical-align: top;"
/>
<field
name="show_followers_message_sent_to"
placeholder="This message has been sent to"
style="display:inline-block;"
/>
</div>
<div>
<label
for="show_followers_partner_format"
class="o_light_label"
style="vertical-align: top;"
/>
<field
name="show_followers_partner_format"
placeholder="%%(partner_name)s &lt;%%(partner_email)s&gt;"
style="display:inline-block;"
/>
</div>
<div>
<label
for="show_followers_message_response_warning"
class="o_light_label"
style="vertical-align: top;"
/>
<field
name="show_followers_message_response_warning"
placeholder="Notice: Replies to this email will be sent to all recipients."
style="display:inline-block;"
/>
</div>
</div>
<label
for="show_followers_message_preview"
class="text-muted"
/>
<field
name="show_followers_message_preview"
style="width:100%;"
widget="html"
/>
</div> </div>
</div> </div>
</div> </div>