diff options
| author | Olivier Dony <odo@openerp.com> | 2017-09-21 23:42:45 +0200 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2017-09-21 23:48:36 +0200 |
| commit | 2257583bb5aeb8d165f8bc6e872a671fbcd6a1a9 (patch) | |
| tree | b116c6d4bbd848944457ea75c4121de206e48314 /addons/web/controllers | |
| parent | bb0404ea30af6aefc40d9ea92801dcf314bcb9f9 (diff) | |
[ADD] ir.attachment: add token field for external access
Introduce a new attachment field (access_token) to allow external
unauthenticated access. This will be an opaque unique number
(typically a UUID) that should be provided via an appropriate
controller, for unauthenticated display.
The field is intended to be NULL unless unauthenticated access has been
allowed, in which case a value will be set for the access_token.
This could be used e.g. for allowing access to images within mailings,
even when the recipient is not logged in (which is sometimes entirely
impossible, when email providers use restricted proxy servers to
load images)
Note 1: this is still a work-in-progress, but serves to freeze the API.
The implementation of the access check and provisioning of the new
field will be added later.
Note 2: namimg collisions with the file download token prevent the use
of a shorter 'token' parameter for download routes.
Apologies for the late (and incomplete) addition in saas-18 :-/
Diffstat (limited to 'addons/web/controllers')
| -rw-r--r-- | addons/web/controllers/main.py | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 94e88af0900..84e5b524343 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -417,10 +417,13 @@ def xml2json_from_elementtree(el, preserve_whitespaces=False): res["children"] = kids return res -def binary_content(xmlid=None, model='ir.attachment', id=None, field='datas', unique=False, filename=None, filename_field='datas_fname', download=False, mimetype=None, default_mimetype='application/octet-stream', env=None): +def binary_content(xmlid=None, model='ir.attachment', id=None, field='datas', unique=False, + filename=None, filename_field='datas_fname', download=False, mimetype=None, + default_mimetype='application/octet-stream', access_token=None, env=None): return request.registry['ir.http'].binary_content( - xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename, filename_field=filename_field, - download=download, mimetype=mimetype, default_mimetype=default_mimetype, env=env) + xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename, + filename_field=filename_field, download=download, mimetype=mimetype, + default_mimetype=default_mimetype, access_token=access_token, env=env) #---------------------------------------------------------- # Odoo Web web Controllers @@ -971,8 +974,13 @@ class Binary(http.Controller): '/web/content/<int:id>-<string:unique>/<string:filename>', '/web/content/<string:model>/<int:id>/<string:field>', '/web/content/<string:model>/<int:id>/<string:field>/<string:filename>'], type='http', auth="public") - def content_common(self, xmlid=None, model='ir.attachment', id=None, field='datas', filename=None, filename_field='datas_fname', unique=None, mimetype=None, download=None, data=None, token=None): - status, headers, content = binary_content(xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename, filename_field=filename_field, download=download, mimetype=mimetype) + def content_common(self, xmlid=None, model='ir.attachment', id=None, field='datas', + filename=None, filename_field='datas_fname', unique=None, mimetype=None, + download=None, data=None, token=None, access_token=None): + status, headers, content = binary_content( + xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename, + filename_field=filename_field, download=download, mimetype=mimetype, + access_token=access_token) if status == 304: response = werkzeug.wrappers.Response(status=status, headers=headers) elif status == 301: @@ -1004,8 +1012,13 @@ class Binary(http.Controller): '/web/image/<int:id>-<string:unique>/<string:filename>', '/web/image/<int:id>-<string:unique>/<int:width>x<int:height>', '/web/image/<int:id>-<string:unique>/<int:width>x<int:height>/<string:filename>'], type='http', auth="public") - def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas', filename_field='datas_fname', unique=None, filename=None, mimetype=None, download=None, width=0, height=0, crop=False): - status, headers, content = binary_content(xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename, filename_field=filename_field, download=download, mimetype=mimetype, default_mimetype='image/png') + def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas', + filename_field='datas_fname', unique=None, filename=None, mimetype=None, + download=None, width=0, height=0, crop=False, access_token=None): + status, headers, content = binary_content( + xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename, + filename_field=filename_field, download=download, mimetype=mimetype, + default_mimetype='image/png', access_token=access_token) if status == 304: return werkzeug.wrappers.Response(status=304, headers=headers) elif status == 301: |
