The goal of this revision is to add a group `mail.group_mail_notification_type_inbox` which is granted automatically when the user `notification_type` is set to `Inbox` to be able to easily hide the filter `Unread messages` when the user uses the `Email` notification type, by simply adding `groups="mail.group_mail_notification_type_inbox"` on the filter rather than overriding `_get_view` in every model. The code overriding `_get_view` of `project.task` to hide the filter "Unread messages" replaced in this revision initially comes from odoo/odoo@da868d28e2 > - In project.task search View: > - the filter for unread messages should be visible only if the current user > managing his notifications in Odoo The above revision was part of the task 2844212 closes odoo/odoo#104328 Related: odoo/enterprise#33338 Related: odoo/upgrade#3996 Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from psycopg2 import IntegrityError
|
|
|
|
from odoo import Command
|
|
from odoo.addons.mail.tests.common import MailCommon, mail_new_test_user
|
|
from odoo.tools import mute_logger
|
|
|
|
|
|
class TestUser(MailCommon):
|
|
|
|
@mute_logger('odoo.sql_db')
|
|
def test_notification_type_constraint(self):
|
|
with self.assertRaises(IntegrityError, msg='Portal user can not receive notification in Odoo'):
|
|
mail_new_test_user(
|
|
self.env,
|
|
login='user_test_constraint_2',
|
|
name='Test User 2',
|
|
email='user_test_constraint_2@test.example.com',
|
|
notification_type='inbox',
|
|
groups='base.group_portal',
|
|
)
|
|
|
|
def test_notification_type_convert_internal_inbox_to_portal(self):
|
|
"""Tests an internal user using inbox notifications converted to portal
|
|
is automatically set to email notifications"""
|
|
user = mail_new_test_user(
|
|
self.env,
|
|
login='user_test_constraint_3',
|
|
name='Test User 3',
|
|
email='user_test_constraint_3@test.example.com',
|
|
notification_type='inbox',
|
|
groups='base.group_user',
|
|
)
|
|
|
|
# Ensure the internal user has well the inbox notification type
|
|
self.assertEqual(user.notification_type, 'inbox')
|
|
self.assertIn(self.env.ref('mail.group_mail_notification_type_inbox'), user.groups_id)
|
|
|
|
# Change the internal user to portal, and make sure it automatically converts from inbox to email notifications
|
|
user.write({'groups_id': [
|
|
Command.unlink(self.env.ref('base.group_user').id),
|
|
Command.link(self.env.ref('base.group_portal').id),
|
|
]})
|
|
self.assertEqual(user.notification_type, 'email')
|
|
self.assertNotIn(self.env.ref('mail.group_mail_notification_type_inbox'), user.groups_id)
|