Skip to content

Commit 0ce4998

Browse files
committed
Merge PR #420 into 18.0
Signed-off-by lmignon
2 parents 8224563 + a223d28 commit 0ce4998

File tree

7 files changed

+362
-287
lines changed

7 files changed

+362
-287
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"pull_requests": {
3+
"OCA/storage#344": "migration PR"
4+
}
5+
}

fs_attachment/README.rst

+201-199
Large diffs are not rendered by default.

fs_attachment/fs_stream.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ def read(self):
3838
return f.read()
3939
return super().read()
4040

41-
def get_response(self, as_attachment=None, immutable=None, **send_file_kwargs):
41+
def get_response(
42+
self,
43+
as_attachment=None,
44+
immutable=None,
45+
content_security_policy="default-src 'none'",
46+
**send_file_kwargs,
47+
):
4248
if self.type != "fs":
4349
return super().get_response(
4450
as_attachment=as_attachment, immutable=immutable, **send_file_kwargs
@@ -57,7 +63,6 @@ def get_response(self, as_attachment=None, immutable=None, **send_file_kwargs):
5763
"max_age": STATIC_CACHE_LONG if immutable else self.max_age,
5864
"environ": request.httprequest.environ,
5965
"response_class": Response,
60-
**send_file_kwargs,
6166
}
6267
use_x_sendfile = self._fs_use_x_sendfile
6368
# The file will be closed by werkzeug...
@@ -79,6 +84,12 @@ def get_response(self, as_attachment=None, immutable=None, **send_file_kwargs):
7984

8085
if immutable and res.cache_control:
8186
res.cache_control["immutable"] = None
87+
88+
res.headers["X-Content-Type-Options"] = "nosniff"
89+
90+
if content_security_policy:
91+
res.headers["Content-Security-Policy"] = content_security_policy
92+
8293
return res
8394

8495
@classmethod

fs_attachment/models/ir_binary.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@
1616
class IrBinary(models.AbstractModel):
1717
_inherit = "ir.binary"
1818

19-
def _record_to_stream(self, record, field_name):
20-
# Extend base implementation to support attachment stored into a
21-
# filesystem storage
22-
fs_attachment = None
19+
def _get_fs_attachment_for_field(self, record, field_name):
2320
if record._name == "ir.attachment" and record.fs_filename:
24-
fs_attachment = record
21+
return record
22+
2523
record.check_field_access_rights("read", [field_name])
2624
field_def = record._fields[field_name]
27-
if field_def.attachment and not field_def.compute and not field_def.related:
28-
field_attachment = (
25+
if field_def.attachment and field_def.store:
26+
fs_attachment = (
2927
self.env["ir.attachment"]
3028
.sudo()
3129
.search(
@@ -37,8 +35,14 @@ def _record_to_stream(self, record, field_name):
3735
limit=1,
3836
)
3937
)
40-
if field_attachment.fs_filename:
41-
fs_attachment = field_attachment
38+
if fs_attachment and fs_attachment.fs_filename:
39+
return fs_attachment
40+
return None
41+
42+
def _record_to_stream(self, record, field_name):
43+
# Extend base implementation to support attachment stored into a
44+
# filesystem storage
45+
fs_attachment = self._get_fs_attachment_for_field(record, field_name)
4246
if fs_attachment:
4347
return FsStream.from_fs_attachment(fs_attachment)
4448
return super()._record_to_stream(record, field_name)
@@ -100,6 +104,11 @@ def _get_image_stream_from(
100104
if value:
101105
record = value.attachment
102106
field_name = "raw"
107+
elif field_def.type in ("binary"):
108+
fs_attachment = self._get_fs_attachment_for_field(record, field_name)
109+
if fs_attachment:
110+
record = fs_attachment
111+
field_name = "raw"
103112
stream = super()._get_image_stream_from(
104113
record,
105114
field_name=field_name,

fs_attachment/readme/CONTRIBUTORS.md

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
Thierry Ducrest \<<thierry.ducrest@camptocamp.com>\> Guewen Baconnier
2-
\<<guewen.baconnier@camptocamp.com>\> Julien Coux
3-
\<<julien.coux@camptocamp.com>\> Akim Juillerat
4-
\<<akim.juillerat@camptocamp.com>\> Thomas Nowicki
5-
\<<thomas.nowicki@camptocamp.com>\> Vincent Renaville
6-
\<<vincent.renaville@camptocamp.com>\> Denis Leemann
7-
\<<denis.leemann@camptocamp.com>\> Patrick Tombez
8-
\<<patrick.tombez@camptocamp.com>\> Don Kendall
9-
\<<kendall@donkendall.com>\> Stephane Mangin
10-
\<<stephane.mangin@camptocamp.com>\> Laurent Mignon
11-
\<<laurent.mignon@acsone.eu>\> Marie Lejeune
12-
\<<marie.lejeune@acsone.eu>\> Wolfgang Pichler \<<wpichler@callino.at>\>
13-
Nans Lefebvre \<<len@lambdao.dev>\>
1+
* Thierry Ducrest \<<thierry.ducrest@camptocamp.com>\>
2+
* Guewen Baconnier \<<guewen.baconnier@camptocamp.com>\>
3+
* Julien Coux \<<julien.coux@camptocamp.com>\>
4+
* Akim Juillerat \<<akim.juillerat@camptocamp.com>\>
5+
* Thomas Nowicki \<<thomas.nowicki@camptocamp.com>\>
6+
* Vincent Renaville \<<vincent.renaville@camptocamp.com>\>
7+
* Denis Leemann \<<denis.leemann@camptocamp.com>\>
8+
* Patrick Tombez \<<patrick.tombez@camptocamp.com>\>
9+
* Don Kendall \<<kendall@donkendall.com>\>
10+
* Stephane Mangi \<<stephane.mangin@camptocamp.com>\>
11+
* Laurent Mignon \<<laurent.mignon@acsone.eu>\>
12+
* Marie Lejeune \<<marie.lejeune@acsone.eu>\>
13+
* Wolfgang Pichler \<<wpichler@callino.at>\>
14+
* Nans Lefebvre \<<len@lambdao.dev>\>
15+
* Mohamed Alkobrosli \<<alkobroslymohamed@gmail.com>\>

0 commit comments

Comments
 (0)