diff --git a/addons/web/static/src/legacy/legacy_client_actions.js b/addons/web/static/src/legacy/legacy_client_actions.js index b649b537653..37334e64bb7 100644 --- a/addons/web/static/src/legacy/legacy_client_actions.js +++ b/addons/web/static/src/legacy/legacy_client_actions.js @@ -1,6 +1,7 @@ /** @odoo-module **/ import { registry } from "@web/core/registry"; +import { useService } from "@web/core/utils/hooks"; import { action_registry as legacyActionRegistry } from "web.core"; import Widget from "web.Widget"; import { setScrollPosition } from "../core/utils/scrolling"; @@ -36,7 +37,14 @@ function registerClientAction(name, action) { options[key] = this.props[key]; } } - this.widgetArgs = [this.props.action, options]; + + // always add user context to the action context + this.user = useService("user"); + const clientAction = Object.assign({}, this.props.action, { + context: Object.assign({}, this.user.context, this.props.action.context), + }); + + this.widgetArgs = [clientAction, options]; this.widget = this.props.state && this.props.state.__legacy_widget__; this.onReverseBreadcrumb = this.props.state && this.props.state.__on_reverse_breadcrumb__; diff --git a/addons/web/static/src/legacy/legacy_views.js b/addons/web/static/src/legacy/legacy_views.js index 48876eed3e2..02f04fdb50d 100644 --- a/addons/web/static/src/legacy/legacy_views.js +++ b/addons/web/static/src/legacy/legacy_views.js @@ -51,9 +51,15 @@ function registerView(name, LegacyView) { searchPanel = globalState.searchPanel; } + // always add user context to the action context + this.user = useService("user"); + const action = Object.assign({}, this.props.action, { + context: Object.assign({}, this.user.context, this.props.action.context), + }); + const { actionFlags, breadcrumbs = [] } = this.env.config; this.viewParams = Object.assign({}, actionFlags, { - action: this.props.action, + action, // legacy views automatically add the last part of the breadcrumbs breadcrumbs: breadcrumbsToLegacy(breadcrumbs), modelName: this.props.resModel, diff --git a/addons/web/static/tests/webclient/actions/legacy_tests.js b/addons/web/static/tests/webclient/actions/legacy_tests.js index bf6aa011919..6dafcca704d 100644 --- a/addons/web/static/tests/webclient/actions/legacy_tests.js +++ b/addons/web/static/tests/webclient/actions/legacy_tests.js @@ -10,7 +10,7 @@ import { makeTestEnv } from "../../helpers/mock_env"; import { createWebClient, doAction, getActionManagerServerData } from "./../helpers"; import makeTestEnvironment from "web.test_env"; -import { ClientActionAdapter } from "@web/legacy/action_adapters"; +import { ClientActionAdapter, ViewAdapter } from "@web/legacy/action_adapters"; import { makeLegacyCrashManagerService } from "@web/legacy/utils"; import { useDebugCategory } from "@web/core/debug/debug_context"; import { ErrorDialog } from "@web/core/errors/error_dialogs"; @@ -409,4 +409,35 @@ QUnit.module("ActionManager", (hooks) => { assert.verifySteps(["do action"]); delete SystrayMenu.Items.FakeSystrayItemWidget; }); + + QUnit.test("usercontext always added to legacy actions", async (assert) => { + assert.expect(8); + core.action_registry.add("testClientAction", AbstractAction); + registerCleanup(() => delete core.action_registry.map.testClientAction); + patchWithCleanup(ClientActionAdapter.prototype, { + setup() { + assert.step("ClientActionAdapter"); + const action = { ...this.props.widgetArgs[0] }; + const originalAction = JSON.parse(action._originalAction); + assert.deepEqual(originalAction.context, undefined); + assert.deepEqual(action.context, this.env.services.user.context); + this._super(); + }, + }); + patchWithCleanup(ViewAdapter.prototype, { + setup() { + assert.step("ViewAdapter"); + const action = { ...this.props.viewParams.action }; + const originalAction = JSON.parse(action._originalAction); + assert.deepEqual(originalAction.context, undefined); + assert.deepEqual(action.context, this.env.services.user.context); + this._super(); + }, + }); + const webClient = await createWebClient({ serverData }); + await doAction(webClient, "testClientAction"); + assert.verifySteps(["ClientActionAdapter"]); + await doAction(webClient, 1); + assert.verifySteps(["ViewAdapter"]); + }); });