From 0a4249ccbce6ed9b387a966732607a28230bbaee Mon Sep 17 00:00:00 2001 From: Luc De Meyer Date: Sat, 5 Aug 2023 18:04:37 +0200 Subject: [PATCH] [IMP] remove storage of ebics_files in EBICS Files Root directory --- account_ebics/models/ebics_config.py | 19 -------------- account_ebics/models/ebics_userid.py | 2 -- account_ebics/views/ebics_config_views.xml | 1 - account_ebics/wizards/ebics_admin_order.py | 1 - account_ebics/wizards/ebics_xfer.py | 30 +--------------------- 5 files changed, 1 insertion(+), 52 deletions(-) diff --git a/account_ebics/models/ebics_config.py b/account_ebics/models/ebics_config.py index d84eb25..a7b6fe5 100644 --- a/account_ebics/models/ebics_config.py +++ b/account_ebics/models/ebics_config.py @@ -91,14 +91,6 @@ class EbicsConfig(models.Model): "between customer and financial institution. " "The human user also can authorise orders.", ) - ebics_files = fields.Char( - string="EBICS Files Root", - required=True, - readonly=True, - states={"draft": [("readonly", False)]}, - default=lambda self: self._default_ebics_files(), - help="Root Directory for EBICS File Transfer Folders.", - ) # We store the EBICS keys in a separate directory in the file system. # This directory requires special protection to reduce fraude. ebics_keys = fields.Char( @@ -253,14 +245,3 @@ class EbicsConfig(models.Model): ) % dirname ) - - def _check_ebics_files(self): - dirname = self.ebics_files or "" - if not os.path.exists(dirname): - raise UserError( - _( - "EBICS Files Root Directory %s is not available." - "\nPlease contact your system administrator." - ) - % dirname - ) diff --git a/account_ebics/models/ebics_userid.py b/account_ebics/models/ebics_userid.py index 2e1cfb3..9fdd034 100644 --- a/account_ebics/models/ebics_userid.py +++ b/account_ebics/models/ebics_userid.py @@ -255,7 +255,6 @@ class EbicsUserID(models.Model): Create new keys and certificates for this user """ self.ensure_one() - self.ebics_config_id._check_ebics_files() if self.state != "draft": raise UserError( _("Set state to 'draft' before Bank Key (re)initialisation.") @@ -442,7 +441,6 @@ class EbicsUserID(models.Model): must be downloaded and checked for consistency. """ self.ensure_one() - self.ebics_config_id._check_ebics_files() if self.state != "get_bank_keys": raise UserError(_("Set state to 'Get Keys from Bank'.")) try: diff --git a/account_ebics/views/ebics_config_views.xml b/account_ebics/views/ebics_config_views.xml index f7220d9..15735fe 100644 --- a/account_ebics/views/ebics_config_views.xml +++ b/account_ebics/views/ebics_config_views.xml @@ -52,7 +52,6 @@ - diff --git a/account_ebics/wizards/ebics_admin_order.py b/account_ebics/wizards/ebics_admin_order.py index 3f28d0e..d0ffedf 100644 --- a/account_ebics/wizards/ebics_admin_order.py +++ b/account_ebics/wizards/ebics_admin_order.py @@ -27,7 +27,6 @@ class EbicsAdminOrder(models.TransientModel): def ebics_admin_order(self): self.ensure_one() - self.ebics_config_id._check_ebics_files() client = self._setup_client() if not client: self.note += ( diff --git a/account_ebics/wizards/ebics_xfer.py b/account_ebics/wizards/ebics_xfer.py index 44a5504..f5a9f6b 100644 --- a/account_ebics/wizards/ebics_xfer.py +++ b/account_ebics/wizards/ebics_xfer.py @@ -10,7 +10,6 @@ logging.basicConfig( import base64 import logging -import os from sys import exc_info from traceback import format_exception @@ -193,7 +192,6 @@ class EbicsXfer(models.TransientModel): def ebics_download(self): self.ensure_one() - self.ebics_config_id._check_ebics_files() ctx = self.env.context.copy() self.note = "" err_cnt = 0 @@ -532,43 +530,17 @@ class EbicsXfer(models.TransientModel): return ebics_files def _create_ebics_file(self, data, file_format, docname=None): - """ - Write the data as received over the EBICS connection - to a temporary file so that is is available for - analysis (e.g. in case formats are received that cannot - be handled in the current version of this module). - - TODO: add code to clean-up /tmp on a regular basis. - - After saving the data received we call the method to perform - file format specific processing. - """ - ebics_files_root = self.ebics_config_id.ebics_files - tmp_dir = os.path.normpath(ebics_files_root + "/tmp") - if not os.path.isdir(tmp_dir): - os.makedirs(tmp_dir, mode=0o700) fn_parts = [self.ebics_config_id.ebics_host, self.ebics_config_id.ebics_partner] if docname: fn_parts.append(docname) else: fn_date = self.date_to or fields.Date.today() fn_parts.append(fn_date.isoformat()) - base_fn = "_".join(fn_parts) - n = 1 - full_tmp_fn = os.path.normpath(tmp_dir + "/" + base_fn) - while os.path.exists(full_tmp_fn): - n += 1 - tmp_fn = base_fn + "_" + str(n).rjust(3, "0") - full_tmp_fn = os.path.normpath(tmp_dir + "/" + tmp_fn) - - with open(full_tmp_fn, "wb") as f: - f.write(data) - + fn = "_".join(fn_parts) ff_methods = self._file_format_methods() if file_format.name in ff_methods: data = ff_methods[file_format.name](data) - fn = base_fn suffix = file_format.suffix if suffix and not fn.endswith(suffix): fn = ".".join([fn, suffix])