Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] fs_attachment: Migration to 18.0 #403

Open
wants to merge 70 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
67671a4
[ADD] fs_attachment: Store attachment through fsspec
lmignon Apr 7, 2023
4c26cc6
[IMP] fs_attachement: implements x-access
lmignon Apr 20, 2023
8d84d0c
[IMP] fs_attachement: implements filename obfuscation
lmignon Apr 20, 2023
3806c92
[IMP] fs_attachment: Declares maintainer
lmignon Apr 27, 2023
324fa5e
[FIX] fs_attachment: Do nothing in write if nothing to write
lmignon Apr 27, 2023
204ee54
[IMP] fs_attachment: Set development status to 'Beta'
lmignon May 24, 2023
7675e61
[IMP] fs_attachment: Add full support for file like open method
lmignon Jun 4, 2023
d98405e
[IMP] fs_attachment: Speedup install
lmignon Jul 10, 2023
62e1b7f
[IMP] fs_attachment: Server Environement support
lmignon Jul 10, 2023
edca4e2
[IMP] fs_attachment: Simplify code.
lmignon Jul 10, 2023
6b297ac
[FIX] fs_attachment: No new registry creation
lmignon Jul 10, 2023
e8de0cc
[IMP] fs_attachment: store attachments linked to different model/fiel…
marielejeune Aug 1, 2023
d5f0a17
[UPD] Update fs_attachment.pot
Aug 24, 2023
be93eaa
[UPD] README.rst
OCA-git-bot Aug 24, 2023
a527cc6
[ADD] icon.png
OCA-git-bot Aug 24, 2023
aaed4ac
[IMP] fs_attachment: Fix too many values to unpack
lmignon Aug 31, 2023
e5c06d0
fs_attachment 16.0.1.0.1
OCA-git-bot Aug 31, 2023
c7533d7
[FIX] fs_attachment: Fix streaming
lmignon Sep 3, 2023
b035b43
[UPD] README.rst
OCA-git-bot Sep 3, 2023
12b42af
[IMP] fs_attachment: Remose useless code
lmignon Sep 7, 2023
b49246e
[FIX] fs_attachment: No db rules for storages not used as default for…
lmignon Oct 9, 2023
b6b39cc
[FIX] Added future import annotations to be python 3.9 compatible
wpichler Oct 5, 2023
58399a3
[IMP] fs_attachment: Add history
lmignon Oct 9, 2023
465c5ca
[BOT] post-merge updates
OCA-git-bot Oct 9, 2023
05df14e
[FIX] fs_storage, fs_attachement: Missing sudo for technical models
adrienpeiffer Oct 16, 2023
158ca29
[BOT] post-merge updates
OCA-git-bot Oct 17, 2023
bd64099
Added translation using Weblate (Spanish)
Ivorra78 Oct 26, 2023
d3b1366
Translated using Weblate (Spanish)
Ivorra78 Oct 26, 2023
70f734f
[FIX] fs_attachment: Avoid error on url compute
lmignon Nov 22, 2023
79a4e05
[BOT] post-merge updates
OCA-git-bot Nov 22, 2023
c490407
Added translation using Weblate (Italian)
mymage Nov 27, 2023
0a69156
[FIX] fs_attachment: Avoid local variable redefine
lmignon Nov 29, 2023
4f3fcf4
[BOT] post-merge updates
OCA-git-bot Nov 29, 2023
b5325e3
Translated using Weblate (Italian)
mymage Nov 29, 2023
c43e470
[IMP] fs_attachment: Improve performance
lmignon Nov 30, 2023
e6cb5e8
Translated using Weblate (Italian)
mymage Dec 1, 2023
4f930bd
[BOT] post-merge updates
OCA-git-bot Dec 2, 2023
5ee7965
[FIX] add a few missing sudo to fs_attachment
sbidoul Dec 3, 2023
ab82adf
[BOT] post-merge updates
OCA-git-bot Dec 3, 2023
15e8ed3
[FIX] fs_attachment: broken links when nonempty paths
len-foss Dec 10, 2023
22218a8
[BOT] post-merge updates
OCA-git-bot Dec 20, 2023
05d7165
Translated using Weblate (Italian)
mymage Jan 5, 2024
5e4c2d3
[IMP] fs_attachment: more robust pre_init_hook
len-foss Feb 13, 2024
5029f0a
Added translation using Weblate (French)
benwillig Feb 15, 2024
a07579b
[BOT] post-merge updates
OCA-git-bot Feb 21, 2024
b65d8ff
[FIX] compute the mimetype from new datas or raw to prevent errors wh…
benwillig Jan 24, 2024
b026e45
[IMP] fs_attachment: pre-commit auto fixes
nguyenminhchien Feb 22, 2024
ef15e92
[MIG] fs_attachment: Migration to 17.0
nguyenminhchien Mar 11, 2024
e765d0a
[UPD] Update fs_attachment.pot
Mar 24, 2024
4e53bea
[BOT] post-merge updates
OCA-git-bot Mar 24, 2024
2835410
Update translation files
weblate Mar 24, 2024
eb9ebef
[FIX] pre-commit
lmignon May 2, 2024
1d29e07
[BOT] post-merge updates
OCA-git-bot May 2, 2024
586d157
[UPD] Update fs_attachment.pot
May 3, 2024
e797b4a
Update translation files
weblate May 3, 2024
f0fca40
[FIX] fs_attachment: fix constraint
astirpe Apr 25, 2024
bc72b19
[BOT] post-merge updates
OCA-git-bot Jun 4, 2024
360f454
Added translation using Weblate (Chinese (Simplified) (zh_CN))
xtanuiha Aug 26, 2024
e7877e7
Translated using Weblate (Chinese (Simplified) (zh_CN))
xtanuiha Aug 26, 2024
2752db4
[FIX] fs_attachment: respect controller parameters for /web/content/
hbrunn Apr 27, 2024
346dfe2
[FIX] fs_attachment: Rename file in storage when name is written
hbrunn Apr 27, 2024
206d9b4
[IMP] fs_attachment: No crash on missing file
lmignon Apr 22, 2024
eba9319
[FIX] fs_attachment: prevent recompute_urls from skipping records wit…
PabloEForgeFlow Jul 17, 2024
2119d70
[IMP] fs_attachment: add test for recompute_urls
PabloEForgeFlow Jul 24, 2024
d2da214
[IMP] fs_attachment OSError is an alias for the deprecated IOError
sbidoul Oct 7, 2024
4524f9c
[IMP] fs_attachment: wrap long lines
sbidoul Oct 7, 2024
9013015
[BOT] post-merge updates
OCA-git-bot Oct 15, 2024
c2b39bb
[IMP] fs_attachment: pre-commit auto fixes
sbidoul Oct 15, 2024
edd8bf0
[MIG] fs_attachment: Migration to 18.0
qgroulard Oct 7, 2024
0eb78b9
[TMP] dependency on unmerged fs_storage migration
sbidoul Oct 15, 2024
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
474 changes: 474 additions & 0 deletions fs_attachment/README.rst

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions fs_attachment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import pre_init_hook
24 changes: 24 additions & 0 deletions fs_attachment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2017-2021 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)


