Skip to content

Commit

Permalink
[FIX] mail: reduce no sudo effect mark_all_as_read
Browse files Browse the repository at this point in the history
The "Mark all read" button either set all messages as read, or if a
domain is given, filter messages on it.

But this filtering is also dependent on not doing sudo so odd
notification to which we would somehow not have any access would never
disappear in the unread number.

Adding a sudo is risky, so this changeset just modify the test on domain
since in most instance the domain is just an empty list (so: []).

The added test before this change would fail at the last assert ("mark
all read should conclude all needactions even inacessible ones").

opw-805185
closes odoo#22277
  • Loading branch information
nle-odoo committed Jan 17, 2018
1 parent 23a2bac commit 80f1d9d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addons/mail/models/mail_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def mark_all_as_read(self, channel_ids=None, domain=None):
""" Remove all needactions of the current partner. If channel_ids is
given, restrict to messages written in one of those channels. """
partner_id = self.env.user.partner_id.id
if domain is None:
if not domain:
query = "DELETE FROM mail_message_res_partner_needaction_rel WHERE res_partner_id IN %s"
args = [(partner_id,)]
if channel_ids:
Expand Down
26 changes: 26 additions & 0 deletions addons/mail/tests/test_mail_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@ def test_needaction(self):
self.assertEqual(na_emp1_new, na_emp1_base + 1)
self.assertEqual(na_emp2_new, na_emp2_base)

@mute_logger('openerp.addons.mail.models.mail_mail')
def test_mark_all_as_read(self):
portal_partner = self.user_portal.partner_id.sudo(self.user_portal.id)

# mark all as read clear needactions
self.group_pigs.message_post(body='Test', message_type='comment', subtype='mail.mt_comment', partner_ids=[portal_partner.id])
portal_partner.env['mail.message'].mark_all_as_read(channel_ids=[], domain=[])
na_count = portal_partner.get_needaction_count()
self.assertEqual(na_count, 0, "mark all as read should conclude all needactions")

# mark all as read also clear inaccessible needactions
new_msg = self.group_pigs.message_post(body='Zest', message_type='comment', subtype='mail.mt_comment', partner_ids=[portal_partner.id])
needaction_accessible = len(portal_partner.env['mail.message'].search([['needaction', '=', True]]))
self.assertEqual(needaction_accessible, 1, "a new message to a partner is readable to that partner")

new_msg.sudo().partner_ids = self.env['res.partner']
needaction_length = len(portal_partner.env['mail.message'].search([['needaction', '=', True]]))
self.assertEqual(needaction_length, 0, "removing access of a message make it not readable")

na_count = portal_partner.get_needaction_count()
self.assertEqual(na_count, 1, "message not accessible is currently still counted")

portal_partner.env['mail.message'].mark_all_as_read(channel_ids=[], domain=[])
na_count = portal_partner.get_needaction_count()
self.assertEqual(na_count, 0, "mark all read should conclude all needactions even inacessible ones")


class TestMessagePost(TestMail):

Expand Down

0 comments on commit 80f1d9d

Please sign in to comment.