483b06
From 894fdd8c10552ef0b90363db985bb25e398d99e1 Mon Sep 17 00:00:00 2001
483b06
From: Pavel Vomacka <pvomacka@redhat.com>
483b06
Date: Wed, 22 Mar 2017 16:48:36 +0100
483b06
Subject: [PATCH] WebUI: add method for disabling item in user dropdown menu
483b06
483b06
AD user can do only several things. One of those which are not
483b06
allowed is to reset password to itself. Therefore we need to be
483b06
able to turn of a item in dropdown menu. In our case
483b06
'Password reset' item. Function which disable menu item and detach
483b06
the listener on click from the item specified by its name was added.
483b06
483b06
Part of: https://pagure.io/freeipa/issue/3242
483b06
483b06
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
483b06
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
483b06
---
483b06
 install/ui/src/freeipa/Application_controller.js | 42 ++++++++++++++++++++----
483b06
 install/ui/src/freeipa/widgets/App.js            |  4 +++
483b06
 2 files changed, 40 insertions(+), 6 deletions(-)
483b06
483b06
diff --git a/install/ui/src/freeipa/Application_controller.js b/install/ui/src/freeipa/Application_controller.js
483b06
index 32add5f8f3d6874c1c555bf28d2b70cd54af5956..d809c1f2662609e390609270ef3ddc42f0727936 100644
483b06
--- a/install/ui/src/freeipa/Application_controller.js
483b06
+++ b/install/ui/src/freeipa/Application_controller.js
483b06
@@ -69,6 +69,16 @@ define([
483b06
         facet_changing: false,
483b06
 
483b06
         /**
483b06
+         * Listeners for user menu items
483b06
+         */
483b06
+         on_profile_listener: null,
483b06
+         on_passwd_reset_listener: null,
483b06
+         on_logout_listener: null,
483b06
+         on_item_select_listener: null,
483b06
+         on_configuration_listerer: null,
483b06
+         on_about_listener: null,
483b06
+
483b06
+        /**
483b06
          * Currently displayed facet
483b06
          *
483b06
          */
483b06
@@ -109,12 +119,7 @@ define([
483b06
                 }
483b06
             };
483b06
 
483b06
-            on(this.app_widget.menu_widget, 'item-select', this.on_menu_click.bind(this));
483b06
-            on(this.app_widget, 'profile-click', this.on_profile.bind(this));
483b06
-            on(this.app_widget, 'logout-click', this.on_logout.bind(this));
483b06
-            on(this.app_widget, 'password-reset-click', this.on_password_reset.bind(this));
483b06
-            on(this.app_widget, 'configuration-click', this.on_configuration.bind(this));
483b06
-            on(this.app_widget, 'about-click', this.on_about.bind(this));
483b06
+            this.register_user_menu_listeners();
483b06
 
483b06
             on(this.router, 'facet-show', this.on_facet_show.bind(this));
483b06
             on(this.router, 'facet-change', this.on_facet_change.bind(this));
483b06
@@ -133,6 +138,31 @@ define([
483b06
             IPA.opened_dialogs.start_handling(this);
483b06
         },
483b06
 
483b06
+        register_user_menu_listeners: function() {
483b06
+            this.on_profile_listener = on(this.app_widget, 'profile-click',
483b06
+                    this.on_profile.bind(this));
483b06
+            this.on_passwd_reset_listener = on(this.app_widget,
483b06
+                    'password-reset-click', this.on_password_reset.bind(this));
483b06
+            this.on_logout_listener = on(this.app_widget, 'logout-click',
483b06
+                    this.on_logout.bind(this));
483b06
+            this.on_item_select_listener = on(this.app_widget.menu_widget,
483b06
+                    'item-select', this.on_menu_click.bind(this));
483b06
+            this.on_configuration_listerer = on(this.app_widget,
483b06
+                    'configuration-click', this.on_configuration.bind(this));
483b06
+            this.on_about_listener = on(this.app_widget,
483b06
+                    'about-click', this.on_about.bind(this));
483b06
+        },
483b06
+
483b06
+        /**
483b06
+         * Turns off one item in user dropdown menu and remove its listener.
483b06
+         * @param {string} name of the user menu item which should be disabled
483b06
+         * @param {Object} listener disable this listener
483b06
+         */
483b06
+        disable_user_menu_item: function(name, listener) {
483b06
+            this.app_widget.disable_user_menu_item(name);
483b06
+            listener.remove();
483b06
+        },
483b06
+
483b06
         /**
483b06
          * Gets:
483b06
          *  * metadata
483b06
diff --git a/install/ui/src/freeipa/widgets/App.js b/install/ui/src/freeipa/widgets/App.js
483b06
index 68b78c7c4be44f5a1f658fed6b6b75d1beda22c5..95bc9b2cf3bcf40cd3a4cab47e9043e05331e019 100644
483b06
--- a/install/ui/src/freeipa/widgets/App.js
483b06
+++ b/install/ui/src/freeipa/widgets/App.js
483b06
@@ -222,6 +222,10 @@ define(['dojo/_base/declare',
483b06
             }
483b06
         },
483b06
 
483b06
+        disable_user_menu_item: function(name) {
483b06
+            this.user_menu.disable_item(name);
483b06
+        },
483b06
+
483b06
         on_menu_item_click: function(item) {
483b06
             this.collapse_menu();
483b06
         },
483b06
-- 
483b06
2.12.1
483b06