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] fs_attachment Oca port from 17.0 to 18.0 pr 344 368 413 415 414 #420

Merged
Merged
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
5 changes: 5 additions & 0 deletions .oca/oca-port/blacklist/fs_attachment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"pull_requests": {
"OCA/storage#344": "migration PR"
}
}
400 changes: 201 additions & 199 deletions fs_attachment/README.rst

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions fs_attachment/fs_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ def read(self):
return f.read()
return super().read()

def get_response(self, as_attachment=None, immutable=None, **send_file_kwargs):
def get_response(
self,
as_attachment=None,
immutable=None,
content_security_policy="default-src 'none'",
**send_file_kwargs,
):
if self.type != "fs":
return super().get_response(
as_attachment=as_attachment, immutable=immutable, **send_file_kwargs
Expand All @@ -57,7 +63,6 @@ def get_response(self, as_attachment=None, immutable=None, **send_file_kwargs):
"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...
Expand All @@ -79,6 +84,12 @@ def get_response(self, as_attachment=None, immutable=None, **send_file_kwargs):

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

res.headers["X-Content-Type-Options"] = "nosniff"

if content_security_policy:
res.headers["Content-Security-Policy"] = content_security_policy

return res

@classmethod
Expand Down
27 changes: 18 additions & 9 deletions fs_attachment/models/ir_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@
class IrBinary(models.AbstractModel):
_inherit = "ir.binary"

def _record_to_stream(self, record, field_name):
# Extend base implementation to support attachment stored into a
# filesystem storage
fs_attachment = None
def _get_fs_attachment_for_field(self, record, field_name):
if record._name == "ir.attachment" and record.fs_filename:
fs_attachment = record
return record

record.check_field_access_rights("read", [field_name])
field_def = record._fields[field_name]
if field_def.attachment and not field_def.compute and not field_def.related:
field_attachment = (
if field_def.attachment and field_def.store:
fs_attachment = (
self.env["ir.attachment"]
.sudo()
.search(
Expand All @@ -37,8 +35,14 @@ def _record_to_stream(self, record, field_name):
limit=1,
)
)
if field_attachment.fs_filename:
fs_attachment = field_attachment
if fs_attachment and fs_attachment.fs_filename:
return fs_attachment
return None

def _record_to_stream(self, record, field_name):
# Extend base implementation to support attachment stored into a
# filesystem storage
fs_attachment = self._get_fs_attachment_for_field(record, field_name)
if fs_attachment:
return FsStream.from_fs_attachment(fs_attachment)
return super()._record_to_stream(record, field_name)
Expand Down Expand Up @@ -100,6 +104,11 @@ def _get_image_stream_from(
if value:
record = value.attachment
field_name = "raw"
elif field_def.type in ("binary"):
fs_attachment = self._get_fs_attachment_for_field(record, field_name)
if fs_attachment:
record = fs_attachment
field_name = "raw"
stream = super()._get_image_stream_from(
record,
field_name=field_name,
Expand Down
28 changes: 15 additions & 13 deletions fs_attachment/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
Thierry Ducrest \<<thierry.ducrest@camptocamp.com>\> Guewen Baconnier
\<<guewen.baconnier@camptocamp.com>\> Julien Coux
\<<julien.coux@camptocamp.com>\> Akim Juillerat
\<<akim.juillerat@camptocamp.com>\> Thomas Nowicki
\<<thomas.nowicki@camptocamp.com>\> Vincent Renaville
\<<vincent.renaville@camptocamp.com>\> Denis Leemann
\<<denis.leemann@camptocamp.com>\> Patrick Tombez
\<<patrick.tombez@camptocamp.com>\> Don Kendall
\<<kendall@donkendall.com>\> Stephane Mangin
\<<stephane.mangin@camptocamp.com>\> Laurent Mignon
\<<laurent.mignon@acsone.eu>\> Marie Lejeune
\<<marie.lejeune@acsone.eu>\> Wolfgang Pichler \<<wpichler@callino.at>\>
Nans Lefebvre \<<len@lambdao.dev>\>
* Thierry Ducrest \<<thierry.ducrest@camptocamp.com>\>
* Guewen Baconnier \<<guewen.baconnier@camptocamp.com>\>
* Julien Coux \<<julien.coux@camptocamp.com>\>
* Akim Juillerat \<<akim.juillerat@camptocamp.com>\>
* Thomas Nowicki \<<thomas.nowicki@camptocamp.com>\>
* Vincent Renaville \<<vincent.renaville@camptocamp.com>\>
* Denis Leemann \<<denis.leemann@camptocamp.com>\>
* Patrick Tombez \<<patrick.tombez@camptocamp.com>\>
* Don Kendall \<<kendall@donkendall.com>\>
* Stephane Mangi \<<stephane.mangin@camptocamp.com>\>
* Laurent Mignon \<<laurent.mignon@acsone.eu>\>
* Marie Lejeune \<<marie.lejeune@acsone.eu>\>
* Wolfgang Pichler \<<wpichler@callino.at>\>
* Nans Lefebvre \<<len@lambdao.dev>\>
* Mohamed Alkobrosli \<<alkobroslymohamed@gmail.com>\>
Loading
Loading