[FIX] website: correctly sync website homepage url when page url change
This commit is fixing a last minute error in commit [1] after a push force which move its code above the existing line `vals['url'] = url`. After the code move, `vals['url']` was not the updated url value (which went through slugify and unique path functions). - Create a /test page, publish it. - Set /test as homepage url directly on the website (in the settings) - Go to that page - Open the page properties and change its URL from /test to /test_un -> The page url is /test-un but the website homepage_url is still /test_un (not slugified) in the website settings [1]: https://github.com/odoo/odoo/commit/374a1b31f70a3209b1ae11db8e5886350579c7f9 closes odoo/odoo#147641 X-original-commit: 3c8a58b654418fc2fc0dc9bc28420c7dcb1bafee Signed-off-by: Colin Louis (loco) <loco@odoo.com> Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
@@ -183,7 +183,7 @@ class Page(models.Model):
|
||||
page_url_normalized = {'homepage_url': page.url}
|
||||
website._handle_homepage_url(page_url_normalized)
|
||||
if website.homepage_url == page_url_normalized['homepage_url']:
|
||||
website.homepage_url = vals['url']
|
||||
website.homepage_url = url
|
||||
vals['url'] = url
|
||||
|
||||
# If name has changed, check for key uniqueness
|
||||
|
||||
@@ -308,6 +308,7 @@ class WithContext(HttpCase):
|
||||
|
||||
def test_website_homepage_url_change(self):
|
||||
website = self.env['website'].browse([1])
|
||||
self.assertFalse(website.homepage_url)
|
||||
|
||||
test_page = self.env['website.page'].create({
|
||||
'name': 'HomepageUrlTest',
|
||||
@@ -336,6 +337,7 @@ class WithContext(HttpCase):
|
||||
test_page.url = '/url-changed'
|
||||
|
||||
# .. the `homepage_url` should be changed to follow the new page URL
|
||||
self.assertEqual(website.homepage_url, '/url-changed')
|
||||
r = self.url_open('/')
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(
|
||||
@@ -344,6 +346,17 @@ class WithContext(HttpCase):
|
||||
menu different from '/', see homepage controller.""")
|
||||
self.assertIn(b"HomepageUrlTest", r.content)
|
||||
|
||||
# Side test: ensure `slugify` and `get_unique_path` changes are
|
||||
# correctly replicated in the synced website homepage_url
|
||||
with MockRequest(self.env, website=website):
|
||||
# `/url-changed_two` will become `/url-changed-two`
|
||||
test_page.url = '/url-changed_two'
|
||||
self.assertEqual(website.homepage_url, '/url-changed-two')
|
||||
r = self.url_open('/')
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(r.url, home_url_full)
|
||||
self.assertIn(b"HomepageUrlTest", r.content)
|
||||
|
||||
def test_06_homepage_url(self):
|
||||
# Setup
|
||||
website = self.env['website'].browse([1])
|
||||
|
||||
Reference in New Issue
Block a user