Skip to content

Commit

Permalink
[FIX] edi_webservice_oca: use sudo to get webserivce backend info
Browse files Browse the repository at this point in the history
queue.job task are running in the context with the user that create the edi exchage record
as those user are able to create exchange they should be able to read webservice backend
while sending data in order to etablish the connexion to send payloads
to the related webserivce.
  • Loading branch information
petrus-v committed Sep 7, 2023
1 parent 88750e5 commit 376f211
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion edi_webservice_oca/components/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EDIWebserviceSend(Component):
def __init__(self, work_context):
super().__init__(work_context)
self.ws_settings = getattr(work_context, "webservice", {})
self.webservice_backend = self.backend.webservice_backend_id
self.webservice_backend = self.backend.webservice_backend_id.sudo()

def send(self):
method, pargs, kwargs = self._get_call_params()
Expand Down
2 changes: 1 addition & 1 deletion edi_webservice_oca/models/edi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _component_match_attrs(self, exchange_record, key):
res = super()._component_match_attrs(exchange_record, key)
if not self.webservice_backend_id or key not in self._webservice_actions:
return res
res["webservice_protocol"] = self.webservice_backend_id.protocol
res["webservice_protocol"] = self.webservice_backend_id.sudo().protocol
return res

def _component_sort_key(self, component_class):
Expand Down
31 changes: 31 additions & 0 deletions edi_webservice_oca/tests/test_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ def _setup_records(cls):
endpoint: push/here
"""
cls.record.type_id.set_settings(cls.settings1)
cls.a_user = cls.env["res.users"].create(
{
"name": "foo",
"login": "a_user",
"email": "[email protected]",
"groups_id": [
(
6,
0,
(cls.env.ref("base.group_user")).ids,
)
],
}
)

def test_find_component(self):
component = self.backend._get_component(self.record, "send")
Expand Down Expand Up @@ -88,3 +102,20 @@ def test_component_send(self):
responses.calls[0].request.headers["Content-Type"], "application/xml"
)
self.assertEqual(responses.calls[0].request.body, "This is a simple file")

@responses.activate
def test_compenent_send_by_end_user(self):

self.record.type_id.set_settings(self.settings2)
self.record = self.record.with_user(self.a_user)
self.backend = self.backend.with_user(self.a_user)

url = "https://foo.test/push/here"
responses.add(responses.POST, url, body="{}")
component = self.backend._get_component(self.record, "send")
result = component.send()
self.assertEqual(result, b"{}")
self.assertEqual(
responses.calls[0].request.headers["Content-Type"], "application/xml"
)
self.assertEqual(responses.calls[0].request.body, "This is a simple file")

0 comments on commit 376f211

Please sign in to comment.