[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>
This commit is contained in:
David Beguin
2020-01-31 08:04:15 +00:00
parent 09e102ece5
commit 44c3a6ef8d
2 changed files with 22 additions and 3 deletions
+18
View File
@@ -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
# ----------------------------------------------------------------
+4 -3
View File
@@ -302,9 +302,10 @@
<template id="question_suggested_value_image" name="Image from the question suggested answer">
<div t-if="question.allow_value_image and label.value_image"
t-field="label.value_image"
class="d-flex my-3 justify-content-center"
t-options='{"widget": "image", "alt-field": "name", "itemprop": "image"}'/>
class="d-flex my-3 justify-content-center">
<img t-att-src="'/survey/get_question_image/%s/%s/%s/%s' % (survey.access_token, answer.access_token, question.id, label.id)"/>
</div>
</template>
<template id="question_simple_choice" name="Question: simple choice">