[FIX] knowledge: make removeContextUserInfo a web asset
removeContextUserInfo was a Spreadsheet asset, which is not a dependency of Knowledge. In order to make this feature available for all modules, it is moved in web as an object util, that needs to be used alongside the user service in order to dynamically remove user context information (no hardcoding). Task-3017349 closes odoo/odoo#104304 X-original-commit: fd88fc1bbad4c0cdb44cf634b6a5621eb7597e0d Related: odoo/enterprise#33322 Signed-off-by: David Beguin (dbe) <dbe@odoo.com>
This commit is contained in:
@@ -3,25 +3,12 @@
|
||||
import { LoadableDataSource } from "./data_source";
|
||||
import { Domain } from "@web/core/domain";
|
||||
import { LoadingDataError } from "@spreadsheet/o_spreadsheet/errors";
|
||||
import { omit } from "@web/core/utils/objects";
|
||||
|
||||
/**
|
||||
* @typedef {import("@spreadsheet/data_sources/metadata_repository").Field} Field
|
||||
*/
|
||||
|
||||
/**
|
||||
* Remove user specific info from the context
|
||||
* @param {Object} context
|
||||
* @returns {Object}
|
||||
*/
|
||||
function removeContextUserInfo(context) {
|
||||
context = { ...context };
|
||||
delete context.allowed_company_ids;
|
||||
delete context.tz;
|
||||
delete context.lang;
|
||||
delete context.uid;
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} OdooModelMetaData
|
||||
* @property {string} resModel
|
||||
@@ -41,9 +28,7 @@ export class OdooViewsDataSource extends LoadableDataSource {
|
||||
this._metaData = JSON.parse(JSON.stringify(params.metaData));
|
||||
/** @protected */
|
||||
this._initialSearchParams = JSON.parse(JSON.stringify(params.searchParams));
|
||||
this._initialSearchParams.context = removeContextUserInfo(
|
||||
this._initialSearchParams.context
|
||||
);
|
||||
this._initialSearchParams.context = omit(this._initialSearchParams.context || {}, ...Object.keys(this._orm.user.context));
|
||||
/** @private */
|
||||
this._customDomain = this._initialSearchParams.domain;
|
||||
}
|
||||
|
||||
@@ -252,8 +252,6 @@ QUnit.module("spreadsheet > list plugin", {}, () => {
|
||||
QUnit.test("user context is combined with list context to fetch data", async function (assert) {
|
||||
const context = {
|
||||
allowed_company_ids: [15],
|
||||
default_stage_id: 5,
|
||||
search_default_stage_id: 5,
|
||||
tz: "bx",
|
||||
lang: "FR",
|
||||
uid: 4,
|
||||
|
||||
@@ -228,8 +228,6 @@ QUnit.module("spreadsheet > pivot plugin", {}, () => {
|
||||
async function (assert) {
|
||||
const context = {
|
||||
allowed_company_ids: [15],
|
||||
default_stage_id: 5,
|
||||
search_default_stage_id: 5,
|
||||
tz: "bx",
|
||||
lang: "FR",
|
||||
uid: 4,
|
||||
|
||||
@@ -22,6 +22,25 @@ export function deepCopy(obj) {
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a shallow copy of object with every property in properties removed
|
||||
* if present in object.
|
||||
*
|
||||
* @param {Object} object
|
||||
* @param {...string} properties
|
||||
* @returns {Object}
|
||||
*/
|
||||
export function omit(object, ...properties) {
|
||||
const result = {};
|
||||
const propertiesSet = new Set(properties);
|
||||
for (const key in object) {
|
||||
if (!propertiesSet.has(key)) {
|
||||
result[key] = object[key];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {T}
|
||||
* @param {T} object
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { pick, shallowEqual } from "@web/core/utils/objects";
|
||||
import { omit, pick, shallowEqual } from "@web/core/utils/objects";
|
||||
|
||||
QUnit.module("utils", () => {
|
||||
QUnit.module("Objects");
|
||||
|
||||
QUnit.test("omit", function (assert) {
|
||||
assert.deepEqual(omit({}), {});
|
||||
assert.deepEqual(omit({}, "a"), {});
|
||||
assert.deepEqual(omit({ a: 1 }), { a: 1 });
|
||||
assert.deepEqual(omit({ a: 1 }, "a"), {});
|
||||
assert.deepEqual(omit({ a: 1, b: 2 }, "c", "a"), { b: 2 });
|
||||
assert.deepEqual(omit({ a: 1, b: 2 }, "b", "c"), { a: 1 });
|
||||
});
|
||||
|
||||
QUnit.test("pick", function (assert) {
|
||||
assert.deepEqual(pick({}), {});
|
||||
assert.deepEqual(pick({}, "a"), {});
|
||||
|
||||
Reference in New Issue
Block a user