Skip to content

Commit a69182f

Browse files
tuantrantgthienvh332
authored andcommitted
[IMP] edi_storage_oca: Fix permission
Enable any internal user to trigger creation of EDI records without EDI Manager group nor read access to storage.backend
1 parent 88ee7e3 commit a69182f

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

edi_storage_oca/components/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def _get_remote_file(self, state, filename=None, binary=False):
7979
# TODO: support match via pattern (eg: filename-prefix-*)
8080
# otherwise is impossible to retrieve input files and acks
8181
# (the date will never match)
82-
return self.storage.get(path.as_posix(), binary=binary)
82+
return self.storage.sudo().get(path.as_posix(), binary=binary)
8383
except FileNotFoundError:
8484
_logger.info(
8585
"Ignored FileNotFoundError when trying "

edi_storage_oca/components/receive.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ class EDIStorageReceiveComponent(Component):
1515

1616
def receive(self):
1717
path = self._get_remote_file_path("pending")
18-
filedata = self.storage.get(path.as_posix())
18+
filedata = self.storage.get(path.as_posix(), binary=True)
1919
return filedata

edi_storage_oca/components/send.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def send(self):
2525
return True
2626
filedata = self.exchange_record.exchange_file
2727
path = self._get_remote_file_path("pending")
28-
self.storage.add(path.as_posix(), filedata, binary=False)
28+
self.storage.sudo().add(path.as_posix(), filedata, binary=False)
2929
# TODO: delegate this to generic storage backend
3030
# except paramiko.ssh_exception.AuthenticationException:
3131
# # TODO this exc handling should be moved to sftp backend IMO

edi_storage_oca/models/edi_backend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def _component_match_attrs(self, exchange_record, key):
7272
res = super()._component_match_attrs(exchange_record, key)
7373
if not self.storage_id or key not in self._storage_actions:
7474
return res
75-
res["storage_backend_type"] = self.storage_id.backend_type
75+
res["storage_backend_type"] = self.sudo().storage_id.backend_type
7676
return res
7777

7878
def _component_sort_key(self, component_class):

edi_storage_oca/tests/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ def _mocked_backend_list_files(self, mocked_paths, path, **kwargs):
106106

107107
def _mock_storage_backend_get(self, mocked_paths):
108108
mocked = functools.partial(self._mocked_backend_get, mocked_paths)
109-
return mock.patch(STORAGE_BACKEND_MOCK_PATH + "._get_b64_data", mocked)
109+
return mock.patch(STORAGE_BACKEND_MOCK_PATH + ".get", mocked)
110110

111111
def _mock_storage_backend_add(self):
112112
return mock.patch(
113-
STORAGE_BACKEND_MOCK_PATH + "._add_b64_data", self._mocked_backend_add
113+
STORAGE_BACKEND_MOCK_PATH + ".add", self._mocked_backend_add
114114
)
115115

116116
def _mock_storage_backend_list_files(self, mocked_paths):

edi_storage_oca/tests/test_components_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_remote_file_path(self):
3030
self.checker_input._get_remote_file_path("WHATEVER", "foo.csv")
3131

3232
def test_get_remote_file(self):
33-
with mock.patch(STORAGE_BACKEND_MOCK_PATH + "._get_b64_data") as mocked:
33+
with mock.patch(STORAGE_BACKEND_MOCK_PATH + ".get") as mocked:
3434
self.checker._get_remote_file("pending")
3535
mocked.assert_called_with(
3636
"demo_out/pending/{}".format(self._filename(self.record)), binary=False

0 commit comments

Comments
 (0)