From c28e7856e4d144eb2840cd729abb10995cf69445 Mon Sep 17 00:00:00 2001 From: Noe Antoine Date: Tue, 11 Jan 2022 16:25:05 +0000 Subject: [PATCH] [IMP] portal: prevent duplicate views of portal wizard The portal's granting access / revoking access / reinvite actions return the wizard modal opening action in order to keep it open and allow the user to keep browsing and managing portal access. However, this can return the modal opening several times and execute them all, generating several (unsynchronized) modal view instances that the user sees and has to close one at a time. Therefore the user field in the portal wizard receives a small widget, that only allows one of these actions at a time. Clicking on other buttons in the list while an action is ongoing will not do anything since buttons are disabled for the time the action is being done. Buttons showing the email_state will not do actions when clicked. A short scss file is also added to the widget in order to make the elements of the user_ids tree view as close to each other as possible. This prevents in most cases the loss of buttons going off the list's width view and generating a scroll bar, a situation to avoid since it does not show the user the (dyamically appeared) action buttons. (e.g. when hiding buttons if no valid email, then editing to a valid email, button reappearing out of visible range) Task-2613780 Part-of: odoo/odoo#74911 --- addons/portal/__manifest__.py | 3 +++ .../fields/portal_wizard_user_one2many.js | 14 +++++++++++ .../fields/portal_wizard_user_one2many.scss | 3 +++ .../list/portal_wizard_user_list_renderer.js | 23 +++++++++++++++++++ addons/portal/wizard/portal_wizard.py | 2 +- addons/portal/wizard/portal_wizard_views.xml | 2 +- 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 addons/portal/static/src/views/fields/portal_wizard_user_one2many.js create mode 100644 addons/portal/static/src/views/fields/portal_wizard_user_one2many.scss create mode 100644 addons/portal/static/src/views/list/portal_wizard_user_list_renderer.js diff --git a/addons/portal/__manifest__.py b/addons/portal/__manifest__.py index f545e16ee60..3d11a22f5fe 100644 --- a/addons/portal/__manifest__.py +++ b/addons/portal/__manifest__.py @@ -32,6 +32,9 @@ a dependency towards website editing and customization capabilities.""", 'web._assets_frontend_helpers': [ ('prepend', 'portal/static/src/scss/bootstrap_overridden.scss'), ], + 'web.assets_backend': [ + 'portal/static/src/views/**/*', + ], 'web.assets_frontend': [ 'portal/static/src/scss/bootstrap.extend.scss', 'portal/static/src/scss/portal.scss', diff --git a/addons/portal/static/src/views/fields/portal_wizard_user_one2many.js b/addons/portal/static/src/views/fields/portal_wizard_user_one2many.js new file mode 100644 index 00000000000..840e52f86df --- /dev/null +++ b/addons/portal/static/src/views/fields/portal_wizard_user_one2many.js @@ -0,0 +1,14 @@ +/** @odoo-module **/ + +import { PortalWizardUserListRenderer } from "../list/portal_wizard_user_list_renderer"; +import { X2ManyField } from "@web/views/fields/x2many/x2many_field"; +import { registry } from "@web/core/registry"; + +export class PortalUserX2ManyField extends X2ManyField { + setup() { + super.setup(); + this.Renderer = PortalWizardUserListRenderer; + } +} + +registry.category("fields").add("portal_wizard_user_one2many", PortalUserX2ManyField); diff --git a/addons/portal/static/src/views/fields/portal_wizard_user_one2many.scss b/addons/portal/static/src/views/fields/portal_wizard_user_one2many.scss new file mode 100644 index 00000000000..bb5713fa64b --- /dev/null +++ b/addons/portal/static/src/views/fields/portal_wizard_user_one2many.scss @@ -0,0 +1,3 @@ +.o_portal_wizard_user_one2many td { + width: 1%; +} diff --git a/addons/portal/static/src/views/list/portal_wizard_user_list_renderer.js b/addons/portal/static/src/views/list/portal_wizard_user_list_renderer.js new file mode 100644 index 00000000000..4d21b441b1b --- /dev/null +++ b/addons/portal/static/src/views/list/portal_wizard_user_list_renderer.js @@ -0,0 +1,23 @@ +/** @odoo-module **/ + +import { ListRenderer } from "@web/views/list/list_renderer"; + +const { useSubEnv } = owl; + +export class PortalWizardUserListRenderer extends ListRenderer { + setup() { + super.setup(); + this.isPortalActionOngoing = false; + const defaultOnClickViewButton = this.env.onClickViewButton; + useSubEnv({ + onClickViewButton: async (params) => { + if (params.clickParams.name === 'action_refresh_modal' || this.isPortalActionOngoing) { + return false; + } + this.isPortalActionOngoing = true; + await defaultOnClickViewButton(params); + this.isPortalActionOngoing = false; + }, + }); + } +} diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index fc70dd821ee..e4d37de2fcc 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -206,7 +206,7 @@ class PortalWizardUser(models.TransientModel): return self.action_refresh_modal() def action_refresh_modal(self): - """Refresh the portal wizard modal and keep it open. Used as action of email state icon buttons, + """Refresh the portal wizard modal and keep it open. Used as fallback action of email state icon buttons, required as they must be non-disabled buttons to fire mouse events to show tooltips on email state.""" return self.wizard_id._action_open_modal() diff --git a/addons/portal/wizard/portal_wizard_views.xml b/addons/portal/wizard/portal_wizard_views.xml index 2b782e3a96b..a83805294e4 100644 --- a/addons/portal/wizard/portal_wizard_views.xml +++ b/addons/portal/wizard/portal_wizard_views.xml @@ -31,7 +31,7 @@ - +