[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>
This commit is contained in:
Xavier Morel
2020-07-09 07:23:04 +00:00
parent ccea563abb
commit 350ed97c45
3 changed files with 24 additions and 10 deletions
@@ -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]);
},
//--------------------------------------------------------------------------
@@ -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;
@@ -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");