summaryrefslogtreecommitdiff
path: root/addons/project/tests
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2018-03-02 17:48:32 +0100
committerThibault Delavallée <tde@odoo.com>2018-04-03 17:11:43 +0200
commitb6d2351df45bdd049e42e828743b5dd2f1941649 (patch)
tree40fb6f3b0f515ab538fa9f5a1a1fc7754f758e1e /addons/project/tests
parent301f140cb6c872e3f4303f6ce46c626d3f04fa2f (diff)
[REF] mail: improve implementation of message subscribe
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.
Diffstat (limited to 'addons/project/tests')
-rw-r--r--addons/project/tests/test_access_rights.py4
-rw-r--r--addons/project/tests/test_portal.py10
2 files changed, 7 insertions, 7 deletions
diff --git a/addons/project/tests/test_access_rights.py b/addons/project/tests/test_access_rights.py
index 0016a71f71f..fe184147492 100644
--- a/addons/project/tests/test_access_rights.py
+++ b/addons/project/tests/test_access_rights.py
@@ -79,7 +79,7 @@ class TestPortalProject(TestPortalProjectBase):
# Do: Donovan reads project -> ko (public ko employee)
self.assertRaises(AccessError, pigs.sudo(self.user_public).read, ['user_id'])
- pigs.message_subscribe_users(user_ids=[self.user_projectuser.id])
+ pigs.message_subscribe(partner_ids=[self.user_projectuser.partner_id.id])
# Do: Alfred reads project -> ok (follower ok followers)
prout = pigs.sudo(self.user_projectuser)
@@ -93,7 +93,7 @@ class TestPortalProject(TestPortalProjectBase):
'name': 'Pigs task', 'project_id': pigs.id
})
# not follower user should not be able to create a task
- pigs.sudo(self.user_projectuser).message_unsubscribe_users(user_ids=[self.user_projectuser.id])
+ pigs.sudo(self.user_projectuser).message_unsubscribe(partner_ids=[self.user_projectuser.partner_id.id])
self.assertRaises(AccessError, self.env['project.task'].sudo(self.user_projectuser).with_context({
'mail_create_nolog': True}).create, {'name': 'Pigs task', 'project_id': pigs.id})
diff --git a/addons/project/tests/test_portal.py b/addons/project/tests/test_portal.py
index 6413488da2e..ba18b5a5a16 100644
--- a/addons/project/tests/test_portal.py
+++ b/addons/project/tests/test_portal.py
@@ -25,9 +25,9 @@ class TestPortalProject(TestPortalProjectBase):
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_users(user_ids=[self.user_portal.id])
- self.task_1.sudo(self.user_projectuser).message_subscribe_users(user_ids=[self.user_portal.id])
- self.task_3.sudo(self.user_projectuser).message_subscribe_users(user_ids=[self.user_portal.id])
+ 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)
@@ -35,5 +35,5 @@ class TestPortalProject(TestPortalProjectBase):
# 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_users(user_ids=[self.user_portal.id])
- self.task_3.sudo(self.user_projectuser).message_unsubscribe_users(user_ids=[self.user_portal.id])
+ 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])