From c1c90e455516ad4ef591bda8cc8523c07d2a911b Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Mon, 9 Oct 2023 10:08:15 +0200 Subject: [PATCH 1/4] [FIX] fs_attachment: No db rules for storages not used as default for attachement --- fs_attachment/models/fs_storage.py | 6 +++++- fs_attachment/readme/newsfragments/.gitignore | 0 fs_attachment/readme/newsfragments/286.bugfix | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 fs_attachment/readme/newsfragments/.gitignore create mode 100644 fs_attachment/readme/newsfragments/286.bugfix diff --git a/fs_attachment/models/fs_storage.py b/fs_attachment/models/fs_storage.py index d1bf83258c..1afe16fe92 100644 --- a/fs_attachment/models/fs_storage.py +++ b/fs_attachment/models/fs_storage.py @@ -348,7 +348,11 @@ def get_force_db_for_default_attachment_rules(self, code): 0 means no limit. """ storage = self.get_by_code(code) - if storage and storage.force_db_for_default_attachment_rules: + if ( + storage + and storage.use_as_default_for_attachments + and storage.force_db_for_default_attachment_rules + ): return const_eval(storage.force_db_for_default_attachment_rules) return {} diff --git a/fs_attachment/readme/newsfragments/.gitignore b/fs_attachment/readme/newsfragments/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/fs_attachment/readme/newsfragments/286.bugfix b/fs_attachment/readme/newsfragments/286.bugfix new file mode 100644 index 0000000000..936f148ae1 --- /dev/null +++ b/fs_attachment/readme/newsfragments/286.bugfix @@ -0,0 +1,2 @@ +If a storage is not used to store all the attachments by default, the call to the +`get_force_db_for_default_attachment_rules` method must return an empty dictionary. From 836d719e9f85457ee709fbf9d1572127c5fd2283 Mon Sep 17 00:00:00 2001 From: Wolfgang Pichler Date: Thu, 5 Oct 2023 15:19:17 +0200 Subject: [PATCH 2/4] [FIX] Added future import annotations to be python 3.9 compatible --- fs_attachment/models/fs_storage.py | 2 ++ fs_attachment/models/ir_attachment.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/fs_attachment/models/fs_storage.py b/fs_attachment/models/fs_storage.py index 1afe16fe92..2554c1001c 100644 --- a/fs_attachment/models/fs_storage.py +++ b/fs_attachment/models/fs_storage.py @@ -1,6 +1,8 @@ # Copyright 2023 ACSONE SA/NV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from __future__ import annotations + from odoo import _, api, fields, models, tools from odoo.exceptions import ValidationError from odoo.tools.safe_eval import const_eval diff --git a/fs_attachment/models/ir_attachment.py b/fs_attachment/models/ir_attachment.py index fd4a2a0e48..8b34a6b9c3 100644 --- a/fs_attachment/models/ir_attachment.py +++ b/fs_attachment/models/ir_attachment.py @@ -2,6 +2,8 @@ # Copyright 2023 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +from __future__ import annotations + import io import logging import mimetypes From ef68e0df9145c3f5e89445e8b803e5ac64edc014 Mon Sep 17 00:00:00 2001 From: Wolfgang Pichler Date: Thu, 5 Oct 2023 15:24:48 +0200 Subject: [PATCH 3/4] [FIX] Small fix to reformat the auth option as tuple for protocol webdav. It is not possible to specify a tuple in json --- fs_storage/models/fs_storage.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs_storage/models/fs_storage.py b/fs_storage/models/fs_storage.py index 5bcc5f3e5e..b1886b7f77 100644 --- a/fs_storage/models/fs_storage.py +++ b/fs_storage/models/fs_storage.py @@ -314,6 +314,13 @@ def _get_filesystem(self) -> fsspec.AbstractFileSystem: options = self.json_options if self.protocol == "odoofs": options["odoo_storage_path"] = self._odoo_storage_path + # Webdav protocol handler does need the auth to be a tuple not a list ! + if ( + self.protocol == "webdav" + and "auth" in options + and isinstance(options["auth"], list) + ): + options["auth"] = tuple(options["auth"]) options = self._recursive_add_odoo_storage_path(options) fs = fsspec.filesystem(self.protocol, **options) directory_path = self.directory_path From f4d2fe6c0d36b429762b1286200cba303292a5fc Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Mon, 9 Oct 2023 10:28:41 +0200 Subject: [PATCH 4/4] [IMP] fs_attachment: Add history Add history for commit included from https://github.com/OCA/storage/pull/285 and the author to the contributors list --- fs_attachment/readme/CONTRIBUTORS.rst | 1 + fs_attachment/readme/newsfragments/285.bugfix | 1 + fs_storage/readme/newsfragments/.gitignore | 0 fs_storage/readme/newsfragments/285.bugfix | 4 ++++ 4 files changed, 6 insertions(+) create mode 100644 fs_attachment/readme/newsfragments/285.bugfix create mode 100644 fs_storage/readme/newsfragments/.gitignore create mode 100644 fs_storage/readme/newsfragments/285.bugfix diff --git a/fs_attachment/readme/CONTRIBUTORS.rst b/fs_attachment/readme/CONTRIBUTORS.rst index b06e37ea72..886c390695 100644 --- a/fs_attachment/readme/CONTRIBUTORS.rst +++ b/fs_attachment/readme/CONTRIBUTORS.rst @@ -10,3 +10,4 @@ Don Kendall Stephane Mangin Laurent Mignon Marie Lejeune +Wolfgang Pichler diff --git a/fs_attachment/readme/newsfragments/285.bugfix b/fs_attachment/readme/newsfragments/285.bugfix new file mode 100644 index 0000000000..ad218e3faa --- /dev/null +++ b/fs_attachment/readme/newsfragments/285.bugfix @@ -0,0 +1 @@ +Ensures python 3.9 compatibility. diff --git a/fs_storage/readme/newsfragments/.gitignore b/fs_storage/readme/newsfragments/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/fs_storage/readme/newsfragments/285.bugfix b/fs_storage/readme/newsfragments/285.bugfix new file mode 100644 index 0000000000..75a7e27c5a --- /dev/null +++ b/fs_storage/readme/newsfragments/285.bugfix @@ -0,0 +1,4 @@ +Avoid config error when using the webdav protocol. The auth option is expected +to be a tuple not a list. Since our config is loaded from a json file, we +cannot use tuples. The fix converts the list to a tuple when the config is +related to a webdav protocol and the auth option is into the confix.