Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^fs_file/|
^fs_folder/|
^fs_folder_demo/|
^fs_folder_ms_drive/|
^fs_folder_webdav/|
Expand Down
10 changes: 5 additions & 5 deletions fs_folder/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Fs Folder
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github
:target: https://github.com/OCA/storage/tree/18.0/fs_folder
:target: https://github.com/OCA/storage/tree/19.0/fs_folder
:alt: OCA/storage
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/storage-18-0/storage-18-0-fs_folder
:target: https://translation.odoo-community.org/projects/storage-19-0/storage-19-0-fs_folder
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/storage&target_branch=18.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/storage&target_branch=19.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -311,7 +311,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/storage/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/storage/issues/new?body=module:%20fs_folder%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/storage/issues/new?body=module:%20fs_folder%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -358,6 +358,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-lmignon|

This module is part of the `OCA/storage <https://github.com/OCA/storage/tree/18.0/fs_folder>`_ project on GitHub.
This module is part of the `OCA/storage <https://github.com/OCA/storage/tree/19.0/fs_folder>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
7 changes: 2 additions & 5 deletions fs_folder/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
"name": "Fs Folder",
"summary": """A module to link to Odoo records and manage from record forms forlders
from external file systems """,
"version": "18.0.1.0.0",
"version": "19.0.1.0.0",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/storage",
"depends": [
"fs_storage",
],
"depends": ["fs_storage", "bus"],
"data": [
"views/fs_storage.xml",
],
Expand All @@ -21,6 +19,5 @@
],
},
"demo": [],
"installable": False,
"maintainers": ["lmignon"],
}
16 changes: 8 additions & 8 deletions fs_folder/controllers/fs_folder_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_file(self, res_id, res_model, field_name, path, download=False, **kwargs

@http.route(
"/fs_folder/get_children/<string:res_model>/<int:res_id>/<string:field_name>",
type="json",
type="jsonrpc",
auth="user",
methods=["POST"],
)
Expand All @@ -43,7 +43,7 @@ def get_children(self, res_id, res_model, field_name, path=""):

@http.route(
"/fs_folder/add_folder/<string:res_model>/<int:res_id>/<string:field_name>",
type="json",
type="jsonrpc",
auth="user",
methods=["POST"],
)
Expand All @@ -54,7 +54,7 @@ def add_folder(self, res_id, res_model, field_name, path, name):

@http.route(
"/fs_folder/delete/<string:res_model>/<int:res_id>/<string:field_name>",
type="json",
type="jsonrpc",
auth="user",
methods=["POST"],
)
Expand All @@ -65,7 +65,7 @@ def delete(self, res_id, res_model, field_name, path, name):

@http.route(
"/fs_folder/move/<string:res_model>/<int:res_id>/<string:field_name>",
type="json",
type="jsonrpc",
auth="user",
methods=["POST"],
)
Expand All @@ -83,7 +83,7 @@ def move_file(self, res_id, res_model, field_name, path, origin_path, record):

@http.route(
"/fs_folder/copy/<string:res_model>/<int:res_id>/<string:field_name>",
type="json",
type="jsonrpc",
auth="user",
methods=["POST"],
)
Expand All @@ -101,7 +101,7 @@ def copy_file(self, res_id, res_model, field_name, path, origin_path, record):

@http.route(
"/fs_folder/rename/<string:res_model>/<int:res_id>/<string:field_name>",
type="json",
type="jsonrpc",
auth="user",
methods=["POST"],
)
Expand All @@ -116,7 +116,7 @@ def rename(self, res_id, res_model, field_name, path, name, new_name):

@http.route(
"/fs_folder/upload/<string:res_model>/<int:res_id>/<string:field_name>",
type="json",
type="jsonrpc",
auth="user",
methods=["POST"],
)
Expand All @@ -132,7 +132,7 @@ def upload(self, res_id, res_model, field_name, path, name, data):

@http.route(
"/fs_folder/initialize/<string:res_model>/<int:res_id>/<string:field_name>",
type="json",
type="jsonrpc",
auth="user",
methods=["POST"],
)
Expand Down
5 changes: 3 additions & 2 deletions fs_folder/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import fsspec

from odoo import api, fields, models, registry
from odoo import api, fields, models
from odoo.modules.registry import Registry
from odoo.tools.misc import SENTINEL, Sentinel
from odoo.tools.sql import pg_varchar

Expand Down Expand Up @@ -356,7 +357,7 @@ def create_value_in_fs(self, records: models.BaseModel) -> list[FsFolderValue]:
fs.mkdir(path, **kwargs)

def clean_up_folder(path, storage_code, dbname, user_id):
db_registry = registry(dbname)
db_registry = Registry(dbname)
with db_registry.cursor() as cr:
env = api.Environment(cr, user_id, {})
fs = env["fs.storage"].get_fs_by_code(storage_code)
Expand Down
18 changes: 10 additions & 8 deletions fs_folder/models/fs_folder_field_web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import fsspec
from werkzeug import Response

from odoo import _, api, models
from odoo import api, models
from odoo.exceptions import AccessError, UserError

from ..fs_stream import FsStream
Expand All @@ -31,10 +31,10 @@ def _check_field_access(self, res_id, res_model, field_name, access):
:param access: the access rights to check
"""
if res_model not in self.env:
raise AccessError(_("Unknown model"))
raise AccessError(self.env._("Unknown model"))
record = self.env[res_model].browse(res_id)
if field_name not in record._fields:
raise AccessError(_("Unknown field"))
raise AccessError(self.env._("Unknown field"))
record.check_access(access)

@api.model
Expand Down Expand Up @@ -76,7 +76,9 @@ def _get_fs(
if field.type == "fs_folder":
fs = record[field_name].fs
if not fs:
raise ValueError(_("The field is not an external filesystem field."))
raise ValueError(
self.env._("The field is not an external filesystem field.")
)
return fs

@api.model
Expand Down Expand Up @@ -113,13 +115,13 @@ def get_children(self, res_id, res_model, field_name, path, **kwargs) -> list[di
return fs.ls(path, detail=True)
except Exception as e:
raise UserError(
_(
"An error occurred while listing files: '%s'\n"
self.env._(
"An error occurred while listing files: '%(exception)s'\n"
"This might happen if the folder was moved, renamed or deleted "
"on the external storage.\n"
"If this is expected you might want to unlink this folder."
"If this is expected you might want to unlink this folder.",
exception=e,
)
% e
) from e

@api.model
Expand Down
20 changes: 13 additions & 7 deletions fs_folder/models/fs_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
import re

from odoo import _, api, fields, models, tools
from odoo import api, fields, models, tools
from odoo.exceptions import UserError, ValidationError


Expand Down Expand Up @@ -33,18 +33,23 @@ def _check_fs_name_sanitization_replace_char(self):

if rc and self._invalid_fs_name_chars_re_pattern.findall(rc):
raise ValidationError(
_("The character to use as replacement can not be one of '%s'")
% self._invalid_fs_name_chars
self.env._(
"The character to use as replacement can not be one of "
"'%(invalid_chars)s'",
invalid_chars=self._invalid_fs_name_chars,
)
)

@api.constrains("use_as_default_for_fs_contents")
def _check_use_as_default_for_fs_contents(self):
# constrains are checked in python since values can be provided by
# the server environment
defaults = self.search([]).filtered("use_as_default_for_fs_contents")
defaults = self.search([]).filtered("use_as_default_for_fs_contents") # pylint: disable=no-search-all
if len(defaults) > 1:
raise ValidationError(
_("Only one storage can be used as default for filesystem contents.")
self.env._(
"Only one storage can be used as default for filesystem contents."
)
)

@property
Expand All @@ -60,6 +65,7 @@ def _server_env_fields(self):
@api.model
@tools.ormcache()
def get_storage_code_for_fs_content_fallback(self) -> str | None:
# pylint: disable=no-search-all
storages = (
self.sudo()
.search([])
Expand All @@ -80,7 +86,7 @@ def get_default_storage_code_for_fs_content(self, model_name, field_name) -> str
storage_code = self.get_storage_code_for_fs_content_fallback()
if not storage_code:
raise ValueError(
_(
self.env._(
"No default storage found for the content of the external "
"filesystem fields for model %(model)s and field %(field)s. "
"Please set a default storage in the filesystem storage "
Expand All @@ -105,7 +111,7 @@ def is_fs_name_valid(self, name, raise_if_invalid=False) -> bool:
invalid = self._invalid_fs_name_chars_re_pattern.findall(name)
if invalid and raise_if_invalid:
raise UserError(
_(
self.env._(
"The name '%(name)s' contains invalid characters"
" %(invalid_chars)s.\n"
"The following chars are not allowed: %(all_invalid_chars)s",
Expand Down
6 changes: 3 additions & 3 deletions fs_folder/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ <h1>Fs Folder</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c4cce3679f458dfca0f84f2626680d41bd9ae5049b0fde289ecb07ee4359a869
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/storage/tree/18.0/fs_folder"><img alt="OCA/storage" src="https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/storage-18-0/storage-18-0-fs_folder"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/storage&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/storage/tree/19.0/fs_folder"><img alt="OCA/storage" src="https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/storage-19-0/storage-19-0-fs_folder"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/storage&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>If you need to link some specific models to a specific folder into an
external filesystem and be able to manage the content of this folder
from the model form view, this module is for you.</p>
Expand Down Expand Up @@ -645,7 +645,7 @@ <h2><a class="toc-backref" href="#toc-entry-11">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/storage/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/storage/issues/new?body=module:%20fs_folder%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/storage/issues/new?body=module:%20fs_folder%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -682,7 +682,7 @@ <h3><a class="toc-backref" href="#toc-entry-16">Maintainers</a></h3>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/lmignon"><img alt="lmignon" src="https://github.com/lmignon.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/storage/tree/18.0/fs_folder">OCA/storage</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/storage/tree/19.0/fs_folder">OCA/storage</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions fs_folder/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def setUpClass(cls):
cls.loader.update_registry(
(FsTestModel, FsTestModelInherits, FsTestModelRelated)
)

cls.fs_test_model = cls.env[FsTestModel._name]
cls.fs_test_model_inherits = cls.env[FsTestModelInherits._name]
cls.fs_test_model_related = cls.env[FsTestModelRelated._name]
Expand Down
9 changes: 8 additions & 1 deletion fs_folder/tests/test_fs_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
from odoo.tests.common import TransactionCase

from odoo.addons.base.tests.common import BaseCommon
from odoo.addons.fs_storage.models.fs_storage import FSStorage


class TestFsStorage(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env["base"].with_context(**BaseCommon.default_env_context()).env
cls.backend = cls.env.ref("fs_storage.fs_storage_demo")
cls.backend: FSStorage = cls.env["fs.storage"].create(
{
"name": "Odoo Filesystem Backend",
"protocol": "odoofs",
"code": "odoofs",
}
)

def test_is_fs_name_valid(self):
self.assertFalse(self.backend.is_fs_name_valid(r'my\/:*?"<>| directory'))
Expand Down
Loading