[IMP] web, *: read session information from a module
* google_recaptcha, mail, partner_autocomplete, point_of_sale, website Now, to read session information, the module "@web/session" must be imported. Not that, there is also the user service with all the user information. closes odoo/odoo#73201 Related: odoo/enterprise#19434 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -4,6 +4,7 @@ odoo.define('google_recaptcha.ReCaptchaV3', function (require) {
|
||||
const ajax = require('web.ajax');
|
||||
const Class = require('web.Class');
|
||||
const core = require('web.core');
|
||||
const { session } = require('@web/session');
|
||||
|
||||
const _t = core._t;
|
||||
|
||||
@@ -12,7 +13,7 @@ const ReCaptcha = Class.extend({
|
||||
* @override
|
||||
*/
|
||||
init: function () {
|
||||
this._publicKey = odoo.session_info.recaptcha_public_key;
|
||||
this._publicKey = session.recaptcha_public_key;
|
||||
},
|
||||
/**
|
||||
* Loads the recaptcha libraries.
|
||||
|
||||
@@ -9,6 +9,7 @@ import { legacyExtraNextTick, patchWithCleanup } from "@web/../tests/helpers/uti
|
||||
import { createWebClient, doAction } from "@web/../tests/webclient/helpers";
|
||||
import { patch, unpatch } from 'web.utils';
|
||||
import { registry } from "@web/core/registry";
|
||||
import { session } from '@web/session';
|
||||
|
||||
let serverData;
|
||||
|
||||
@@ -394,7 +395,7 @@ QUnit.test("activity view: no group_by_menu and no comparison_menu", async funct
|
||||
}
|
||||
};
|
||||
|
||||
patchWithCleanup(odoo.session_info.user_context, { lang: "zz_ZZ" });
|
||||
patchWithCleanup(session.user_context, { lang: "zz_ZZ" });
|
||||
|
||||
const webClient = await createWebClient({ serverData, mockRPC , legacyParams: {withLegacyMockServer: true}});
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
import { session } from "@web/session";
|
||||
|
||||
export const companyAutocompleteService = {
|
||||
dependencies: ["orm", "company"],
|
||||
|
||||
start(env, { orm, company }) {
|
||||
if (odoo.session_info.iap_company_enrich) {
|
||||
if (session.iap_company_enrich) {
|
||||
const currentCompanyId = company.currentCompany.id;
|
||||
orm.silent.call("res.company", "iap_enrich_auto", [currentCompanyId], {});
|
||||
}
|
||||
|
||||
@@ -28,11 +28,11 @@
|
||||
<script type="text/javascript">
|
||||
var odoo = <t t-out="json.dumps({
|
||||
'csrf_token': request.csrf_token(None),
|
||||
'session_info': session_info,
|
||||
'__session_info__': session_info,
|
||||
'login_number': login_number,
|
||||
'debug': debug,
|
||||
})"/>;
|
||||
odoo.loadTemplatesPromise = fetch(`/web/webclient/qweb/${odoo.session_info.cache_hashes.qweb}?bundle=web.assets_qweb`).then(doc => doc.text());
|
||||
odoo.loadTemplatesPromise = fetch(`/web/webclient/qweb/${odoo.__session_info__.cache_hashes.qweb}?bundle=web.assets_qweb`).then(doc => doc.text());
|
||||
</script>
|
||||
|
||||
<t t-call="point_of_sale.assets_common"/>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<script type="text/javascript">
|
||||
var odoo = <t t-out="json.dumps({
|
||||
'csrf_token': request.csrf_token(None),
|
||||
'session_info': session_info,
|
||||
'__session_info__': session_info,
|
||||
'debug': debug,
|
||||
})"/>;
|
||||
</script>
|
||||
|
||||
@@ -57,6 +57,7 @@ This module provides the core of the Odoo Web Client.
|
||||
'web/static/lib/es6-promise/es6-promise-polyfill.js',
|
||||
'web/static/src/legacy/js/promise_extension.js',
|
||||
'web/static/src/boot.js',
|
||||
'web/static/src/session.js',
|
||||
],
|
||||
'web.assets_common': [
|
||||
('include', 'web._assets_helpers'),
|
||||
@@ -73,6 +74,7 @@ This module provides the core of the Odoo Web Client.
|
||||
('remove', 'web/static/lib/es6-promise/es6-promise-polyfill.js'),
|
||||
('remove', 'web/static/src/legacy/js/promise_extension.js'),
|
||||
('remove', 'web/static/src/boot.js'),
|
||||
('remove', 'web/static/src/session.js'),
|
||||
],
|
||||
'web.assets_backend': [
|
||||
('include', 'web._assets_helpers'),
|
||||
|
||||
@@ -2,17 +2,17 @@
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
import { ProfilingItem } from "./profiling_item";
|
||||
import { session } from "@web/session";
|
||||
|
||||
const { core } = owl;
|
||||
|
||||
const profilingService = {
|
||||
dependencies: ["orm"],
|
||||
start(env, { orm }) {
|
||||
const sessionInfo = odoo.session_info;
|
||||
const state = {
|
||||
session: sessionInfo.profile_session || false,
|
||||
collectors: sessionInfo.profile_collectors || ["sql", "traces_async"],
|
||||
params: sessionInfo.profile_params || {},
|
||||
session: session.profile_session || false,
|
||||
collectors: session.profile_collectors || ["sql", "traces_async"],
|
||||
params: session.profile_params || {},
|
||||
get isEnabled() {
|
||||
return Boolean(state.session);
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { formatFloat, humanNumber, parseFloat, InvalidNumberError } from "./numbers";
|
||||
import { session } from "@web/session";
|
||||
|
||||
/**
|
||||
* Formats a value as a currency.
|
||||
@@ -20,7 +21,7 @@ export function formatCurrency(value, cid, options = {}) {
|
||||
if (value === false) {
|
||||
return "";
|
||||
}
|
||||
const currency = odoo.session_info.currencies[cid];
|
||||
const currency = session.currencies[cid];
|
||||
const { noSymbol } = options || {};
|
||||
const digits = (currency && currency.digits) || options.digits;
|
||||
|
||||
@@ -56,9 +57,9 @@ export function parseCurrency(value, options = {}) {
|
||||
}
|
||||
let currency;
|
||||
if (options.currencyId) {
|
||||
currency = odoo.session_info.currencies[options.currencyId];
|
||||
currency = session.currencies[options.currencyId];
|
||||
} else {
|
||||
currency = Object.values(odoo.session_info.currencies)[0];
|
||||
currency = Object.values(session.currencies)[0];
|
||||
}
|
||||
const symbolIndex = values.findIndex((v) => v === currency.symbol);
|
||||
if (symbolIndex === -1) {
|
||||
|
||||
@@ -5,11 +5,12 @@ import { registry } from "../registry";
|
||||
import { strftimeToLuxonFormat } from "./dates";
|
||||
import { localization } from "./localization";
|
||||
import { translatedTerms, _t } from "./translation";
|
||||
import { session } from "@web/session";
|
||||
|
||||
export const localizationService = {
|
||||
dependencies: ["user"],
|
||||
start: async (env, { user }) => {
|
||||
const cacheHashes = odoo.session_info.cache_hashes;
|
||||
const cacheHashes = session.cache_hashes;
|
||||
const translationsHash = cacheHashes.translations || new Date().getTime().toString();
|
||||
const lang = user.lang || null;
|
||||
let url = `/web/webclient/translations/${translationsHash}`;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from "./registry";
|
||||
import { session } from "@web/session";
|
||||
|
||||
export const userService = {
|
||||
dependencies: ["rpc"],
|
||||
async: ["hasGroup"],
|
||||
start(env, { rpc }) {
|
||||
const sessionInfo = odoo.session_info;
|
||||
const groupProms = {};
|
||||
|
||||
const context = {
|
||||
...sessionInfo.user_context,
|
||||
uid: sessionInfo.uid,
|
||||
...session.user_context,
|
||||
uid: session.uid,
|
||||
};
|
||||
return {
|
||||
get context() {
|
||||
@@ -37,13 +37,13 @@ export const userService = {
|
||||
}
|
||||
return groupProms[group];
|
||||
},
|
||||
name: sessionInfo.name,
|
||||
userName: sessionInfo.username,
|
||||
isAdmin: sessionInfo.is_admin,
|
||||
isSystem: sessionInfo.is_system,
|
||||
partnerId: sessionInfo.partner_id,
|
||||
home_action_id: sessionInfo.home_action_id,
|
||||
showEffect: sessionInfo.show_effect,
|
||||
name: session.name,
|
||||
userName: session.username,
|
||||
isAdmin: session.is_admin,
|
||||
isSystem: session.is_system,
|
||||
partnerId: session.partner_id,
|
||||
home_action_id: session.home_action_id,
|
||||
showEffect: session.show_effect,
|
||||
get userId() {
|
||||
return context.uid;
|
||||
},
|
||||
@@ -55,10 +55,10 @@ export const userService = {
|
||||
},
|
||||
get db() {
|
||||
const res = {
|
||||
name: sessionInfo.db,
|
||||
name: session.db,
|
||||
};
|
||||
if ("dbuuid" in sessionInfo) {
|
||||
res.uuid = sessionInfo.dbuuid;
|
||||
if ("dbuuid" in session) {
|
||||
res.uuid = session.dbuuid;
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@ var core = require('web.core');
|
||||
var session = require('web.session');
|
||||
var utils = require('web.utils');
|
||||
var Widget = require('web.Widget');
|
||||
const { session: sessionInfo } = require('@web/session');
|
||||
|
||||
var QWeb = core.qweb;
|
||||
|
||||
@@ -25,12 +26,12 @@ var DebugManager = Widget.extend({
|
||||
var debug = odoo.debug;
|
||||
this.debug_mode = debug;
|
||||
this.debug_mode_help = debug && debug !== '1' ? ' (' + debug + ')' : '';
|
||||
this.profile_session = odoo.session_info && odoo.session_info.profile_session || false;
|
||||
this.profile_collectors = odoo.session_info && odoo.session_info.profile_collectors;
|
||||
this.profile_session = sessionInfo.profile_session || false;
|
||||
this.profile_collectors = sessionInfo.profile_collectors;
|
||||
if (! Array.isArray(this.profile_collectors)) {
|
||||
this.profile_collectors = ['sql', 'traces_async']; // use default value when not defined in session.
|
||||
}
|
||||
this.profile_params = odoo.session_info && odoo.session_info.profile_params || {};
|
||||
this.profile_params = sessionInfo.profile_params || {};
|
||||
},
|
||||
start: function () {
|
||||
core.bus.on('rpc:result', this, function (req, resp) {
|
||||
|
||||
@@ -7,6 +7,7 @@ var core = require('web.core');
|
||||
var time = require('web.time');
|
||||
var download = require('web.download');
|
||||
var contentdisposition = require('web.contentdisposition');
|
||||
const { session } = require('@web/session');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
@@ -437,7 +438,7 @@ var loadAsset = (function () {
|
||||
if (cache[xmlId]) {
|
||||
return cache[xmlId];
|
||||
}
|
||||
context = _.extend({}, odoo.session_info.user_context, context);
|
||||
context = _.extend({}, session.user_context, context);
|
||||
const params = {
|
||||
args: [xmlId, {
|
||||
debug: config.isDebug()
|
||||
|
||||
@@ -6,6 +6,7 @@ var concurrency = require('web.concurrency');
|
||||
var core = require('web.core');
|
||||
var mixins = require('web.mixins');
|
||||
var utils = require('web.utils');
|
||||
const { session } = require('@web/session');
|
||||
|
||||
var _t = core._t;
|
||||
var qweb = core.qweb;
|
||||
@@ -258,7 +259,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
|
||||
* @returns {Promise} promise indicating the session is done reloading
|
||||
*/
|
||||
session_reload: function () {
|
||||
var result = _.extend({}, window.odoo.session_info);
|
||||
var result = _.extend({}, session);
|
||||
_.extend(this, result);
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
export const session = odoo.__session_info__ || {};
|
||||
delete odoo.__session_info__;
|
||||
@@ -4,6 +4,7 @@ import { makeEnv, startServices } from "./env";
|
||||
import { legacySetupProm } from "./legacy/legacy_setup";
|
||||
import { mapLegacyEnvToWowlEnv } from "./legacy/utils";
|
||||
import { processTemplates } from "./core/assets";
|
||||
import { session } from "@web/session";
|
||||
|
||||
const { mount, utils } = owl;
|
||||
const { whenReady } = utils;
|
||||
@@ -17,13 +18,11 @@ const { whenReady } = utils;
|
||||
* @param {owl.Component} Webclient
|
||||
*/
|
||||
export async function startWebClient(Webclient) {
|
||||
// delete (odoo as any).session_info; // FIXME: some legacy code rely on this (e.g. ajax.js)
|
||||
const sessionInfo = odoo.session_info;
|
||||
odoo.info = {
|
||||
db: sessionInfo.db,
|
||||
server_version: sessionInfo.server_version,
|
||||
server_version_info: sessionInfo.server_version_info,
|
||||
isEnterprise: sessionInfo.server_version_info.slice(-1)[0] === "e",
|
||||
db: session.db,
|
||||
server_version: session.server_version,
|
||||
server_version_info: session.server_version_info,
|
||||
isEnterprise: session.server_version_info.slice(-1)[0] === "e",
|
||||
};
|
||||
odoo.isReady = false;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { symmetricalDifference } from "../core/utils/arrays";
|
||||
import { session } from "@web/session";
|
||||
|
||||
function parseCompanyIds(cidsFromHash) {
|
||||
const cids = [];
|
||||
@@ -15,7 +16,7 @@ function parseCompanyIds(cidsFromHash) {
|
||||
}
|
||||
|
||||
function computeAllowedCompanyIds(cids) {
|
||||
const { user_companies } = odoo.session_info;
|
||||
const { user_companies } = session;
|
||||
let allowedCompanyIds = cids || [];
|
||||
const availableCompaniesFromSession = user_companies.allowed_companies;
|
||||
const notReallyAllowedCompanies = allowedCompanyIds.filter(
|
||||
@@ -44,7 +45,7 @@ export const companyService = {
|
||||
cookie.setCookie("cids", stringCIds);
|
||||
|
||||
user.updateContext({ allowed_company_ids: allowedCompanyIds });
|
||||
const availableCompanies = odoo.session_info.user_companies.allowed_companies;
|
||||
const availableCompanies = session.user_companies.allowed_companies;
|
||||
|
||||
return {
|
||||
availableCompanies,
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
|
||||
import { browser } from "../core/browser/browser";
|
||||
import { registry } from "../core/registry";
|
||||
import { session } from "@web/session";
|
||||
|
||||
const loadMenusUrl = `/web/webclient/load_menus`;
|
||||
|
||||
function makeFetchLoadMenus() {
|
||||
const cacheHashes = odoo.session_info.cache_hashes;
|
||||
const cacheHashes = session.cache_hashes;
|
||||
let loadMenusHash = cacheHashes.load_menus || new Date().getTime().toString();
|
||||
return async function fetchLoadMenus(reload) {
|
||||
if (reload) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Dialog } from "../../core/dialog/dialog";
|
||||
import { browser } from "../../core/browser/browser";
|
||||
import { registry } from "../../core/registry";
|
||||
import { _lt } from "../../core/l10n/translation";
|
||||
import { session } from "@web/session";
|
||||
|
||||
function documentationItem(env) {
|
||||
const documentationURL = "https://www.odoo.com/documentation/14.0";
|
||||
@@ -20,7 +21,7 @@ function documentationItem(env) {
|
||||
}
|
||||
|
||||
function supportItem(env) {
|
||||
const url = odoo.session_info.support_url;
|
||||
const url = session.support_url;
|
||||
return {
|
||||
type: "item",
|
||||
id: "support",
|
||||
|
||||
@@ -5,6 +5,7 @@ import { localization } from "@web/core/l10n/localization";
|
||||
import { patch, unpatch } from "@web/core/utils/patch";
|
||||
import { defaultLocalization } from "../../helpers/mock_services";
|
||||
import { patchWithCleanup } from "@web/../tests/helpers/utils";
|
||||
import { session } from "@web/session";
|
||||
|
||||
QUnit.module("utils", (hooks) => {
|
||||
hooks.beforeEach(() => {
|
||||
@@ -34,7 +35,7 @@ QUnit.module("utils", (hooks) => {
|
||||
QUnit.test("parseCurrency", function (assert) {
|
||||
assert.expect(17);
|
||||
|
||||
patchWithCleanup(odoo.session_info, {
|
||||
patchWithCleanup(session, {
|
||||
currencies: {
|
||||
1: {
|
||||
digits: [69, 2],
|
||||
|
||||
@@ -5,16 +5,17 @@ odoo.define("web.SessionOverrideForTests", (require) => {
|
||||
// So if a test does a session_reload, it will merge the odoo global of that test
|
||||
// into the session, and will alter every subsequent test of the suite.
|
||||
// Obviously, we don't want that, ever.
|
||||
const initialOdoo = Object.assign({}, odoo);
|
||||
const { session: sessionInfo } = require("@web/session");
|
||||
const initialSessionInfo = Object.assign({}, sessionInfo);
|
||||
const Session = require("web.Session");
|
||||
const { patch } = require("@web/core/utils/patch");
|
||||
patch(Session.prototype, "web.SessionTestPatch", {
|
||||
async session_reload() {
|
||||
const oldOdoo = odoo;
|
||||
odoo = initialOdoo;
|
||||
const res = await this._super(...arguments);
|
||||
odoo = oldOdoo;
|
||||
return res;
|
||||
for (const key in sessionInfo) delete sessionInfo[key];
|
||||
for (const key in initialSessionInfo) {
|
||||
sessionInfo[key] = initialSessionInfo[key];
|
||||
}
|
||||
return await this._super(...arguments);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ import { patchWithCleanup } from "@web/../tests/helpers/utils";
|
||||
import { legacyProm } from "web.test_legacy";
|
||||
import { registerCleanup } from "./helpers/cleanup";
|
||||
import { prepareRegistriesWithCleanup } from "./helpers/mock_env";
|
||||
import { session as sessionInfo } from "@web/session";
|
||||
|
||||
const { whenReady, loadFile } = owl.utils;
|
||||
|
||||
@@ -148,7 +149,11 @@ function patchLegacyCoreBus() {
|
||||
function patchOdoo() {
|
||||
patchWithCleanup(odoo, {
|
||||
debug: "",
|
||||
session_info: {
|
||||
});
|
||||
}
|
||||
|
||||
function patchSessionInfo() {
|
||||
patchWithCleanup(sessionInfo, {
|
||||
cache_hashes: {
|
||||
load_menus: "161803",
|
||||
translations: "314159",
|
||||
@@ -178,7 +183,6 @@ function patchOdoo() {
|
||||
db: "test",
|
||||
server_version: "1.0",
|
||||
server_version_info: ["1.0"],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -190,6 +194,7 @@ export async function setupTests() {
|
||||
patchBrowserWithCleanup();
|
||||
patchLegacyCoreBus();
|
||||
patchOdoo();
|
||||
patchSessionInfo();
|
||||
});
|
||||
|
||||
const templatesUrl = `/web/webclient/qweb/${new Date().getTime()}?bundle=web.assets_qweb`;
|
||||
|
||||
@@ -5,6 +5,7 @@ import testUtils from "web.test_utils";
|
||||
import { clearRegistryWithCleanup } from "../../helpers/mock_env";
|
||||
import { click, legacyExtraNextTick, nextTick, patchWithCleanup } from "../../helpers/utils";
|
||||
import { createWebClient, doAction, getActionManagerServerData } from "./../helpers";
|
||||
import { session } from "@web/session";
|
||||
|
||||
let serverData;
|
||||
|
||||
@@ -19,7 +20,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
|
||||
QUnit.test("rainbowman integrated to webClient", async function (assert) {
|
||||
assert.expect(10);
|
||||
patchWithCleanup(odoo.session_info, { show_effect: true });
|
||||
patchWithCleanup(session, { show_effect: true });
|
||||
clearRegistryWithCleanup(mainComponentRegistry);
|
||||
|
||||
const webClient = await createWebClient({ serverData });
|
||||
@@ -65,7 +66,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
|
||||
QUnit.test("on close with effect from server", async function (assert) {
|
||||
assert.expect(1);
|
||||
patchWithCleanup(odoo.session_info, { show_effect: true });
|
||||
patchWithCleanup(session, { show_effect: true });
|
||||
const mockRPC = async (route) => {
|
||||
if (route === "/web/dataset/call_button") {
|
||||
return Promise.resolve({
|
||||
@@ -96,7 +97,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
</header>
|
||||
<field name="display_name"/>
|
||||
</form>`;
|
||||
patchWithCleanup(odoo.session_info, { show_effect: true });
|
||||
patchWithCleanup(session, { show_effect: true });
|
||||
const mockRPC = async (route) => {
|
||||
if (route === "/web/dataset/call_button") {
|
||||
return Promise.resolve(false);
|
||||
|
||||
@@ -8,7 +8,14 @@ import core from "web.core";
|
||||
import AbstractAction from "web.AbstractAction";
|
||||
import { registerCleanup } from "../../helpers/cleanup";
|
||||
import { makeTestEnv } from "../../helpers/mock_env";
|
||||
import { click, getFixture, legacyExtraNextTick, patchWithCleanup, nextTick } from "../../helpers/utils";
|
||||
import {
|
||||
click,
|
||||
getFixture,
|
||||
legacyExtraNextTick,
|
||||
patchWithCleanup,
|
||||
nextTick,
|
||||
} from "../../helpers/utils";
|
||||
import { session } from "@web/session";
|
||||
import {
|
||||
createWebClient,
|
||||
doAction,
|
||||
@@ -104,7 +111,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
|
||||
QUnit.test("fallback on home action if no action found", async (assert) => {
|
||||
assert.expect(2);
|
||||
patchWithCleanup(odoo.session_info, { home_action_id: 1001 });
|
||||
patchWithCleanup(session, { home_action_id: 1001 });
|
||||
|
||||
const wc = await createWebClient({ serverData });
|
||||
await testUtils.nextTick(); // wait for the navbar to be updated
|
||||
|
||||
@@ -9,6 +9,7 @@ import { patchWithCleanup } from "../../helpers/utils";
|
||||
import { createWebClient, doAction, getActionManagerServerData } from "./../helpers";
|
||||
import { mockDownload } from "@web/../tests/helpers/utils";
|
||||
import { clearRegistryWithCleanup } from "../../helpers/mock_env";
|
||||
import { session } from "@web/session";
|
||||
|
||||
let serverData;
|
||||
|
||||
@@ -184,7 +185,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
() => {}
|
||||
)
|
||||
);
|
||||
patchWithCleanup(odoo.session_info.user_context, { some_key: 2 });
|
||||
patchWithCleanup(session.user_context, { some_key: 2 });
|
||||
const mockRPC = async (route, args) => {
|
||||
assert.step(args.method || route);
|
||||
if (route.includes("/report/html/some_report")) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import FormView from "web.FormView";
|
||||
import ListController from "web.ListController";
|
||||
import testUtils from "web.test_utils";
|
||||
import legacyViewRegistry from "web.view_registry";
|
||||
import { session } from "@web/session";
|
||||
import {
|
||||
click,
|
||||
legacyExtraNextTick,
|
||||
@@ -712,7 +713,7 @@ QUnit.module("ActionManager", (hooks) => {
|
||||
|
||||
QUnit.test("requests for execute_action of type object are handled", async function (assert) {
|
||||
assert.expect(11);
|
||||
patchWithCleanup(odoo.session_info.user_context, { some_key: 2 });
|
||||
patchWithCleanup(session.user_context, { some_key: 2 });
|
||||
const mockRPC = async (route, args) => {
|
||||
assert.step((args && args.method) || route);
|
||||
if (route === "/web/dataset/call_button") {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { RainbowMan } from "@web/webclient/effects/rainbow_man";
|
||||
import { userService } from "@web/core/user_service";
|
||||
import { makeTestEnv } from "../../helpers/mock_env";
|
||||
import { click, getFixture, nextTick, patchWithCleanup } from "../../helpers/utils";
|
||||
import { session } from "@web/session";
|
||||
|
||||
const { Component, mount, tags } = owl;
|
||||
const serviceRegistry = registry.category("services");
|
||||
@@ -31,7 +32,7 @@ QUnit.module("RainbowMan", (hooks) => {
|
||||
fadeout: "nextTick",
|
||||
};
|
||||
target = getFixture();
|
||||
patchWithCleanup(odoo.session_info, { show_effect: true });
|
||||
patchWithCleanup(session, { show_effect: true });
|
||||
serviceRegistry.add("user", userService);
|
||||
serviceRegistry.add("effect", effectService);
|
||||
serviceRegistry.add("notification", notificationService);
|
||||
|
||||
@@ -9,6 +9,7 @@ import { makeTestEnv } from "../helpers/mock_env";
|
||||
import { companyService } from "@web/webclient/company_service";
|
||||
import { click, getFixture, makeDeferred, patchWithCleanup } from "../helpers/utils";
|
||||
import { uiService } from "@web/core/ui/ui_service";
|
||||
import { session } from "@web/session";
|
||||
|
||||
const { mount } = owl;
|
||||
const serviceRegistry = registry.category("services");
|
||||
@@ -37,7 +38,7 @@ async function createSwitchCompanyMenu(routerParams = {}, toggleDelay = 0) {
|
||||
|
||||
QUnit.module("SwitchCompanyMenu", (hooks) => {
|
||||
hooks.beforeEach(() => {
|
||||
patchWithCleanup(odoo.session_info.user_companies, {
|
||||
patchWithCleanup(session.user_companies, {
|
||||
allowed_companies: {
|
||||
1: { id: 1, name: "Hermit" },
|
||||
2: { id: 2, name: "Herman's" },
|
||||
|
||||
@@ -12,6 +12,7 @@ import { userService } from "@web/core/user_service";
|
||||
import { makeTestEnv } from "../helpers/mock_env";
|
||||
import { makeFakeLocalizationService } from "../helpers/mock_services";
|
||||
import { click, getFixture, patchWithCleanup } from "../helpers/utils";
|
||||
import { session } from "@web/session";
|
||||
|
||||
const { mount } = owl;
|
||||
const serviceRegistry = registry.category("services");
|
||||
@@ -22,7 +23,7 @@ let userMenu;
|
||||
|
||||
QUnit.module("UserMenu", {
|
||||
async beforeEach() {
|
||||
patchWithCleanup(odoo.session_info, { name: "Sauron" });
|
||||
patchWithCleanup(session, { name: "Sauron" });
|
||||
serviceRegistry.add("user", userService);
|
||||
serviceRegistry.add("hotkey", hotkeyService);
|
||||
serviceRegistry.add("ui", uiService);
|
||||
|
||||
@@ -13,6 +13,7 @@ import { WebClient } from "@web/webclient/webclient";
|
||||
import { clearRegistryWithCleanup, makeTestEnv } from "../helpers/mock_env";
|
||||
import { fakeTitleService } from "../helpers/mock_services";
|
||||
import { getFixture, patchWithCleanup, triggerEvent } from "../helpers/utils";
|
||||
import { session } from "@web/session";
|
||||
|
||||
const { Component, tags, mount } = owl;
|
||||
const { xml } = tags;
|
||||
@@ -61,7 +62,7 @@ QUnit.test("can render a main component", async (assert) => {
|
||||
|
||||
QUnit.test("webclient for the superuser", async (assert) => {
|
||||
assert.expect(1);
|
||||
patchWithCleanup(odoo.session_info, { uid: 1 });
|
||||
patchWithCleanup(session, { uid: 1 });
|
||||
const env = await makeTestEnv(baseConfig);
|
||||
const target = getFixture();
|
||||
const webClient = await mount(WebClient, { env, target });
|
||||
@@ -71,7 +72,7 @@ QUnit.test("webclient for the superuser", async (assert) => {
|
||||
|
||||
QUnit.test("webclient for a non superuser", async (assert) => {
|
||||
assert.expect(1);
|
||||
patchWithCleanup(odoo.session_info, { uid: 2 });
|
||||
patchWithCleanup(session, { uid: 2 });
|
||||
const env = await makeTestEnv(baseConfig);
|
||||
const target = getFixture();
|
||||
const webClient = await mount(WebClient, { env, target });
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<!--in an iframe, we don't want the session to perform qweb_templates rpc-->
|
||||
<script type="text/javascript">
|
||||
window.odoo = {};
|
||||
window.odoo.session_info = {is_report: true};
|
||||
window.odoo.__session_info__ = {is_report: true};
|
||||
</script>
|
||||
<t t-call-assets="web.assets_common" t-css="false"/>
|
||||
<t t-call-assets="web.report_assets_common" t-css="false"/>
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
</xpath>
|
||||
<xpath expr="//head/script[@id='web.layout.odooscript']" position="after">
|
||||
<script type="text/javascript">
|
||||
odoo.session_info = <t t-out="json.dumps(request.env['ir.http'].get_frontend_session_info())"/>;
|
||||
odoo.__session_info__ = <t t-out="json.dumps(request.env['ir.http'].get_frontend_session_info())"/>;
|
||||
if (!/(^|;\s)tz=/.test(document.cookie)) {
|
||||
const userTZ = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
document.cookie = `tz=${userTZ}; path=/`;
|
||||
@@ -286,13 +286,13 @@
|
||||
<t t-call="web.layout">
|
||||
<t t-set="head_web">
|
||||
<script type="text/javascript">
|
||||
odoo.session_info = <t t-out="json.dumps(session_info)"/>;
|
||||
odoo.reloadMenus = () => fetch(`/web/webclient/load_menus/${odoo.session_info.cache_hashes.load_menus}`).then(res => res.json());
|
||||
odoo.__session_info__ = <t t-out="json.dumps(session_info)"/>;
|
||||
odoo.reloadMenus = () => fetch(`/web/webclient/load_menus/${odoo.__session_info__.cache_hashes.load_menus}`).then(res => res.json());
|
||||
odoo.loadMenusPromise = odoo.reloadMenus();
|
||||
odoo.loadTemplatesPromise = fetch(`/web/webclient/qweb/${odoo.session_info.cache_hashes.qweb}?bundle=web.assets_qweb`).then(doc => doc.text());
|
||||
odoo.loadTemplatesPromise = fetch(`/web/webclient/qweb/${odoo.__session_info__.cache_hashes.qweb}?bundle=web.assets_qweb`).then(doc => doc.text());
|
||||
// Block to avoid leaking variables in the script scope
|
||||
{
|
||||
const { user_context, cache_hashes } = odoo.session_info;
|
||||
const { user_context, cache_hashes } = odoo.__session_info__;
|
||||
// Prefetch translations to speedup webclient. This is done in JS because link rel="prefetch"
|
||||
// is not yet supported on safari.
|
||||
fetch(`/web/webclient/translations/${cache_hashes.translations}?lang=${user_context.lang}`);
|
||||
|
||||
@@ -9,6 +9,7 @@ var rpc = require('web.rpc');
|
||||
var Widget = require('web.Widget');
|
||||
var weWidgets = require('wysiwyg.widgets');
|
||||
var websiteNavbarData = require('website.navbar');
|
||||
const { session } = require('@web/session');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
@@ -581,7 +582,7 @@ var MetaImageSelector = Widget.extend({
|
||||
this.activeMetaImg = data.metaImg;
|
||||
this.serverUrl = data.htmlpage.url();
|
||||
const imgField = data.hasSocialDefaultImage ? 'social_default_image' : 'logo';
|
||||
data.pageImages.unshift(_.str.sprintf('/web/image/website/%s/%s', odoo.session_info.website_id, imgField));
|
||||
data.pageImages.unshift(_.str.sprintf('/web/image/website/%s/%s', session.website_id, imgField));
|
||||
this.images = _.uniq(data.pageImages);
|
||||
this.customImgUrl = _.contains(
|
||||
data.pageImages.map((img)=> new URL(img, window.location.origin).pathname),
|
||||
|
||||
Reference in New Issue
Block a user