From 3de06d645dc164219530c74a8fe7cfbb7bf8a1ef Mon Sep 17 00:00:00 2001 From: amdi-odoo Date: Tue, 27 Feb 2024 13:26:56 +0100 Subject: [PATCH] [FIX] survey: fix override answers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Purpose ======= Fix the UserError which is raised when the user submits an answer to a question having the "save as nickname" or "save as email" option checked. In testing or non-testing mode. Specifications ============== When the question is marked as "save as email" or "save as nickname" and when the user isn't public, the partner data is already saved as the question answer (in the form of a user input line). The answer is then pre-filled in the survey. This is an issue because when the survey has the "users can go back" option to False and the user tries to submit the answer, it thinks the user is trying to changed the already saved user input line and it crashes for security reasons. In addition of allowing the answer override if the user can go back, also allow the override if the question is marked as "save as nickname" or "save as email". This issue was introduced in 17.0 when the overwrite_existing optional parameter has been added on the _save_lines method. Before that, the existing user input lines were overwritten no matter what. related odoo/odoo#129329 Task-3756749 closes odoo/odoo#155561 Signed-off-by: Warnon Aurélien (awa) --- addons/survey/controllers/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py index b9ee8f94df6..3433285c1b6 100644 --- a/addons/survey/controllers/main.py +++ b/addons/survey/controllers/main.py @@ -533,7 +533,7 @@ class Survey(http.Controller): answer, comment = self._extract_comment_from_answers(question, post.get(str(question.id))) errors.update(question.validate_question(answer, comment)) if not errors.get(question.id): - answer_sudo._save_lines(question, answer, comment, overwrite_existing=survey_sudo.users_can_go_back) + answer_sudo._save_lines(question, answer, comment, overwrite_existing=survey_sudo.users_can_go_back or question.save_as_nickname or question.save_as_email) if errors and not (answer_sudo.survey_time_limit_reached or answer_sudo.question_time_limit_reached): return {}, {'error': 'validation', 'fields': errors}