[FIX] base_suspend_security: Pretend to be a list of ints if neccessary

This commit is contained in:
Holger Brunn
2021-02-12 09:35:46 +01:00
parent e27ebb144c
commit f70b2f5ede
2 changed files with 30 additions and 0 deletions

View File

@@ -14,3 +14,16 @@ class BaseSuspendSecurityUid(int):
def __iter__(self):
yield super(BaseSuspendSecurityUid, self).__int__()
def __len__(self):
return 1
def __getitem__(self, key):
int_value = super().__int__()
if isinstance(key, slice):
if key.start > 0:
return ()
return (int_value,)
if key != 0:
raise IndexError
return int_value

View File

@@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import exceptions
from odoo.tests.common import TransactionCase
from ..base_suspend_security import BaseSuspendSecurityUid
class TestBaseSuspendSecurity(TransactionCase):
@@ -31,6 +32,15 @@ class TestBaseSuspendSecurity(TransactionCase):
self.env['res.users'].browse(
self.env['res.users'].suspend_security().env.uid)
def test_base_suspend_security_uid(self):
""" Test corner cases of dunder functions """
uid = BaseSuspendSecurityUid(42)
self.assertFalse(uid == 42)
self.assertEqual(uid[0], 42)
self.assertFalse(uid[1:])
with self.assertRaises(IndexError):
self.env['res.users'].browse(uid[1])
def test_suspend_security_on_search(self):
user_without_access = self.env["res.users"].create(
dict(
@@ -46,3 +56,10 @@ class TestBaseSuspendSecurity(TransactionCase):
model.sudo(user_without_access).search([])
# this tests the search
model.sudo(user_without_access).suspend_security().search([])
# be sure we can search suspended uids like ints
partners = self.env['res.partner'].with_context(
active_test=False,
).search([
('user_ids', '=', user_without_access.suspend_security().env.uid),
])
self.assertTrue(partners)