[IMP] test_mail: add a test about inactive user creating records

Currently an inactive user that creates records is added in followers. Standard
use case is the mailgateway but it has the 'mail_create_nosubscribe' context
key that avoids the mailgateway user to be added in followers automatically.

A test is added without the context key that shows that inactive users are
added as follower when creating a record. This is due to the direct call
to '_insert_followers' that does not perform any filtering on inactive users.

Task-3046371 (Mail: Better Language Support in Composer)

Part-of: odoo/odoo#113522
This commit is contained in:
Thibault Delavallée
2023-02-23 18:28:59 +01:00
parent b915617569
commit 3fea6d05fa
+15 -2
View File
@@ -3,8 +3,8 @@
from odoo.addons.test_mail.tests.common import TestMailCommon
from odoo.exceptions import AccessError
from odoo.tests import tagged
from odoo.tests import users
from odoo.tests import tagged, users
from odoo.tools import mute_logger
@tagged('mail_followers')
@@ -145,6 +145,7 @@ class BaseFollowersTest(TestMailCommon):
self.assertEqual(document.message_follower_ids.partner_id, self.partner_portal | customer)
@users('employee')
@mute_logger('odoo.models.unlink')
def test_followers_inverse_message_partner(self):
test_record = self.test_record.with_env(self.env)
partner0, partner1, partner2, partner3 = self.env['res.partner'].create(
@@ -183,6 +184,7 @@ class BaseFollowersTest(TestMailCommon):
test_record.write({'message_partner_ids': [(4, partner0.id), (4, partner1.id)]})
self.assertEqual(test_record.message_follower_ids.partner_id, partner1)
@mute_logger('odoo.addons.base.models.ir_model', 'odoo.models')
def test_followers_inverse_message_partner_access_rights(self):
""" Make sure we're not bypassing security checks by setting a partner
instead of a follower """
@@ -301,6 +303,7 @@ class AdvancedFollowersTest(TestMailCommon):
""" Creator of records are automatically added as followers """
self.assertEqual(self.test_track.message_partner_ids, self.user_employee.partner_id)
@mute_logger('odoo.models.unlink')
def test_auto_subscribe_inactive(self):
""" Test inactive are not added as followers in automated subscription """
self.test_track.user_id = False
@@ -317,6 +320,14 @@ class AdvancedFollowersTest(TestMailCommon):
self.assertEqual(self.test_track.message_partner_ids, self.user_employee.partner_id)
self.assertEqual(self.test_track.message_follower_ids.partner_id, self.user_employee.partner_id)
new_record = self.env['mail.test.track'].with_user(self.user_admin).create({
'name': 'Test',
})
self.assertFalse(new_record.message_partner_ids,
'Filters out inactive partners')
self.assertEqual(new_record.message_follower_ids.partner_id, self.partner_admin,
'TODO: should not subscribe inactive partner')
def test_auto_subscribe_post(self):
""" People posting a message are automatically added as followers """
self.test_track.with_user(self.user_admin).message_post(body='Coucou hibou', message_type='comment')
@@ -340,6 +351,7 @@ class AdvancedFollowersTest(TestMailCommon):
})
self.assertEqual(sub.message_partner_ids, (self.user_employee.partner_id | self.user_admin.partner_id))
@mute_logger('odoo.models.unlink')
def test_auto_subscribe_defaults(self):
""" Test auto subscription based on an container record. This mimics
the behavior of addons like project and task where subscribing to
@@ -573,6 +585,7 @@ class RecipientsNotificationTest(TestMailCommon):
partner_to_users={self.common_partner.id: self.user_2})
@users('employee')
@mute_logger('odoo.models.unlink')
def test_notification_unlink(self):
""" Check that we unlink the created user_notification after unlinked the
related document. """