Browse Source

[FIX] partner_multi_relation: Avoid access error on Relations button

In Odoo v14, ir.actions.act_window have only access rights for admin while a user had read access in previous versions. Odoo provides now a function (_for_xml_id) that returns the action read with sudo.
14.0
Tobias Zehntner 3 years ago
parent
commit
39c72d119c
  1. 4
      partner_multi_relation/models/res_partner.py
  2. 1
      partner_multi_relation/tests/__init__.py
  3. 29
      partner_multi_relation/tests/test_partner_relation_action.py

4
partner_multi_relation/models/res_partner.py

@ -187,9 +187,9 @@ class ResPartner(models.Model):
("other_partner_id", "=", contact.id), ("other_partner_id", "=", contact.id),
] ]
) )
action = self.env.ref(
action = self.env["ir.actions.act_window"]._for_xml_id(
"partner_multi_relation.action_res_partner_relation_all" "partner_multi_relation.action_res_partner_relation_all"
).read()[0]
)
action["domain"] = [("id", "in", relation_ids.ids)] action["domain"] = [("id", "in", relation_ids.ids)]
context = action.get("context", "{}").strip()[1:-1] context = action.get("context", "{}").strip()[1:-1]
elements = context.split(",") if context else [] elements = context.split(",") if context else []

1
partner_multi_relation/tests/__init__.py

@ -1,5 +1,6 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import test_partner_relation_common from . import test_partner_relation_common
from . import test_partner_relation_action
from . import test_partner_relation from . import test_partner_relation
from . import test_partner_relation_all from . import test_partner_relation_all
from . import test_partner_search from . import test_partner_search

29
partner_multi_relation/tests/test_partner_relation_action.py

@ -0,0 +1,29 @@
# © 2021 Tobias Zehntner
# © 2021 Niboo SRL (https://www.niboo.com/)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import exceptions
from .test_partner_relation_common import TestPartnerRelationCommon
class TestPartnerRelationAction(TestPartnerRelationCommon):
def setUp(self):
super().setUp()
self.user = self.env["res.users"].create(
{
"login": "test_partner_action_user",
"name": "test_partner_action_user",
"groups_id": [
(4, self.env.ref("base.group_user").id),
],
}
)
def test_call_relation_action(self):
"""Test calling relations action. Should be possible with simple user rights"""
try:
self.partner_01_person.with_user(self.user).action_view_relations()
except exceptions.AccessError:
self.fail("action_view_relations() raised AccessError unexpectedly!")
Loading…
Cancel
Save