From 11ff01af9b3887e7ec70dae204cd0d2c1bc0f8f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Ku=CC=88hn?= Date: Fri, 17 Nov 2017 11:31:37 +0100 Subject: [PATCH] [FIX] web: delete attribute on list view Before this fix, when adding the attribute delete=0 on a listview, it was still possible to delete records via the menu 'Delete' in the sidebar. After this fix, this should not be possible to delete records when delete=0. The attribute delete was hard-coded to true, as there was a traceback when it was set to false. It was simply due to a misplaced closing brackets that was hiding an assignment, which resulted to calling a method on undefined. --- .../src/js/views/list/list_controller.js | 2 +- .../web/static/src/js/views/list/list_view.js | 1 - addons/web/static/tests/views/list_tests.js | 21 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 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 67cc6271509..5c6b7ea414d 100644 --- a/addons/web/static/src/js/views/list/list_controller.js +++ b/addons/web/static/src/js/views/list/list_controller.js @@ -148,6 +148,7 @@ var ListController = BasicController.extend({ label: _t('Delete'), callback: this._onDeleteSelectedRecords.bind(this) }); + } this.sidebar = new Sidebar(this, { editable: this.is_action_enabled('edit'), env: { @@ -157,7 +158,6 @@ var ListController = BasicController.extend({ }, actions: _.extend(this.toolbarActions, {other: other}), }); - } this.sidebar.appendTo($node); this._toggleSidebar(); diff --git a/addons/web/static/src/js/views/list/list_view.js b/addons/web/static/src/js/views/list/list_view.js index 61612282bf5..b2295affb98 100644 --- a/addons/web/static/src/js/views/list/list_view.js +++ b/addons/web/static/src/js/views/list/list_view.js @@ -42,7 +42,6 @@ var ListView = BasicView.extend({ this.controllerParams.editable = arch.attrs.editable; this.controllerParams.hasSidebar = params.sidebar; this.controllerParams.toolbarActions = viewInfo.toolbar; - this.controllerParams.activeActions.delete = true; this.controllerParams.noLeaf = !!this.loadParams.context.group_by_no_leaf; this.controllerParams.mode = mode; diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index fc05a1c92a4..6156a218744 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -141,6 +141,27 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('list with delete="0"', function (assert) { + assert.expect(4); + + var list = createView({ + View: ListView, + model: 'foo', + data: this.data, + viewOptions: {sidebar: true}, + arch: '', + }); + + assert.ok(list.sidebar.$el.hasClass('o_hidden'), 'sidebar should be invisible'); + assert.ok(list.$('tbody td.o_list_record_selector').length, "should have at least one record"); + + list.$('tbody td.o_list_record_selector:first input').click(); + assert.ok(!list.sidebar.$el.hasClass('o_hidden'), 'sidebar should be visible'); + assert.notOk(list.sidebar.$('a:contains(Delete)').length, 'sidebar should not have Delete button'); + + list.destroy(); + }); + QUnit.test('simple editable rendering', function (assert) { assert.expect(12);