[FIX] website: do not reuse an existing view key for a page key

When generating a new page key, it was only made sure to not match
existing page keys. This leads to COW happening on existing views if the
key already existed in a view.

This commit ensures that new page keys are not existing view keys
either.

Steps to reproduce:
- Create a page named "snippets".

=> Notification was shown indicating that `website.snippets` is private.

task-3328827

closes odoo/odoo#123693

X-original-commit: e7ef9f0bfc59a468c9f883561c371367cc06c1b7
Signed-off-by: Romain Derie (rde) <rde@odoo.com>
Signed-off-by: Benoit Socias (bso) <bso@odoo.com>
This commit is contained in:
Benoit Socias
2023-06-05 17:51:23 +02:00
parent fc7fa1683c
commit 6e26ca030d
2 changed files with 17 additions and 5 deletions
+1 -1
View File
@@ -817,7 +817,7 @@ class Website(models.Model):
website_id = self.env.context.get('website_id', False)
if website_id:
domain_static = [('website_id', 'in', (False, website_id))]
while self.env['website.page'].with_context(active_test=False).sudo().search([('key', '=', key_copy)] + domain_static):
while self.env['ir.ui.view'].with_context(active_test=False).sudo().search([('key', '=', key_copy)] + domain_static):
inc += 1
key_copy = string + (inc and "-%s" % inc or "")
return key_copy
+16 -4
View File
@@ -1,14 +1,15 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from unittest.mock import patch
from odoo.http import root
from lxml import html
from unittest.mock import patch
from odoo.addons.website.controllers.main import Website
from odoo.addons.website.tools import MockRequest
from odoo.fields import Command
from odoo.http import root
from odoo.tests import common, HttpCase, tagged
from odoo.tests.common import HOST
from odoo.tools import config, mute_logger
from odoo.addons.website.tools import MockRequest
from odoo.fields import Command
@tagged('-at_install', 'post_install')
@@ -490,3 +491,14 @@ class WithContext(HttpCase):
r2 = self.url_open('/Page_1', allow_redirects=False)
self.assertEqual(r2.status_code, 303, "URL exists only in different casing, should redirect to it")
self.assertTrue(r2.headers.get('Location').endswith('/page_1'), "Should redirect /Page_1 to /page_1")
@tagged('-at_install', 'post_install')
class TestNewPage(common.TransactionCase):
def test_new_page_used_key(self):
website = self.env.ref('website.default_website')
controller = Website()
with MockRequest(self.env, website=website):
controller.pagenew(path="snippets")
pages = self.env['website.page'].search([('url', '=', '/snippets')])
self.assertEqual(len(pages), 1, "Exactly one page should be at /snippets.")
self.assertNotEqual(pages.key, "website.snippets", "Page's key cannot be website.snippets.")