From 0eaee456591b31e35b56f365cdfbf1e618b17a6c Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 24 Jan 2019 08:08:30 +0000 Subject: [PATCH] [IMP] web: force activeActions to be boolean The docstring says they are boolean, but they actually aren't (e.g. edit="0" in the arch would lead to activeActions.edit=0). This could cause issue if that value is used to toggle a class with jQuery, as in this case the flag argument *must* be a boolean. --- .../static/src/js/fields/relational_fields.js | 4 ++-- addons/web/static/src/js/views/abstract_view.js | 8 ++++---- .../static/src/js/views/kanban/kanban_view.js | 17 +++++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 24a1eced358..d30d263fa12 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -817,10 +817,10 @@ var FieldX2Many = AbstractField.extend({ var arch = this.view && this.view.arch; if (arch) { this.activeActions.create = arch.attrs.create ? - JSON.parse(arch.attrs.create) : + !!JSON.parse(arch.attrs.create) : true; this.activeActions.delete = arch.attrs.delete ? - JSON.parse(arch.attrs.delete) : + !!JSON.parse(arch.attrs.delete) : true; this.editable = arch.attrs.editable; } diff --git a/addons/web/static/src/js/views/abstract_view.js b/addons/web/static/src/js/views/abstract_view.js index 5921c1b4bc3..085571a200f 100644 --- a/addons/web/static/src/js/views/abstract_view.js +++ b/addons/web/static/src/js/views/abstract_view.js @@ -122,10 +122,10 @@ var AbstractView = Factory.extend({ this.controllerParams = { actionViews: params.actionViews, activeActions: { - edit: this.arch.attrs.edit ? JSON.parse(this.arch.attrs.edit) : true, - create: this.arch.attrs.create ? JSON.parse(this.arch.attrs.create) : true, - delete: this.arch.attrs.delete ? JSON.parse(this.arch.attrs.delete) : true, - duplicate: this.arch.attrs.duplicate ? JSON.parse(this.arch.attrs.duplicate) : true, + edit: this.arch.attrs.edit ? !!JSON.parse(this.arch.attrs.edit) : true, + create: this.arch.attrs.create ? !!JSON.parse(this.arch.attrs.create) : true, + delete: this.arch.attrs.delete ? !!JSON.parse(this.arch.attrs.delete) : true, + duplicate: this.arch.attrs.duplicate ? !!JSON.parse(this.arch.attrs.duplicate) : true, }, bannerRoute: this.arch.attrs.banner_route, controllerID: params.controllerID, diff --git a/addons/web/static/src/js/views/kanban/kanban_view.js b/addons/web/static/src/js/views/kanban/kanban_view.js index 9f589ffe2a7..fd40ca7df93 100644 --- a/addons/web/static/src/js/views/kanban/kanban_view.js +++ b/addons/web/static/src/js/views/kanban/kanban_view.js @@ -50,18 +50,19 @@ var KanbanView = BasicView.extend({ } var activeActions = this.controllerParams.activeActions; + var archAttrs = this.arch.attrs; activeActions = _.extend(activeActions, { - group_create: this.arch.attrs.group_create ? JSON.parse(this.arch.attrs.group_create) : true, - group_edit: this.arch.attrs.group_edit ? JSON.parse(this.arch.attrs.group_edit) : true, - group_delete: this.arch.attrs.group_delete ? JSON.parse(this.arch.attrs.group_delete) : true, + group_create: this.arch.attrs.group_create ? !!JSON.parse(archAttrs.group_create) : true, + group_edit: archAttrs.group_edit ? !!JSON.parse(archAttrs.group_edit) : true, + group_delete: archAttrs.group_delete ? !!JSON.parse(archAttrs.group_delete) : true, }); this.rendererParams.column_options = { editable: activeActions.group_edit, deletable: activeActions.group_delete, - archivable: this.arch.attrs.archivable ? JSON.parse(this.arch.attrs.archivable) : true, + archivable: archAttrs.archivable ? !!JSON.parse(archAttrs.archivable) : true, group_creatable: activeActions.group_create && !config.device.isMobile, - quickCreateView: this.arch.attrs.quick_create_view || null, + quickCreateView: archAttrs.quick_create_view || null, hasProgressBar: !!progressBar, }; this.rendererParams.record_options = { @@ -70,12 +71,12 @@ var KanbanView = BasicView.extend({ read_only_mode: params.readOnlyMode, }; this.rendererParams.quickCreateEnabled = this._isQuickCreateEnabled(); - var examples = this.arch.attrs.examples; + var examples = archAttrs.examples; if (examples) { this.rendererParams.examples = kanbanExamplesRegistry.get(examples); } - this.controllerParams.on_create = this.arch.attrs.on_create; + this.controllerParams.on_create = archAttrs.on_create; this.controllerParams.readOnlyMode = false; this.controllerParams.hasButtons = true; this.controllerParams.quickCreateEnabled = this.rendererParams.quickCreateEnabled; @@ -100,7 +101,7 @@ var KanbanView = BasicView.extend({ return false; } if (this.arch.attrs.quick_create !== undefined) { - return JSON.parse(this.arch.attrs.quick_create); + return !!JSON.parse(this.arch.attrs.quick_create); } return true; },