summaryrefslogtreecommitdiff
path: root/addons/survey/controllers/main.py
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2020-01-30 13:39:31 +0000
committerDavid Beguin <dbe@odoo.com>2020-01-31 08:04:15 +0000
commit44c3a6ef8dfaacb0b347d9efd28651162de139ca (patch)
tree4c1a18455db0c1009036e0541e3b70a4e389d364 /addons/survey/controllers/main.py
parent09e102ece5cce871fdd3d7d96d8867b1517395e4 (diff)
[FIX] survey: allow question answer image for public users
As well as background, suggested answers images are not available for public users as they don't have access rights on that model. This commit adds a route called by survey template that render the suggested answers image in sudo mode. closes odoo/odoo#44351 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/survey/controllers/main.py')
-rw-r--r--addons/survey/controllers/main.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py
index 7c971d65ab9..5f47305afa0 100644
--- a/addons/survey/controllers/main.py
+++ b/addons/survey/controllers/main.py
@@ -299,6 +299,24 @@ class Survey(http.Controller):
return Binary._content_image_get_response(status, headers, image_base64)
+ @http.route('/survey/get_question_image/<string:survey_token>/<string:answer_token>/<int:question_id>/<int:suggested_answer_id>', type='http', auth="public", website=True, sitemap=False)
+ def survey_get_question_image(self, survey_token, answer_token, question_id, suggested_answer_id):
+ access_data = self._get_access_data(survey_token, answer_token, ensure_token=True)
+ if access_data['validity_code'] is not True:
+ return werkzeug.exceptions.Forbidden()
+
+ survey_sudo, answer_sudo = access_data['survey_sudo'], access_data['answer_sudo']
+
+ if not survey_sudo.question_ids.filtered(lambda q: q.id == question_id)\
+ .suggested_answer_ids.filtered(lambda a: a.id == suggested_answer_id):
+ return werkzeug.exceptions.NotFound()
+
+ status, headers, image_base64 = request.env['ir.http'].sudo().binary_content(
+ model='survey.question.answer', id=suggested_answer_id, field='value_image',
+ default_mimetype='image/png')
+
+ return Binary._content_image_get_response(status, headers, image_base64)
+
# ----------------------------------------------------------------
# JSON ROUTES to begin / continue survey (ajax navigation) + Tools
# ----------------------------------------------------------------