Files
odoo_source/addons/mail_group/tests/test_mail_group_message.py
T
std-odoo 322ed33d42 [IMP] mail_group: improve the UI and misc improvements
Purpose
=======
This commit improves the UI of the mail group module (backend and portal
view), fix some bugs and clean the code.

Bug 1
=====
If a user click 2 times on a confirmation link, an error is raised.

Bug 2
=====
A bug about the website snippets has been fixed;
- Add the snippet to a group in which you are member
- Change the group of the snippet to a group in which you are not member
- The snippet still show "Unsubscribe"

Bug 3
=====
In the portal view, when messages are filtered by month, messages which
are created in the last day of the month appear also in the next month.

Specification
=============
UI
--
Show the Allow / Ban buttons whatever is the state of the message, so
the user can ban / whitelist a message even if there's no pending email.

When we receive an email, remove the "Mailing List" footer. This was a
big issue because when some users reply many times, the footer was
duplicated on each answer.

Improve the form view of the mail group:
- On non-moderated group, show all messages instead of only pending
  message
- Show the guidelines stuff on non-moderated groups

Improve the portal view
- show the attachments under every message (not only on opened message)
- improve the template to confirm the subscription of the user
- improve the portal view for mobile device
- do not show rejected messages, even for admin
- do not show the button "X replies" when the mode is not thread

Technical
---------
Split the route "/groups/subscription" into "/group/subscribe" and
"/group/unsubscribe"

Correctly quote the parent email for the emails sent by web version of
Outlook (with the HTML id "divRplyFwdMsg").

ACLs
----
Now only administrators or responsible / moderators can write / unlink
the group.

Fix an ACL issue on the group member where the responsible of a
non-moderated group could not access the members of the group.

Members with same email
-----------------------

Improve the behavior when multiple members have the same email address
(this situation is possible because there's no unique constraint on the
email field of the <res.partner> model.) We now return the most
appropriate member for the given email address and partner.

When unsubscribing by clicking on the confirmation link that we received
by email, remove all members with the same email address.

Links
=====
Task-2599676
See odoo/odoo/pull/73640

closes odoo/odoo#73640

Related: odoo/upgrade#2774
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-09-01 19:07:48 +00:00

101 lines
5.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.mail_group.tests.common import TestMailListCommon
from odoo.addons.mail_group.tests.data import GROUP_TEMPLATE
from odoo.exceptions import AccessError
from odoo.tools import mute_logger
class TestMailGroupMessage(TestMailListCommon):
@mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.addons.mail_group.models.mail_group_message')
def test_email_duplicated(self):
""" Test gateway does not accept two times same incoming email """
self.test_group.write({'moderation': False})
with self.mock_mail_gateway():
self.format_and_process(
GROUP_TEMPLATE, self.email_from_unknown, self.test_group.alias_id.display_name,
subject='Test subject', msg_id='<test.message.id@localhost>', target_model='mail.group')
message = self.env['mail.group.message'].search([('mail_message_id.message_id', '=', '<test.message.id@localhost>')])
self.assertEqual(message.subject, 'Test subject', 'Should have created a <mail.group.message>')
with self.mock_mail_gateway():
self.format_and_process(
GROUP_TEMPLATE, self.email_from_unknown, self.test_group.alias_id.display_name,
subject='Another subject', msg_id='<test.message.id@localhost>', target_model='mail.group')
new_message = self.env['mail.group.message'].search([('mail_message_id.message_id', '=', '<test.message.id@localhost>')])
self.assertEqual(new_message, message)
@mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.addons.mail_group.models.mail_group_message')
def test_email_not_sent_to_author(self):
"""Test that when someone sends an email the group process does not send
it back to the original author."""
self.test_group.write({'moderation': False})
with self.mock_mail_gateway():
self.format_and_process(
GROUP_TEMPLATE, self.test_group_member_1.email,
self.test_group.alias_id.display_name,
subject='Test subject', target_model='mail.group')
mails = self.env['mail.mail'].search([('subject', '=', 'Test subject')])
self.assertEqual(len(mails), len(self.test_group.member_ids) - 1)
self.assertNotIn(self.test_group_member_1.email, mails.mapped('email_to'), 'Should not have send the email to the original author')
@mute_logger('odoo.addons.base.models.ir_rule')
def test_mail_group_message_security_groups(self):
user_group = self.env.ref('base.group_partner_manager')
self.test_group.access_group_id = user_group
self.test_group.access_mode = 'groups'
# Message pending
with self.assertRaises(AccessError, msg='Portal should not have access to pending messages'):
self.test_group_msg_1_pending.with_user(self.user_portal).check_access_rule('read')
self.user_portal.groups_id |= user_group
with self.assertRaises(AccessError, msg='Non moderator should have access to only accepted message'):
self.test_group_msg_1_pending.with_user(self.user_portal).check_access_rule('read')
self.test_group_msg_1_pending.invalidate_cache()
self.assertEqual(self.test_group_msg_1_pending.with_user(self.user_employee).moderation_status, 'pending_moderation',
msg='Moderators should have access to pending message')
# Message accepted
self.test_group_msg_2_accepted.invalidate_cache()
self.assertEqual(self.test_group_msg_2_accepted.with_user(self.user_portal).moderation_status, 'accepted',
msg='Portal should have access to accepted messages')
self.user_portal.groups_id -= user_group
with self.assertRaises(AccessError, msg='User not in the group should not have access to accepted message'):
self.test_group_msg_2_accepted.with_user(self.user_portal).check_access_rule('read')
@mute_logger('odoo.addons.base.models.ir_rule')
def test_mail_group_message_security_public(self):
self.test_group.access_mode = 'public'
# Message pending
with self.assertRaises(AccessError, msg='Portal should not have access to pending messages'):
self.test_group_msg_1_pending.with_user(self.user_portal).check_access_rule('read')
with self.assertRaises(AccessError, msg='Non moderator should have access to only accepted message'):
self.test_group_msg_1_pending.with_user(self.user_employee_2).check_access_rule('read')
self.test_group_msg_1_pending.invalidate_cache()
self.assertEqual(self.test_group_msg_1_pending.with_user(self.user_employee).moderation_status, 'pending_moderation',
msg='Moderators should have access to pending message')
# Message rejected
with self.assertRaises(AccessError, msg='Portal should not have access to pending messages'):
self.test_group_msg_1_pending.with_user(self.user_portal).check_access_rule('read')
# Message accepted
self.assertEqual(self.test_group_msg_2_accepted.with_user(self.user_portal).moderation_status, 'accepted',
msg='Portal should have access to accepted messages')
self.test_group_msg_3_rejected.invalidate_cache()
self.assertEqual(self.test_group_msg_1_pending.with_user(self.user_admin).moderation_status, 'pending_moderation',
msg='Mail Group Administrator should have access to all messages')