summaryrefslogtreecommitdiff
path: root/addons/web/controllers
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2020-01-15 09:20:14 +0000
committerDavid Beguin <dbe@odoo.com>2020-01-17 10:25:20 +0000
commit307f51ab8597ca14e374f809401f0cf84dcde954 (patch)
tree287413710539bc9d3f53b279505a3e1f1b25504b /addons/web/controllers
parentded9d60986022caf6973e2fbf2b01c3783117db9 (diff)
[IMP] web: split _content_image with get response sub method
This commit splits the _content_image method to allow to call the get response part individually. This is needed because _content_image call binary_content using current user access. But in some cases, we need to render a binary content even if the user does not have access to the target model (typically for public users). The binary_content is gotten in sudo mode where needed and the result can be given to the _content_image_get_response. This will avoid code duplication where the sudo use case is met. Usage : This commit prepare the redesign of survey. This _content_image_get_response method will be called to grant access of background image even for public users. Other modules will use this new method like elearning (website_slides) to display karma ranking, etc. Task ID: '2150291' PR #43237
Diffstat (limited to 'addons/web/controllers')
-rw-r--r--addons/web/controllers/main.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index 90657b2e764..cdc2fa3b950 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -1365,7 +1365,8 @@ class View(http.Controller):
class Binary(http.Controller):
- def placeholder(self, image='placeholder.png'):
+ @staticmethod
+ def placeholder(image='placeholder.png'):
with tools.file_open(get_resource_path('web', 'static/src/img', image), 'rb') as fd:
return fd.read()
@@ -1442,10 +1443,17 @@ class Binary(http.Controller):
filename_field=filename_field, download=download, mimetype=mimetype,
default_mimetype='image/png', access_token=access_token)
+ return Binary._content_image_get_response(status, headers, image_base64, field=field, download=download,
+ width=width, height=height, crop=crop, quality=quality,
+ placeholder=placeholder)
+
+ @staticmethod
+ def _content_image_get_response(status, headers, image_base64, field='datas', download=None,
+ width=0, height=0, crop=False, quality=0, placeholder='placeholder.png'):
if status in [301, 304] or (status != 200 and download):
return request.env['ir.http']._response_by_status(status, headers, image_base64)
if not image_base64:
- image_base64 = base64.b64encode(self.placeholder(image=placeholder))
+ image_base64 = base64.b64encode(Binary.placeholder(image=placeholder))
if not (width or height):
width, height = odoo.tools.image_guess_size_from_field_name(field)