Files
odoo_source/addons/website/tests/test_controllers.py
T
Romain Derie 030d3cb10e [IMP] website: use custom URL for website in backend
The website architecture has been refactored for the internal users and
admins with [1].
Now, they can access the website in the backend inside the website app.
Long story short, the website will be displayed in an iframe in a client
action. The URL of the browser will be tweaked to reflect the iframe one
instead of the real one (which is something like /web#action=..).

It had a few drawbacks:
- On page refresh (F5 or browser button), the user would land on the
  frontend version of the website instead of remaining in the backend.
- When the user edited the URL (Like removing `/shop` and typing `/jobs`
  instead, he would land on the frontend version too.
- Impossible to directly go to the backend version of the website.

Those are improved with this commit by using a slightly different URL
when we are in the backend. A `/@/` will prefix the iframe URL.

If logged in, the user will land on the backend. If not, it will simply
redirect to the frontend version of the website.

[1]: https://github.com/odoo/odoo/commit/31cc10b91dc7762e23b4bde9b945be0c4ce3fe3b

task-2687506

closes odoo/odoo#94580

Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
2022-06-30 18:52:01 +02:00

68 lines
2.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import json
from werkzeug.urls import url_encode
from odoo import tests
from odoo.tools import mute_logger
@tests.tagged('post_install', '-at_install')
class TestControllers(tests.HttpCase):
@mute_logger('odoo.addons.http_routing.models.ir_http', 'odoo.http')
def test_last_created_pages_autocompletion(self):
self.authenticate("admin", "admin")
Page = self.env['website.page']
last_5_url_edited = []
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
suggested_links_url = base_url + '/website/get_suggested_links'
for i in range(0, 10):
new_page = Page.create({
'name': 'Generic',
'type': 'qweb',
'arch': '''
<div>content</div>
''',
'key': "test.generic_view-%d" % i,
'url': "/generic-%d" % i,
'is_published': True,
})
if i % 2 == 0:
# mark as old
new_page._write({'write_date': '2020-01-01'})
else:
last_5_url_edited.append(new_page.url)
res = self.opener.post(url=suggested_links_url, json={'params': {'needle': '/'}})
resp = json.loads(res.content)
assert 'result' in resp
suggested_links = resp['result']
last_modified_history = next(o for o in suggested_links['others'] if o["title"] == "Last modified pages")
last_modified_values = map(lambda o: o['value'], last_modified_history['values'])
matching_pages = set(map(lambda o: o['value'], suggested_links['matching_pages']))
self.assertEqual(set(last_modified_values), set(last_5_url_edited) - matching_pages)
def test_02_client_action_iframe_url(self):
base_url = self.base_url()
urls = [
'/', # Homepage URL (special case)
'/contactus', # Regular website.page URL
'/website/info', # Controller (!!also testing multi slashes URL!!)
'/contactus?name=testing', # Query string URL
]
for url in urls:
resp = self.url_open(f'/@{url}')
self.assertEqual(resp.url, base_url + url, "Public user should have landed in the frontend")
self.authenticate("admin", "admin")
for url in urls:
resp = self.url_open(f'/@{url}')
backend_params = url_encode(dict(action='website.website_preview', path=url))
self.assertEqual(
resp.url, f'{base_url}/web#{backend_params}',
"Internal user should have landed in the backend")