{
"name": "Base Attachment Object Store",
"summary": "Store attachments on external object store",
"version": "18.0.1.0.0",
"author": "Camptocamp, ACSONE SA/NV, Odoo Community Association (OCA)",
"license": "AGPL-3",
"development_status": "Beta",
"category": "Knowledge Management",
"depends": ["fs_storage"],
"website": "https://github.com/OCA/storage",
"data": [
"security/fs_file_gc.xml",
"views/fs_storage.xml",
],
"external_dependencies": {"python": ["python_slugify"]},
"installable": True,
"auto_install": False,
"maintainers": ["lmignon"],
"pre_init_hook": "pre_init_hook",
}
95 changes: 95 additions & 0 deletions fs_attachment/fs_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from __future__ import annotations

from odoo.http import STATIC_CACHE_LONG, Response, Stream, request
from odoo.tools import config

from .models.ir_attachment import IrAttachment

try:
from werkzeug.utils import send_file as _send_file
except ImportError:
from odoo.tools._vendor.send_file import send_file as _send_file

Check warning on line 13 in fs_attachment/fs_stream.py

View check run for this annotation

Codecov / codecov/patch

fs_attachment/fs_stream.py#L12-L13

Added lines #L12 - L13 were not covered by tests


class FsStream(Stream):
fs_attachment = None

@classmethod
def from_fs_attachment(cls, attachment: IrAttachment) -> FsStream:
attachment.ensure_one()
if not attachment.fs_filename:
raise ValueError("Attachment is not stored into a filesystem storage")

