[FIX] website, test_website: make reset_template a json route

task-3439417

closes odoo/odoo#129611

Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
flvr-odoo
2023-07-31 16:10:54 +02:00
committed by Romain Derie
parent 35a118eff5
commit db984cb696
3 changed files with 20 additions and 7 deletions
@@ -1,4 +1,6 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import json
import re
import odoo.tests
@@ -17,8 +19,10 @@ class TestWebsiteResetViews(odoo.tests.HttpCase):
resp = self.url_open(page)
self.assertEqual(resp.status_code, 500, "Waiting 500")
self.assertTrue('<button data-mode="soft" class="reset_templates_button' in resp.text)
data = {'view_id': self.find_template(resp), 'redirect': page, 'mode': mode}
resp = self.url_open('/website/reset_template', data)
data = {'params': {'view_id': self.find_template(resp), 'mode': mode}}
self.url_open('/website/reset_template', data=json.dumps(data), headers={'Content-Type': 'application/json'})
resp = self.url_open(page)
self.assertTrue(resp.url.endswith(page), "We should be checking the test page")
self.assertEqual(resp.status_code, 200, "Waiting 200")
def find_template(self, response):
@@ -104,6 +108,7 @@ class TestWebsiteResetViews(odoo.tests.HttpCase):
# Break it again to have a previous arch different than file arch
break_view(self.test_page_view.with_context(website_id=1))
self.assertEqual(total_views + 1, self.View.search_count([('type', '=', 'qweb')]), "Missing COW view")
with self.assertRaises(AssertionError):
# soft reset should not be able to reset the view as previous
# version is also broken
+3 -3
View File
@@ -647,8 +647,8 @@ class Website(Home):
views = views.sorted(key=lambda v: (v.inherit_id.id, v.name))
return views.with_context(display_website=False).read(['name', 'id', 'key', 'xml_id', 'active', 'inherit_id'])
@http.route('/website/reset_template', type='http', auth='user', methods=['POST'], website=True, csrf=False)
def reset_template(self, view_id, mode='soft', redirect='/', **kwargs):
@http.route('/website/reset_template', type='json', auth='user', methods=['POST'])
def reset_template(self, view_id, mode='soft', **kwargs):
""" This method will try to reset a broken view.
Given the mode, the view can either be:
- Soft reset: restore to previous architeture.
@@ -658,7 +658,7 @@ class Website(Home):
view = request.env['ir.ui.view'].browse(int(view_id))
# Deactivate COW to not fix a generic view by creating a specific
view.with_context(website_id=None).reset_arch(mode)
return request.redirect(redirect)
return True
@http.route(['/website/publish'], type='json', auth="user", website=True)
def publish(self, id, object):
+10 -2
View File
@@ -2326,8 +2326,16 @@
if (input.val() == dialog.find('.confirm_word').text()) {
dialog.modal('hide');
button.prop('disabled', true).text('Working...');
$('#reset_templates_form').attr('action', '/website/reset_template');
$('#reset_templates_form').trigger('submit');
const id = document.querySelector('input[id="reset_templates_view_id"]').value;
const redirect = document.querySelector('input[name="redirect"]').value;
const mode = document.querySelector('input[id="reset_templates_mode"]').value;
fetch('/website/reset_template', {
method: "POST",
headers: {
"Content-Type": "application/json",
},
'body': JSON.stringify({'params': {'view_id': id, 'mode': mode}})
}).then(() => window.location = redirect);
} else {
input.val('').focus();
}