[FIX] web: always add usercontext to legacy action
In the new web client architecture, the user context is added to server requests through the ORM service and is therefore not needed in the action context. Thus the commit 7354d16 has removed it from the action. Before the new webclient architecture, the user context was always prepended to the action context. So this commit reintroduces it for the legacy views and client actions through their proper adapters. closes odoo/odoo#78685 X-original-commit: 7975674166a3d8fa9cd8714adab769a7fd681368 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Signed-off-by: Bruno Boi <brboi@users.noreply.github.com>
This commit is contained in:
@@ -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__;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user