Check warning on line 23 in fs_attachment/fs_stream.py

View check run for this annotation

Codecov / codecov/patch

fs_attachment/fs_stream.py#L23

Added line #L23 was not covered by tests
return cls(
mimetype=attachment.mimetype,
download_name=attachment.name,
conditional=True,
etag=attachment.checksum,
type="fs",
size=attachment.file_size,
last_modified=attachment["write_date"],
fs_attachment=attachment,
)

def read(self):
if self.type == "fs":
with self.fs_attachment.open("rb") as f:
return f.read()
return super().read()

Check warning on line 39 in fs_attachment/fs_stream.py

View check run for this annotation

Codecov / codecov/patch

fs_attachment/fs_stream.py#L39

Added line #L39 was not covered by tests

def get_response(self, as_attachment=None, immutable=None, **send_file_kwargs):
if self.type != "fs":
return super().get_response(
as_attachment=as_attachment, immutable=immutable, **send_file_kwargs
)
if as_attachment is None:
as_attachment = self.as_attachment

Check warning on line 47 in fs_attachment/fs_stream.py

View check run for this annotation

Codecov / codecov/patch

fs_attachment/fs_stream.py#L47

Added line #L47 was not covered by tests
if immutable is None:
immutable = self.immutable
send_file_kwargs = {
"mimetype": self.mimetype,
"as_attachment": as_attachment,
"download_name": self.download_name,
"conditional": self.conditional,
"etag": self.etag,
"last_modified": self.last_modified,
"max_age": STATIC_CACHE_LONG if immutable else self.max_age,
"environ": request.httprequest.environ,
"response_class": Response,
**send_file_kwargs,
}
use_x_sendfile = self._fs_use_x_sendfile
# The file will be closed by werkzeug...
send_file_kwargs["use_x_sendfile"] = use_x_sendfile
if not use_x_sendfile:
f = self.fs_attachment.open("rb")
res = _send_file(f, **send_file_kwargs)
else:
x_accel_redirect = (
f"/{self.fs_attachment.fs_storage_code}{self.fs_attachment.fs_url_path}"
)
send_file_kwargs["use_x_sendfile"] = True
res = _send_file("", **send_file_kwargs)
# nginx specific headers
res.headers["X-Accel-Redirect"] = x_accel_redirect
# apache specific headers
res.headers["X-Sendfile"] = x_accel_redirect
res.headers["Content-Length"] = 0

if immutable and res.cache_control:
res.cache_control["immutable"] = None

Check warning on line 81 in fs_attachment/fs_stream.py

View check run for this annotation

Codecov / codecov/patch

fs_attachment/fs_stream.py#L81

Added line #L81 was not covered by tests
return res

@classmethod
def _check_use_x_sendfile(cls, attachment: IrAttachment) -> bool:
return (
config["x_sendfile"]
and attachment.fs_url
and attachment.fs_storage_id.use_x_sendfile_to_serve_internal_url
)

@property
def _fs_use_x_sendfile(self) -> bool:
"""Return True if x-sendfile should be used to serve the file"""
return self._check_use_x_sendfile(self.fs_attachment)
38 changes: 38 additions & 0 deletions fs_attachment/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging

from odoo.tools.sql import column_exists

_logger = logging.getLogger(__name__)


def pre_init_hook(env):
"""Pre init hook."""
# add columns for computed fields to avoid useless computation by the ORM
# when installing the module
cr = env.cr
if column_exists(cr, "ir_attachment", "fs_storage_id"):
return # columns already added; update probably failed partway

Check warning on line 16 in fs_attachment/hooks.py

View check run for this annotation

Codecov / codecov/patch

fs_attachment/hooks.py#L16

Added line #L16 was not covered by tests
_logger.info("Add columns for computed fields on ir_attachment")
cr.execute(
"""
ALTER TABLE ir_attachment
ADD COLUMN fs_storage_id INTEGER;
ALTER TABLE ir_attachment
ADD FOREIGN KEY (fs_storage_id) REFERENCES fs_storage(id);
"""
)
cr.execute(
"""
ALTER TABLE ir_attachment
ADD COLUMN fs_url VARCHAR;
"""
)
cr.execute(
"""
ALTER TABLE ir_attachment
ADD COLUMN fs_storage_code VARCHAR;
"""
)
_logger.info("Columns added on ir_attachment")
Loading
Loading