[IMP] mail: lessen default email notification groups
Purpose of this commit is to add potential groups but de-activate them by
default. Indeed each group require about 20 queries for rendering and
sending. If no specific behavior (access button, content) is made for this
recipient group it can be included in lower-version of the group.
Specifications
* de-activate portal group in mail as it has no additional rights compared
to customers;
* add follower group but de-activate it for the same reason;
* activate portal group in portal_mixin and include links to the record in
notification emails, using standard mail/view link. ACLs are managed in
each specific model, generally based on followers;
Update a test in test_mail as it was playing with public and portal users
that are now not really differentiated when sending notification emails.
Better have more real-life scenarios with portal and internal users.
Task-2739294 (Mail: Batch recipients fetch and improve its usage)
Part-of: odoo/odoo#82167
This commit is contained in:
@@ -2558,19 +2558,27 @@ class MailThread(models.AbstractModel):
|
||||
``_notify_get_recipients_classify`` method.
|
||||
"""
|
||||
return [
|
||||
(
|
||||
[
|
||||
'user',
|
||||
lambda pdata: pdata['type'] == 'user',
|
||||
{'has_button_access': True}
|
||||
), (
|
||||
], [
|
||||
'portal',
|
||||
lambda pdata: pdata['type'] == 'portal',
|
||||
{'has_button_access': False}
|
||||
), (
|
||||
{'active': False, # activate only on demand if rights are enabled
|
||||
'has_button_access': False,
|
||||
}
|
||||
], [
|
||||
'follower',
|
||||
lambda pdata: pdata['is_follower'],
|
||||
{'active': False, # activate only on demand if rights are enabled
|
||||
'has_button_access': False,
|
||||
}
|
||||
], [
|
||||
'customer',
|
||||
lambda pdata: True,
|
||||
{'has_button_access': False}
|
||||
)
|
||||
]
|
||||
]
|
||||
|
||||
def _notify_get_recipients_classify(self, recipient_data, model_name, msg_vals=None):
|
||||
@@ -2579,30 +2587,29 @@ class MailThread(models.AbstractModel):
|
||||
have access to buttons customers should not have in their emails.
|
||||
Module-specific grouping should be done by overriding ``_notify_get_recipients_groups``
|
||||
method defined here-under.
|
||||
:param recipient_data:todo xdo UPDATE ME
|
||||
return example:
|
||||
[{
|
||||
'actions': [],
|
||||
'button_access': {'title': 'View Simple Chatter Model',
|
||||
|
||||
:param recipient_data: list of recipients information (based on res.partner
|
||||
records). See ``MailThread._notify_get_recipients()``;
|
||||
|
||||
:return list: list of groups formatted for notification processing like
|
||||
[{'active': True,
|
||||
'actions': [],
|
||||
'button_access': {},
|
||||
'has_button_access': False,
|
||||
'recipients': [11],},
|
||||
{'active': True,
|
||||
'actions': [],
|
||||
'button_access': {'title': 'View Simple Chatter Model',
|
||||
'url': '/mail/view?model=mail.test.simple&res_id=1497'},
|
||||
'has_button_access': False,
|
||||
'recipients': [11]
|
||||
},
|
||||
{
|
||||
'actions': [],
|
||||
'button_access': {'title': 'View Simple Chatter Model',
|
||||
'url': '/mail/view?model=mail.test.simple&res_id=1497'},
|
||||
'has_button_access': False,
|
||||
'recipients': [4, 5, 6]
|
||||
},
|
||||
{
|
||||
'actions': [],
|
||||
'button_access': {'title': 'View Simple Chatter Model',
|
||||
'has_button_access': True,
|
||||
'recipients': [4, 5, 6],},
|
||||
{'active': True,
|
||||
'actions': [],
|
||||
'button_access': {'title': 'View Simple Chatter Model',
|
||||
'url': '/mail/view?model=mail.test.simple&res_id=1497'},
|
||||
'has_button_access': True,
|
||||
'recipients': [10, 11, 12]
|
||||
}]
|
||||
only return groups with recipients
|
||||
'has_button_access': True,
|
||||
'recipients': [10, 11, 12],}
|
||||
]
|
||||
"""
|
||||
# keep a local copy of msg_vals as it may be modified to include more information about groups or links
|
||||
local_msg_vals = dict(msg_vals) if msg_vals else {}
|
||||
@@ -2616,28 +2623,26 @@ class MailThread(models.AbstractModel):
|
||||
|
||||
# fill group_data with default_values if they are not complete
|
||||
for group_name, group_func, group_data in groups:
|
||||
group_data.setdefault('notification_group_name', group_name)
|
||||
group_data.setdefault('notification_is_customer', False)
|
||||
group_data.setdefault('active', True)
|
||||
group_data.setdefault('actions', list())
|
||||
group_data.setdefault('has_button_access', True)
|
||||
group_data.setdefault('notification_is_customer', False)
|
||||
group_data.setdefault('notification_group_name', group_name)
|
||||
group_data.setdefault('recipients', list())
|
||||
group_button_access = group_data.setdefault('button_access', {})
|
||||
group_button_access.setdefault('url', access_link)
|
||||
group_button_access.setdefault('title', view_title)
|
||||
group_data.setdefault('actions', list())
|
||||
group_data.setdefault('recipients', list())
|
||||
|
||||
# classify recipients in each group
|
||||
for recipient in recipient_data:
|
||||
for group_name, group_func, group_data in groups:
|
||||
if group_func(recipient):
|
||||
if group_data['active'] and group_func(recipient):
|
||||
group_data['recipients'].append(recipient['id'])
|
||||
break
|
||||
|
||||
result = []
|
||||
for group_name, _group_method, group_data in groups:
|
||||
if group_data['recipients']:
|
||||
result.append(group_data)
|
||||
|
||||
return result
|
||||
# filter out groups without recipients
|
||||
return [group_data for _group_name, _group_func, group_data in groups
|
||||
if group_data['recipients']]
|
||||
|
||||
@api.model
|
||||
def _notify_encode_link(self, base_link, params):
|
||||
|
||||
@@ -88,6 +88,13 @@ class PortalMixin(models.AbstractModel):
|
||||
]
|
||||
else:
|
||||
new_group = []
|
||||
|
||||
# enable portal users that should have access through portal (if not access rights
|
||||
# will do their duty)
|
||||
portal_group = next(group for group in groups if group[0] == 'portal')
|
||||
portal_group[2]['active'] = True
|
||||
portal_group[2]['has_button_access'] = True
|
||||
|
||||
return new_group + groups
|
||||
|
||||
def _get_access_action(self, access_uid=None, force_website=False):
|
||||
|
||||
@@ -16,7 +16,7 @@ class TestMailResend(TestMailCommon):
|
||||
cls.test_record = cls.env['mail.test.simple'].with_context(cls._test_context).create({'name': 'Test', 'email_from': 'ignasse@example.com'})
|
||||
|
||||
#Two users
|
||||
cls.user1 = mail_new_test_user(cls.env, login='e1', groups='base.group_public', name='Employee 1', notification_type='email', email='e1') # invalid email
|
||||
cls.user1 = mail_new_test_user(cls.env, login='e1', groups='base.group_user', name='Employee 1', notification_type='email', email='e1') # invalid email
|
||||
cls.user2 = mail_new_test_user(cls.env, login='e2', groups='base.group_portal', name='Employee 2', notification_type='email', email='e2@example.com')
|
||||
#Two partner
|
||||
cls.partner1 = cls.env['res.partner'].with_context(cls._test_context).create({
|
||||
|
||||
Reference in New Issue
Block a user