From da257e9d572047617cdfaac33fbe47983e8ab30d Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 23 Oct 2023 15:55:52 +0200 Subject: [PATCH] [IMP] web: save a has_group rpc at webclient startup ...when voip addon is installed. We want to avoid predictable rpcs that are systematically done at webclient startup. In particular, the voip service needs to know if the user has group "base.group_user", which produces a rpc when the service is started. To avoid this, this commit adds the information in the page directly. As this information is also useful at other places (even though it's not at startup), we directly add it to the groupCache of the user service (and we do the same for the "base.group_system" group, which we also receive in the page). closes odoo/odoo#139477 Signed-off-by: Aaron Bohy (aab) --- addons/web/models/ir_http.py | 4 +++- addons/web/static/src/core/user_service.js | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/web/models/ir_http.py b/addons/web/models/ir_http.py index 0bb015d0c41..9b57e70be3a 100644 --- a/addons/web/models/ir_http.py +++ b/addons/web/models/ir_http.py @@ -86,10 +86,12 @@ class Http(models.AbstractModel): mods = odoo.conf.server_wide_modules or [] if request.db: mods = list(request.registry._init_modules) + mods + is_internal_user = user.has_group('base.group_user') session_info = { "uid": session_uid, "is_system": user._is_system() if session_uid else False, "is_admin": user._is_admin() if session_uid else False, + "is_internal_user": is_internal_user, "user_context": user_context, "db": self.env.cr.dbname, "user_settings": self.env['res.users.settings']._find_or_create_for_user(user)._res_users_settings_format(), @@ -119,7 +121,7 @@ class Http(models.AbstractModel): } if request.session.debug: session_info['bundle_params']['debug'] = request.session.debug - if self.env.user.has_group('base.group_user'): + if is_internal_user: # the following is only useful in the context of a webclient bootstrapping # but is still included in some other calls (e.g. '/web/session/authenticate') # to avoid access errors and unnecessary information, it is only included for users diff --git a/addons/web/static/src/core/user_service.js b/addons/web/static/src/core/user_service.js index 08f175d1117..5feade2beac 100644 --- a/addons/web/static/src/core/user_service.js +++ b/addons/web/static/src/core/user_service.js @@ -19,6 +19,8 @@ export const userService = { kwargs: { context }, }); }); + groupCache.cache["base.group_user"] = session.is_internal_user; + groupCache.cache["base.group_system"] = session.is_system; const accessRightCache = new Cache((model, operation) => { const url = `/web/dataset/call_kw/${model}/check_access_rights`; return rpc(url, {