forked from Techsystech/web
[FIX] web_access_rule_buttons: Fix tests
parent
4528d457fe
commit
4c0b7ebb9e
|
@ -22,19 +22,16 @@ class Base(models.AbstractModel):
|
||||||
operations = ["read", "create", "write", "unlink"]
|
operations = ["read", "create", "write", "unlink"]
|
||||||
result = {}
|
result = {}
|
||||||
for operation in operations:
|
for operation in operations:
|
||||||
try:
|
if self.is_transient() or not self.ids:
|
||||||
self.check_access_rule(operation)
|
|
||||||
except exceptions.AccessError:
|
|
||||||
result[operation] = False
|
|
||||||
if (
|
|
||||||
self.is_transient()
|
|
||||||
or self.ids
|
|
||||||
and self.env.user.has_group("base.user_admin")
|
|
||||||
):
|
|
||||||
# If we call check_access_rule() without id, it will try to
|
# If we call check_access_rule() without id, it will try to
|
||||||
# run a SELECT without ID which will crash, so we just blindly
|
# run a SELECT without ID which will crash, so we just blindly
|
||||||
# allow the operations
|
# allow the operations
|
||||||
result[operation] = True
|
result[operation] = True
|
||||||
else:
|
continue
|
||||||
|
try:
|
||||||
|
self.check_access_rule(operation)
|
||||||
|
except exceptions.AccessError:
|
||||||
result[operation] = False
|
result[operation] = False
|
||||||
|
else:
|
||||||
|
result[operation] = True
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -1,25 +1,38 @@
|
||||||
# Copyright 2019 Onestein BV
|
# Copyright 2019 Onestein BV
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests import common, new_test_user, users
|
||||||
|
|
||||||
|
|
||||||
class TestAccessRuleButtons(TransactionCase):
|
class TestAccessRuleButtons(common.TransactionCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestAccessRuleButtons, self).setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.curr_obj = self.env["res.currency"]
|
|
||||||
self.curr_record = self.env.ref("base.USD")
|
self.curr_record = self.env.ref("base.USD")
|
||||||
|
new_test_user(self.env, login="test-user", groups="base.group_system")
|
||||||
|
self.env.ref("base.user_admin").write(
|
||||||
|
{
|
||||||
|
"groups_id": [(4, self.env.ref("base.group_system").id)],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@users("admin", "test-user")
|
||||||
def test_check_access_rule_1(self):
|
def test_check_access_rule_1(self):
|
||||||
res = self.curr_obj.check_access_rule_all(["write"])
|
res = self.env["res.currency"].check_access_rule_all(["write"])
|
||||||
self.assertFalse(res["write"])
|
|
||||||
|
|
||||||
def test_check_access_rule_2(self):
|
|
||||||
res = self.curr_record.check_access_rule_all(["write"])
|
|
||||||
self.assertTrue(res["write"])
|
self.assertTrue(res["write"])
|
||||||
|
|
||||||
|
@users("admin", "test-user")
|
||||||
|
def test_check_access_rule_2(self):
|
||||||
|
res = (
|
||||||
|
self.env["res.currency"]
|
||||||
|
.browse(self.curr_record.id)
|
||||||
|
.check_access_rule_all(["write"])
|
||||||
|
)
|
||||||
|
self.assertTrue(res["write"])
|
||||||
|
|
||||||
|
@users("admin", "test-user")
|
||||||
def test_check_access_rule_3(self):
|
def test_check_access_rule_3(self):
|
||||||
res = self.curr_record.check_access_rule_all()
|
res = (
|
||||||
|
self.env["res.currency"].browse(self.curr_record.id).check_access_rule_all()
|
||||||
|
)
|
||||||
self.assertTrue(res["read"])
|
self.assertTrue(res["read"])
|
||||||
self.assertTrue(res["create"])
|
self.assertTrue(res["create"])
|
||||||
self.assertTrue(res["write"])
|
self.assertTrue(res["write"])
|
||||||
|
|
Loading…
Reference in New Issue