summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2020-07-06 09:37:49 +0000
committerXavier Morel <xmo@odoo.com>2020-07-09 07:23:04 +0000
commit350ed97c4556f6c6ea1a736db0ea5a804b28ba08 (patch)
treefa582e732f3426a1c7a2cda9cb8344e9702b5a0d /addons/web/static
parentccea563abbbae48b7b914f5b12e59b02e167d486 (diff)
[FIX] web: async operations should not live in init
Support for the "allow exports" group was implemented by checking the group in init(), which is sync. Move that check over to willStart instead. Also add a default mock for user_has_group (makes it so it always replies that the user doesn't have the group), and override that specifically for the group we're interested in in the export tests, so those tests have access to the Export action / option. closes odoo/odoo#54254 X-original-commit: 30968ac93373990338c23f49e678d272b8e60c6b Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/views/list/list_controller.js10
-rw-r--r--addons/web/static/tests/helpers/test_utils_mock.js13
-rw-r--r--addons/web/static/tests/widgets/data_export_tests.js11
3 files changed, 24 insertions, 10 deletions
diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js
index 42da94f7166..12a3e8c75e1 100644
--- a/addons/web/static/src/js/views/list/list_controller.js
+++ b/addons/web/static/src/js/views/list/list_controller.js
@@ -58,9 +58,15 @@ var ListController = BasicController.extend({
this.fieldChangedPrevented = false;
this.isPageSelected = false; // true iff all records of the page are selected
this.isDomainSelected = false; // true iff the user selected all records matching the domain
- session.user_has_group('base.group_allow_export').then(has_group => {
- this.isExportEnable = has_group;
+ this.isExportEnable = false;
+ },
+
+ willStart() {
+ const sup = this._super(...arguments);
+ const acl = session.user_has_group('base.group_allow_export').then(hasGroup => {
+ this.isExportEnable = hasGroup;
});
+ return Promise.all([sup, acl]);
},
//--------------------------------------------------------------------------
diff --git a/addons/web/static/tests/helpers/test_utils_mock.js b/addons/web/static/tests/helpers/test_utils_mock.js
index 1b70673f067..144b05acf74 100644
--- a/addons/web/static/tests/helpers/test_utils_mock.js
+++ b/addons/web/static/tests/helpers/test_utils_mock.js
@@ -168,14 +168,13 @@ async function _getMockedOwlEnv(params, mockServer) {
* end of the test
*/
function _mockGlobalObjects(params) {
+ // store initial session state (for restoration)
+ const initialSession = Object.assign({}, session);
// patch session
- let initialSession = Object.assign({}, session);
- session.getTZOffset = function () {
- return 0; // by default, but may be overridden in specific tests
- };
- if ('session' in params) {
- Object.assign(session, params.session);
- }
+ Object.assign(session, {
+ getTZOffset() { return 0; },
+ async user_has_group() { return false; },
+ }, params.session);
// patch config
let initialConfig;
diff --git a/addons/web/static/tests/widgets/data_export_tests.js b/addons/web/static/tests/widgets/data_export_tests.js
index e7fb9864791..8890ee48c20 100644
--- a/addons/web/static/tests/widgets/data_export_tests.js
+++ b/addons/web/static/tests/widgets/data_export_tests.js
@@ -40,7 +40,9 @@ QUnit.module('widgets', {
records: [],
},
};
-
+ this.mockSession = {
+ async user_has_group(g) { return g === 'base.group_allow_export'; }
+ }
this.mockDataExportRPCs = function (route) {
if (route === '/web/export/formats') {
return Promise.resolve([
@@ -100,6 +102,7 @@ QUnit.module('widgets', {
},
mockRPC: this.mockDataExportRPCs,
session: {
+ ...this.mockSession,
get_file: function (params) {
assert.step(params.url);
params.complete();
@@ -148,6 +151,7 @@ QUnit.module('widgets', {
},
mockRPC: this.mockDataExportRPCs,
session: {
+ ...this.mockSession,
get_file: function (params) {
const data = JSON.parse(params.data.data);
assert.deepEqual({ids: data.ids, domain: data.domain}, expectedData);
@@ -207,6 +211,7 @@ QUnit.module('widgets', {
viewOptions: {
hasActionMenus: true,
},
+ session: this.mockSession,
mockRPC: this.mockDataExportRPCs,
});
@@ -249,6 +254,7 @@ QUnit.module('widgets', {
viewOptions: {
hasActionMenus: true,
},
+ session: this.mockSession,
mockRPC: this.mockDataExportRPCs,
});
@@ -283,6 +289,7 @@ QUnit.module('widgets', {
model: 'partner',
data: this.data,
arch: `<tree export_xlsx="0"><field name="foo"/></tree>`,
+ session: this.mockSession,
});
assert.containsNone(list, '.o_list_export_xlsx')
list.destroy();
@@ -302,6 +309,7 @@ QUnit.module('widgets', {
</tree>`,
domain: [['bar', '!=', 'glou']],
session: {
+ ...this.mockSession,
get_file(args) {
let data = JSON.parse(args.data.data);
assert.strictEqual(args.url, '/web/export/xlsx', "should call get_file with the correct url");
@@ -346,6 +354,7 @@ QUnit.module('widgets', {
groupBy: ['foo', 'bar'],
domain: [['bar', '!=', 'glou']],
session: {
+ ...this.mockSession,
get_file(args) {
let data = JSON.parse(args.data.data);
assert.strictEqual(args.url, '/web/export/xlsx', "should call get_file with the correct url");