Blob Blame History Raw
From 894fdd8c10552ef0b90363db985bb25e398d99e1 Mon Sep 17 00:00:00 2001
From: Pavel Vomacka <pvomacka@redhat.com>
Date: Wed, 22 Mar 2017 16:48:36 +0100
Subject: [PATCH] WebUI: add method for disabling item in user dropdown menu

AD user can do only several things. One of those which are not
allowed is to reset password to itself. Therefore we need to be
able to turn of a item in dropdown menu. In our case
'Password reset' item. Function which disable menu item and detach
the listener on click from the item specified by its name was added.

Part of: https://pagure.io/freeipa/issue/3242

Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
---
 install/ui/src/freeipa/Application_controller.js | 42 ++++++++++++++++++++----
 install/ui/src/freeipa/widgets/App.js            |  4 +++
 2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/install/ui/src/freeipa/Application_controller.js b/install/ui/src/freeipa/Application_controller.js
index 32add5f8f3d6874c1c555bf28d2b70cd54af5956..d809c1f2662609e390609270ef3ddc42f0727936 100644
--- a/install/ui/src/freeipa/Application_controller.js
+++ b/install/ui/src/freeipa/Application_controller.js
@@ -69,6 +69,16 @@ define([
         facet_changing: false,
 
         /**
+         * Listeners for user menu items
+         */
+         on_profile_listener: null,
+         on_passwd_reset_listener: null,
+         on_logout_listener: null,
+         on_item_select_listener: null,
+         on_configuration_listerer: null,
+         on_about_listener: null,
+
+        /**
          * Currently displayed facet
          *
          */
@@ -109,12 +119,7 @@ define([
                 }
             };
 
-            on(this.app_widget.menu_widget, 'item-select', this.on_menu_click.bind(this));
-            on(this.app_widget, 'profile-click', this.on_profile.bind(this));
-            on(this.app_widget, 'logout-click', this.on_logout.bind(this));
-            on(this.app_widget, 'password-reset-click', this.on_password_reset.bind(this));
-            on(this.app_widget, 'configuration-click', this.on_configuration.bind(this));
-            on(this.app_widget, 'about-click', this.on_about.bind(this));
+            this.register_user_menu_listeners();
 
             on(this.router, 'facet-show', this.on_facet_show.bind(this));
             on(this.router, 'facet-change', this.on_facet_change.bind(this));
@@ -133,6 +138,31 @@ define([
             IPA.opened_dialogs.start_handling(this);
         },
 
+        register_user_menu_listeners: function() {
+            this.on_profile_listener = on(this.app_widget, 'profile-click',
+                    this.on_profile.bind(this));
+            this.on_passwd_reset_listener = on(this.app_widget,
+                    'password-reset-click', this.on_password_reset.bind(this));
+            this.on_logout_listener = on(this.app_widget, 'logout-click',
+                    this.on_logout.bind(this));
+            this.on_item_select_listener = on(this.app_widget.menu_widget,
+                    'item-select', this.on_menu_click.bind(this));
+            this.on_configuration_listerer = on(this.app_widget,
+                    'configuration-click', this.on_configuration.bind(this));
+            this.on_about_listener = on(this.app_widget,
+                    'about-click', this.on_about.bind(this));
+        },
+
+        /**
+         * Turns off one item in user dropdown menu and remove its listener.
+         * @param {string} name of the user menu item which should be disabled
+         * @param {Object} listener disable this listener
+         */
+        disable_user_menu_item: function(name, listener) {
+            this.app_widget.disable_user_menu_item(name);
+            listener.remove();
+        },
+
         /**
          * Gets:
          *  * metadata
diff --git a/install/ui/src/freeipa/widgets/App.js b/install/ui/src/freeipa/widgets/App.js
index 68b78c7c4be44f5a1f658fed6b6b75d1beda22c5..95bc9b2cf3bcf40cd3a4cab47e9043e05331e019 100644
--- a/install/ui/src/freeipa/widgets/App.js
+++ b/install/ui/src/freeipa/widgets/App.js
@@ -222,6 +222,10 @@ define(['dojo/_base/declare',
             }
         },
 
+        disable_user_menu_item: function(name) {
+            this.user_menu.disable_item(name);
+        },
+
         on_menu_item_click: function(item) {
             this.collapse_menu();
         },
-- 
2.12.1