This commit refactors mail.thread message_subscribe method. It is done for two purposes. First one is to optimize performance by using the new followers computation methods introduced recently. Second purpose is to clean the API of message_subscribe to make it simpler to use. This commit splits message_subscribe in two main parts : * _message_subscribe is a private method calling the follower new subscription methods and updating the record set; * message_subscribe is a public wrapper on _message_subscribe that adds access rights checks; Simplification comes by removing message_subscribe_users that was a shortcut to message_subscribe. Having a method to subscribe partners and channels is sufficient as we would like to avoid bloating the public API of mail.thread. A force parameter is also removed from message_subscribe as this implementation detail can be induced in the computation. Various addons using the removed methods are updated in order to use the new subscription API. They have the same functional behavior. This commit has a great impact when subscribing several followers. In a more general way all code using message_post is also optimized as posting a message generally implies subscribing followers. It also improves activity use as posting a message and subscribing new followers are common process in activities.
40 lines
2.3 KiB
Python
40 lines
2.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.addons.project.tests.test_access_rights import TestPortalProjectBase
|
|
from odoo.exceptions import AccessError
|
|
from odoo.tools import mute_logger
|
|
|
|
|
|
class TestPortalProject(TestPortalProjectBase):
|
|
@mute_logger('odoo.addons.base.models.ir_model')
|
|
def test_portal_project_access_rights(self):
|
|
pigs = self.project_pigs
|
|
pigs.write({'privacy_visibility': 'portal'})
|
|
|
|
# Do: Alfred reads project -> ok (employee ok public)
|
|
pigs.sudo(self.user_projectuser).read(['user_id'])
|
|
# Test: all project tasks visible
|
|
tasks = self.env['project.task'].sudo(self.user_projectuser).search([('project_id', '=', pigs.id)])
|
|
self.assertEqual(tasks, self.task_1 | self.task_2 | self.task_3 | self.task_4 | self.task_5 | self.task_6,
|
|
'access rights: project user should see all tasks of a portal project')
|
|
|
|
# Do: Bert reads project -> crash, no group
|
|
self.assertRaises(AccessError, pigs.sudo(self.user_noone).read, ['user_id'])
|
|
# Test: no project task searchable
|
|
self.assertRaises(AccessError, self.env['project.task'].sudo(self.user_noone).search, [('project_id', '=', pigs.id)])
|
|
|
|
# Data: task follower
|
|
pigs.sudo(self.user_projectmanager).message_subscribe(partner_ids=[self.user_portal.partner_id.id])
|
|
self.task_1.sudo(self.user_projectuser).message_subscribe(partner_ids=[self.user_portal.partner_id.id])
|
|
self.task_3.sudo(self.user_projectuser).message_subscribe(partner_ids=[self.user_portal.partner_id.id])
|
|
# Do: Chell reads project -> ok (portal ok public)
|
|
pigs.sudo(self.user_portal).read(['user_id'])
|
|
# Do: Donovan reads project -> ko (public ko portal)
|
|
self.assertRaises(AccessError, pigs.sudo(self.user_public).read, ['user_id'])
|
|
# Test: no access right to project.task
|
|
self.assertRaises(AccessError, self.env['project.task'].sudo(self.user_public).search, [])
|
|
# Data: task follower cleaning
|
|
self.task_1.sudo(self.user_projectuser).message_unsubscribe(partner_ids=[self.user_portal.partner_id.id])
|
|
self.task_3.sudo(self.user_projectuser).message_unsubscribe(partner_ids=[self.user_portal.partner_id.id])
|