From a1e7e3ef7e764062a3e5bf9840c55fe1bb4da578 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Thu, 3 Nov 2022 07:49:39 +0000 Subject: [PATCH] [FIX] web, *: tours correctly break when there are missing deps *: im_livechat, website_livechat, website_slides In c989ff3, the odoo module system has been changed so that it now errors out when modules are defined but have missing dependencies and cannot run. Unfortunately, tours are defined in a single bundle, `assets_tests`, and this bundle is used everywhere tours need to run, but some of these tours depend on modules that only exist in the backend and others on modules that only exist in the frontend. We don't want to break up the `assets_tests` bundle as this creates a poor developer experience, and so the solution that was chosen at the time is that when the `assets_tests` bundle is defined, we ignore all module dependency errors. This causes a problem however, which is that if a module dependency is missing in production code, the page will be broken by the module error (which is expected) but if the `assets_tests` are present, which is the case when running tours and tests, then it won't, meaning the tours will happily pass despite the application being broken, which is unacceptable. This commit fixes this issue by replacing the assets_test bundle by a new bundle (`__assets_tests_call__`) within which all module dependency errors are ignored, which lets dependency errors that are hapenning in other bundles (ie in production code) happen even during the tests. Because of this, this commit also fixes the dependency errors that already existed but were previously silent: - for im_livechat and website_livechat, the code was refactored to use the standard mechanism that we use elsewhere to add data directly in the page: we store the data in __session_info__, and the module that exposes that data is always present, instead of having a module that's defined conditionally, which causes issues when non-conditional modules depend on it. - in web, the `report_assets_common` bundle was used alongside `assets_common` but without `assets_frontend` or `assets_backend`. Reports do not need any js and it appears that it already had what it needed as far as css is concerned except for one fontawesome override. Code was changed so that the js from the bundle is not included and it reports no longer use `assets_common`, the js part of the bundle is no longer used. - in website_slides, the `slide_embed_assets` bundle is used alongside `assets_common` without using `assets_frontend` or `assets_backend` which is required for `assets_common` to function, the approach here was to simply take the files from `assets_common` and remove the files that were causing issues. This bundle should be trimmed at some point, as it contains way too many things that it does not need. The file colors.js was also moved to core, as it isn't graph specific and was causing dependency issues with a field that was importing it. Fields shouldn't depend on files in specific views' directory. closes odoo/odoo#104794 Related: odoo/enterprise#33909 Signed-off-by: Aaron Bohy (aab) --- addons/im_livechat/__manifest__.py | 1 + .../im_livechat/static/src/livechat_data.js | 6 + addons/im_livechat/static/src/public/main.js | 2 +- .../im_livechat/static/src/public/session.js | 2 +- .../views/im_livechat_channel_templates.xml | 21 +-- .../views/im_livechat_chatbot_templates.xml | 12 +- addons/web/__manifest__.py | 11 +- addons/web/static/src/boot.js | 20 ++- .../{views/graph => core/colors}/colors.js | 4 + .../journal_dashboard_graph_field.js | 2 +- .../static/src/views/graph/graph_renderer.js | 2 +- .../static/tests/ignore_missing_deps_start.js | 4 + .../static/tests/ignore_missing_deps_stop.js | 1 + .../static/tests/views/graph_view_tests.js | 2 +- addons/web/views/report_templates.xml | 21 --- addons/web/views/webclient_templates.xml | 5 +- .../views/website_livechat.xml | 2 +- addons/website_slides/__manifest__.py | 131 ++++++++++++++++++ .../website_slides_templates_lesson_embed.xml | 9 +- 19 files changed, 189 insertions(+), 69 deletions(-) create mode 100644 addons/im_livechat/static/src/livechat_data.js rename addons/web/static/src/{views/graph => core/colors}/colors.js (91%) create mode 100644 addons/web/static/tests/ignore_missing_deps_start.js create mode 100644 addons/web/static/tests/ignore_missing_deps_stop.js diff --git a/addons/im_livechat/__manifest__.py b/addons/im_livechat/__manifest__.py index e422cd154cc..9f06b716e48 100644 --- a/addons/im_livechat/__manifest__.py +++ b/addons/im_livechat/__manifest__.py @@ -87,6 +87,7 @@ Help your customers with this chat, and analyse their feedback. ], 'im_livechat.assets_public_livechat': [ ('include', 'mail.assets_core_messaging'), + 'im_livechat/static/src/livechat_data.js', 'im_livechat/static/src/legacy/models/*', 'im_livechat/static/src/legacy/widgets/*', 'im_livechat/static/src/legacy/widgets/*/*', diff --git a/addons/im_livechat/static/src/livechat_data.js b/addons/im_livechat/static/src/livechat_data.js new file mode 100644 index 00000000000..aab589fa9bb --- /dev/null +++ b/addons/im_livechat/static/src/livechat_data.js @@ -0,0 +1,6 @@ +/** @odoo-module */ + +import { session } from "@web/session"; + +const { isAvailable, serverUrl, options } = session.livechatData || {}; +export { isAvailable, serverUrl, options }; diff --git a/addons/im_livechat/static/src/public/main.js b/addons/im_livechat/static/src/public/main.js index eb9ac3f0866..f9f6ed4ec71 100644 --- a/addons/im_livechat/static/src/public/main.js +++ b/addons/im_livechat/static/src/public/main.js @@ -1,7 +1,7 @@ /** @odoo-module **/ import { publicLivechatService } from '@im_livechat/services/public_livechat_service'; -import { isAvailable, options, serverUrl } from 'im_livechat.loaderData'; +import { isAvailable, options, serverUrl } from '@im_livechat/livechat_data'; import { messagingService } from '@mail/services/messaging_service'; import { makeMessagingToLegacyEnv } from '@mail/utils/make_messaging_to_legacy_env'; diff --git a/addons/im_livechat/static/src/public/session.js b/addons/im_livechat/static/src/public/session.js index f963661604c..850087f38f5 100644 --- a/addons/im_livechat/static/src/public/session.js +++ b/addons/im_livechat/static/src/public/session.js @@ -1,7 +1,7 @@ odoo.define('web.session', function (require) { const Session = require('web.Session'); - const { serverUrl } = require('im_livechat.loaderData'); + const { serverUrl } = require('@im_livechat/livechat_data'); return new Session(undefined, serverUrl, { use_cors: true }); }); diff --git a/addons/im_livechat/views/im_livechat_channel_templates.xml b/addons/im_livechat/views/im_livechat_channel_templates.xml index 0d1e1bd4304..a15a7b82908 100644 --- a/addons/im_livechat/views/im_livechat_channel_templates.xml +++ b/addons/im_livechat/views/im_livechat_channel_templates.xml @@ -81,23 +81,24 @@