Before this revision, when you pass `context` in the arguments of a JSON routes, this one gets automatically injected in the environment context. This is not the case for regular HTTP routes. It makes sense to propagate the context for the JSONRPC protocol, JSON routes used by the backend, such as `call_kw`, but it doesn't make sense to pass this context automatically for any other kind of routes, such as front-end routes or routes used by custom Javascript widgets. This change brings a more unified behavior for routes of types HTTP and JSON. In addition, most developers were not aware of this "feautre", that passing `context` in the arguments of a JSON route leaded to the injection of this context in the environment context. This is actually reflected by the diff size this changes required, only a dozens of routes needed to be adapted, to manually add the context in their route arguments and to inject it in their environment context. closes odoo/odoo#121726 X-original-commit: a7a5655631e6d5b05fd2ba3d0c80617aae6d9cfe Related: odoo/enterprise#41229 Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from psycopg2 import IntegrityError
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
|
|
|
|
class OnboardingController(http.Controller):
|
|
@http.route('/onboarding/<string:route_name>', auth='user', type='json')
|
|
def get_onboarding_data(self, route_name=None, context=None):
|
|
if not request.env.user.has_group('base.group_system'):
|
|
return {}
|
|
|
|
if context:
|
|
request.update_context(**context)
|
|
onboarding = request.env['onboarding.onboarding'].search([('route_name', '=', route_name)])
|
|
if onboarding:
|
|
try:
|
|
progress = onboarding._search_or_create_progress()
|
|
except IntegrityError: # Another worker created the record at the same time
|
|
return {'code': 503} # Temporarily unavailable - Invites client to try again
|
|
|
|
if not progress.is_onboarding_closed:
|
|
# JS implementation of the onboarding panel expects this data structure
|
|
return {
|
|
'html': request.env['ir.qweb']._render(
|
|
'onboarding.onboarding_panel', onboarding._prepare_rendering_values())
|
|
}
|
|
|
|
return {}
|