[REM] mail: remove follow / unfollow buttons in notification emails

Notification emails contain a link allowing to follow or unfollow
documents directly from the notification email. However there are
several issues with this button

 * it require people to login to follow or unfollow documents;
 * it is not linked to the email;
 * if the customer does not have a login it is not possible to perform
   the action;
 * there is no confirmation step;

This commit removes the follow / unfollow button in the notification
emails. Indeed as people have the "Access document" button there is
only one more click to perform in order to subscribe or unsubscribe.
Concerning customers adding a complete control of the follow mechanism
would be costly in term of code and access rights checks. We therefore
decided to remove this button.

It also allows to simplify a bit the notification process as there
are less parameters to take into account when grouping recipients. It
allows to lessen the number of required template rendering when sending
notification emails.
This commit is contained in:
Thibault Delavallée
2018-01-29 14:19:53 +01:00
parent 27b30daea5
commit 11d2d30e91
3 changed files with 7 additions and 67 deletions
-12
View File
@@ -91,18 +91,6 @@
<a href="${ctx['button_access']['url']}" style="padding: 8px 12px; font-size: 12px; color: #FFFFFF; text-decoration: none !important; font-weight: 400; background-color: #875A7B; border: 0px solid #875A7B; border-radius:3px">${ctx['button_access']['title']}</a>
% endif
% if ctx.get('has_button_follow'):
% if ctx.get('has_button_access'):
|
% endif
<a href="${ctx['button_follow']['url']}" style="color: #875A7B; text-decoration: none !important;">${ctx['button_follow']['title']}</a>
% elif ctx.get('has_button_unfollow'):
% if ctx.get('has_button_access'):
|
% endif
<a href="${ctx['button_unfollow']['url']}" style="color: #875A7B; text-decoration: none !important;">${ctx['button_unfollow']['title']}</a>
% endif
% if ctx.get('actions'):
% for action in ctx['actions']:
|
+2 -35
View File
@@ -652,14 +652,6 @@ class MailThread(models.AbstractModel):
* has_button_access: whether to display Access <Document> in email. True
by default for new groups, False for portal / customer.
* button_access: dict with url and title of the button
* has_button_follow: whether to display Follow in email (if recipient is
not currently following the thread). True by default for new groups,
False for portal / customer.
* button_follow: dict with url adn title of the button
* has_button_unfollow: whether to display Unfollow in email (if recipient
is currently following the thread). True by default for new groups,
False for portal / customer.
* button_unfollow: dict with url and title of the button
* actions: list of action buttons to display in the notification email.
Each action is a dict containing url and title of the button.
@@ -672,17 +664,8 @@ class MailThread(models.AbstractModel):
def _message_notification_recipients(self, message, recipients):
# At this point, all access rights should be ok. We sudo everything to
# access rights checks and speedup the computation.
recipients_sudo = recipients.sudo()
result = {}
doc_followers = self.env['mail.followers']
if message.model and message.res_id:
doc_followers = self.env['mail.followers'].sudo().search([
('res_model', '=', message.model),
('res_id', '=', message.res_id),
('partner_id', 'in', recipients_sudo.ids)])
partner_followers = doc_followers.mapped('partner_id')
if self._context.get('auto_delete', False):
access_link = self._notification_link_helper('view')
else:
@@ -698,13 +681,9 @@ class MailThread(models.AbstractModel):
('user', lambda partner: bool(partner.user_ids) and not any(user.share for user in partner.user_ids), {}),
('portal', lambda partner: bool(partner.user_ids) and all(user.share for user in partner.user_ids), {
'has_button_access': False,
'has_button_follow': False,
'has_button_unfollow': False,
}),
('customer', lambda partner: True, {
'has_button_access': False,
'has_button_follow': False,
'has_button_unfollow': False,
})
]
@@ -715,25 +694,13 @@ class MailThread(models.AbstractModel):
group_data.setdefault('button_access', {
'url': access_link,
'title': view_title})
group_data.setdefault('has_button_follow', True)
group_data.setdefault('button_follow', {
'url': self._notification_link_helper('follow', model=message.model, res_id=message.res_id),
'title': _('Follow')})
group_data.setdefault('has_button_unfollow', True)
group_data.setdefault('button_unfollow', {
'url': self._notification_link_helper('unfollow', model=message.model, res_id=message.res_id),
'title': _('Unfollow')})
group_data.setdefault('actions', list())
group_data.setdefault('followers', self.env['res.partner'])
group_data.setdefault('not_followers', self.env['res.partner'])
group_data.setdefault('recipients', self.env['res.partner'])
for recipient in recipients:
for group_name, group_func, group_data in groups:
if group_func(recipient):
if recipient in partner_followers:
group_data['followers'] |= recipient
else:
group_data['not_followers'] |= recipient
group_data['recipients'] |= recipient
break
for group_name, group_method, group_data in groups:
+5 -20
View File
@@ -179,29 +179,14 @@ class Partner(models.Model):
emails = self.env['mail.mail']
recipients_nbr, recipients_max = 0, 50
for email_type, recipient_template_values in recipients.items():
if recipient_template_values['followers']:
if recipient_template_values['recipients']:
# generate notification email content
template_fol_values = dict(base_template_ctx, **recipient_template_values) # fixme: set button_unfollow to none
template_fol_values['has_button_follow'] = False
template_fol = base_template.with_context(**template_fol_values)
template_ctx = dict(base_template_ctx, **recipient_template_values) # fixme: set button_unfollow to none
template = base_template.with_context(**template_ctx)
# generate templates for followers and not followers
fol_values = template_fol.generate_email(message.id, fields=['body_html', 'subject'])
fol_values = template.generate_email(message.id, fields=['body_html', 'subject'])
# send email
new_emails, new_recipients_nbr = self._notify_send(fol_values['body'], fol_values['subject'], recipient_template_values['followers'], **base_mail_values)
# update notifications
self._notify_udpate_notifications(new_emails)
emails |= new_emails
recipients_nbr += new_recipients_nbr
if recipient_template_values['not_followers']:
# generate notification email content
template_not_values = dict(base_template_ctx, **recipient_template_values) # fixme: set button_follow to none
template_not_values['has_button_unfollow'] = False
template_not = base_template.with_context(**template_not_values)
# generate templates for followers and not followers
not_values = template_not.generate_email(message.id, fields=['body_html', 'subject'])
# send email
new_emails, new_recipients_nbr = self._notify_send(not_values['body'], not_values['subject'], recipient_template_values['not_followers'], **base_mail_values)
new_emails, new_recipients_nbr = self._notify_send(fol_values['body'], fol_values['subject'], recipient_template_values['recipients'], **base_mail_values)
# update notifications
self._notify_udpate_notifications(new_emails)