Since the Add/Delete links in the association table are disabled when
the category is set to 'all', it's no longer necessary to check the
category before showing the add/delete dialogs and modify the category
before adding entries. Thus, the IPA.rule_association_table_widget is
no longer needed.

Ticket #1692

--
Endi S. Dewata
From eb4a9a4daac97da7356e59ad7f6a3323ec9716e7 Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Mon, 22 Aug 2011 15:06:00 -0500
Subject: [PATCH] Removed unnecessary HBAC/sudo rule category modification.

Since the Add/Delete links in the association table are disabled when
the category is set to 'all', it's no longer necessary to check the
category before showing the add/delete dialogs and modify the category
before adding entries. Thus, the IPA.rule_association_table_widget is
no longer needed.

Ticket #1692
---
 install/ui/association.js |   29 +++++++++----------
 install/ui/hbac.js        |   32 ++++++++-------------
 install/ui/ipa.css        |   11 +-------
 install/ui/rule.js        |   66 ---------------------------------------------
 install/ui/search.js      |    9 +++---
 install/ui/sudo.js        |   27 ++++++------------
 6 files changed, 40 insertions(+), 134 deletions(-)

diff --git a/install/ui/association.js b/install/ui/association.js
index 4ee36934d2a4f2f15e33aa3e7e096888dc2bb187..b79a18f061229e51cc9534aadea38b8e2636a984 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -350,32 +350,32 @@ IPA.association_table_widget = function (spec) {
 
         that.table_create(container);
 
-        var button = IPA.action_button({
+        var remove_button = IPA.action_button({
             name: 'remove',
             label: IPA.messages.buttons.remove,
             icon: 'remove-icon',
             click: function() {
-                that.remove_handler();
+                if (!remove_button.hasClass('action-button-disabled')) {
+                    that.remove_handler();
+                }
                 return false;
             }
         }).appendTo(that.buttons);
 
-        button = IPA.action_button({
+        var add_button = IPA.action_button({
             name: 'add',
             label: IPA.messages.buttons.add,
             icon: 'add-icon',
             click: function() {
-                that.add_handler();
+                if (!add_button.hasClass('action-button-disabled')) {
+                    that.add_handler();
+                }
                 return false;
             }
         }).appendTo(that.buttons);
     };
 
     that.add_handler = function() {
-        if ($(this).hasClass('action-button-disabled')) {
-            return;
-        }
-
         var facet = that.entity.get_facet();
 
         if (facet.is_dirty()) {
@@ -396,10 +396,6 @@ IPA.association_table_widget = function (spec) {
     };
 
     that.remove_handler = function() {
-        if ($(this).hasClass('action-button-disabled')) {
-            return;
-        }
-
         var facet = that.entity.get_facet();
 
         if (facet.is_dirty()) {
@@ -838,7 +834,6 @@ IPA.association_facet = function (spec) {
         that.facet_create_header(container);
 
         that.pkey = IPA.nav.get_state(that.entity.name+'-pkey');
-        var other_label = IPA.metadata.objects[that.other_entity].label;
 
         if (!that.read_only) {
             that.remove_button = IPA.action_button({
@@ -846,7 +841,9 @@ IPA.association_facet = function (spec) {
                 label: IPA.messages.buttons.remove,
                 icon: 'remove-icon',
                 click: function() {
-                    that.show_remove_dialog();
+                    if (!that.remove_button.hasClass('action-button-disabled')) {
+                        that.show_remove_dialog();
+                    }
                     return false;
                 }
             }).appendTo(that.controls);
@@ -856,7 +853,9 @@ IPA.association_facet = function (spec) {
                 label: IPA.messages.buttons.enroll,
                 icon: 'add-icon',
                 click: function() {
-                    that.show_add_dialog();
+                    if (!that.add_button.hasClass('action-button-disabled')) {
+                        that.show_add_dialog();
+                    }
                     return false;
                 }
             }).appendTo(that.controls);
diff --git a/install/ui/hbac.js b/install/ui/hbac.js
index 274c52d6839c2ec39ed118ada49084563802aa74..3223e0f31c4fc0b6357a0b65288554b48bd4382a 100644
--- a/install/ui/hbac.js
+++ b/install/ui/hbac.js
@@ -181,22 +181,20 @@ IPA.hbacrule_details_facet = function(spec) {
             ]
         });
 
-        var category = section.add_field(IPA.radio_widget({
+        section.add_field(IPA.radio_widget({
             name: 'usercategory'
         }));
-        section.add_field(IPA.rule_association_table_widget({
+        section.add_field(IPA.association_table_widget({
             id: that.entity.name+'-memberuser_user',
             name: 'memberuser_user',
-            category: category,
             add_method: 'add_user',
             remove_method: 'remove_user',
             add_title: IPA.messages.association.add.member,
             remove_title: IPA.messages.association.remove.member
         }));
-        section.add_field(IPA.rule_association_table_widget({
+        section.add_field(IPA.association_table_widget({
             id: that.entity.name+'-memberuser_group',
             name: 'memberuser_group',
-            category: category,
             add_method: 'add_user',
             remove_method: 'remove_user',
             add_title: IPA.messages.association.add.member,
@@ -222,22 +220,20 @@ IPA.hbacrule_details_facet = function(spec) {
         ]
         });
 
-        var category = section.add_field(IPA.radio_widget({
+        section.add_field(IPA.radio_widget({
             name: 'hostcategory'
         }));
-        section.add_field(IPA.rule_association_table_widget({
+        section.add_field(IPA.association_table_widget({
             id: that.entity.name+'-memberhost_host',
             name: 'memberhost_host',
-            category: category,
             add_method: 'add_host',
             remove_method: 'remove_host',
             add_title: IPA.messages.association.add.member,
             remove_title: IPA.messages.association.remove.member
         }));
-        section.add_field(IPA.rule_association_table_widget({
+        section.add_field(IPA.association_table_widget({
             id: that.entity.name+'-memberhost_hostgroup',
             name: 'memberhost_hostgroup',
-            category: category,
             add_method: 'add_host',
             remove_method: 'remove_host',
             add_title: IPA.messages.association.add.member,
@@ -264,22 +260,20 @@ IPA.hbacrule_details_facet = function(spec) {
             ]
         });
 
-        var category = section.add_field(IPA.radio_widget({
+        section.add_field(IPA.radio_widget({
             name: 'servicecategory'
         }));
-        section.add_field(IPA.rule_association_table_widget({
+        section.add_field(IPA.association_table_widget({
             id: that.entity.name+'-memberservice_hbacsvc',
             name: 'memberservice_hbacsvc',
-            category: category,
             add_method: 'add_service',
             remove_method: 'remove_service',
             add_title: IPA.messages.association.add.member,
             remove_title: IPA.messages.association.remove.member
         }));
-        section.add_field(IPA.rule_association_table_widget({
+        section.add_field(IPA.association_table_widget({
             id: that.entity.name+'-memberservice_hbacsvcgroup',
             name: 'memberservice_hbacsvcgroup',
-            category: category,
             add_method: 'add_service',
             remove_method: 'remove_service',
             add_title: IPA.messages.association.add.member,
@@ -305,22 +299,20 @@ IPA.hbacrule_details_facet = function(spec) {
             ]
         });
 
-        var category = section.add_field(IPA.radio_widget({
+        section.add_field(IPA.radio_widget({
             name: 'sourcehostcategory'
         }));
-        section.add_field(IPA.rule_association_table_widget({
+        section.add_field(IPA.association_table_widget({
             id: that.entity.name+'-sourcehost_host',
             name: 'sourcehost_host',
-            category: category,
             add_method: 'add_sourcehost',
             remove_method: 'remove_sourcehost',
             add_title: IPA.messages.association.add.sourcehost,
             remove_title: IPA.messages.association.remove.sourcehost
         }));
-        section.add_field(IPA.rule_association_table_widget({
+        section.add_field(IPA.association_table_widget({
             id: that.entity.name+'-sourcehost_hostgroup',
             name: 'sourcehost_hostgroup',
-            category: category,
             add_method: 'add_sourcehost',
             remove_method: 'remove_sourcehost',
             add_title: IPA.messages.association.add.sourcehost,
diff --git a/install/ui/ipa.css b/install/ui/ipa.css
index 9f94d470b12f3643a65fa03ae5a8f1384d551510..705e9a11ebf54771669172a85025d17b18aa2ae2 100644
--- a/install/ui/ipa.css
+++ b/install/ui/ipa.css
@@ -130,15 +130,6 @@ body {
     cursor: pointer;
 }
 
-.input_link_disabled {
-    cursor: default;
-    color:black;
-}
-
-.input_link_label {
-
-}
-
 .icon {
     display: inline-block;
     height: 16px;
@@ -1034,7 +1025,7 @@ span.main-separator{
     padding: 0 0.2em;
 }
 
-a.action-button-disabled {
+.action-button-disabled {
     color: gray;
     cursor: default;
 }
diff --git a/install/ui/rule.js b/install/ui/rule.js
index 44f037f16446cdb354789f708c31d3d5ed096b03..d9602f689a84d1db436dc33e658bda165e678d1d 100644
--- a/install/ui/rule.js
+++ b/install/ui/rule.js
@@ -104,69 +104,3 @@ IPA.rule_details_section = function(spec) {
 
     return that;
 };
-
-
-IPA.rule_association_table_widget = function(spec) {
-
-    spec = spec || {};
-
-    var that = IPA.association_table_widget(spec);
-
-    that.category = spec.category;
-
-    that.show_add_dialog = function() {
-        if (that.category) {
-            var values = that.category.save();
-            if (values[0] !== '') return;
-        }
-        that.association_table_widget_show_add_dialog();
-    };
-
-    that.show_remove_dialog = function() {
-        if (that.category) {
-            var values = that.category.save();
-            if (values[0] !== '') return;
-        }
-        that.association_table_widget_show_remove_dialog();
-    };
-
-    that.add = function(values, on_success, on_error) {
-
-        var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
-
-        var batch = IPA.batch_command({
-            'on_success': on_success,
-            'on_error': on_error
-        });
-
-        var command;
-
-        if (that.category) {
-            command = IPA.command({
-                entity: that.entity.name,
-                method: 'mod',
-                args: [pkey],
-                options: {all: true, rights: true},
-                on_success: function() {
-                    var record = {};
-                    record[that.category.name] = [''];
-                    that.category.load(record);
-                }
-            });
-            command.set_option(that.category.name, '');
-            batch.add_command(command);
-        }
-
-        command = IPA.command({
-            entity: that.entity.name,
-            method: that.add_method,
-            args: [pkey]
-        });
-        command.set_option(that.other_entity, values.join(','));
-        batch.add_command(command);
-
-        batch.execute();
-    };
-
-    return that;
-};
diff --git a/install/ui/search.js b/install/ui/search.js
index 454ecf45310fadcbc0f758670609be5647cec95f..c469debc8f76deac0ba72f60c55f3790b8cc6ea2 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -146,10 +146,9 @@ IPA.search_facet = function(spec) {
             label: IPA.messages.buttons.remove,
             icon: 'remove-icon',
             click: function() {
-                if (that.remove_button.hasClass('input_link_disabled')) {
-                    return false;
+                if (!that.remove_button.hasClass('action-button-disabled')) {
+                    that.remove();
                 }
-                that.remove();
                 return false;
             }
         }).appendTo(that.controls);
@@ -181,9 +180,9 @@ IPA.search_facet = function(spec) {
 
         if (that.remove_button) {
             if (values.length === 0) {
-                that.remove_button.addClass('input_link_disabled');
+                that.remove_button.addClass('action-button-disabled');
             } else {
-                that.remove_button.removeClass('input_link_disabled');
+                that.remove_button.removeClass('action-button-disabled');
             }
         }
     };
diff --git a/install/ui/sudo.js b/install/ui/sudo.js
index 375ca93acc5156b68ef3b3f31d9fa69d02a16040..8d33550c0d7c25bc8f882084cb8a04662a54ebd7 100644
--- a/install/ui/sudo.js
+++ b/install/ui/sudo.js
@@ -180,7 +180,7 @@ IPA.sudorule_details_facet = function(spec) {
             ]
         });
 
-        var category = section.add_field(IPA.radio_widget({
+        section.add_field(IPA.radio_widget({
             entity: that.entity,
             name: 'usercategory'
         }));
@@ -188,7 +188,6 @@ IPA.sudorule_details_facet = function(spec) {
             id: that.entity.name+'-memberuser_user',
             entity: that.entity,
             name: 'memberuser_user',
-            category: category,
             add_method: 'add_user',
             remove_method: 'remove_user',
             external: 'externaluser',
@@ -199,7 +198,6 @@ IPA.sudorule_details_facet = function(spec) {
             id: that.entity.name+'-memberuser_group',
             entity: that.entity,
             name: 'memberuser_group',
-            category: category,
             add_method: 'add_user',
             remove_method: 'remove_user',
             add_title: IPA.messages.association.add.member,
@@ -224,7 +222,7 @@ IPA.sudorule_details_facet = function(spec) {
             ]
         });
 
-        var category = section.add_field(IPA.radio_widget({
+        section.add_field(IPA.radio_widget({
             entity: that.entity,
             name: 'hostcategory'
         }));
@@ -232,7 +230,6 @@ IPA.sudorule_details_facet = function(spec) {
             id: that.entity.name+'-memberhost_host',
             entity: that.entity,
             name: 'memberhost_host',
-            category: category,
             add_method: 'add_host',
             remove_method: 'remove_host',
             external: 'externalhost',
@@ -243,7 +240,6 @@ IPA.sudorule_details_facet = function(spec) {
             id: that.entity.name+'-memberhost_hostgroup',
             entity: that.entity,
             name: 'memberhost_hostgroup',
-            category: category,
             add_method: 'add_host',
             remove_method: 'remove_host',
             add_title: IPA.messages.association.add.member,
@@ -680,26 +676,24 @@ IPA.sudo.rule_details_command_section = function(spec) {
                 ]
             }));
 
-        that.add_field(IPA.rule_association_table_widget({
+        that.add_field(IPA.association_table_widget({
             id: that.entity.name+'-memberallowcmd_sudocmd',
             name: 'memberallowcmd_sudocmd',
-            category: that.category,
             add_method: 'add_allow_command',
             remove_method: 'remove_allow_command',
             add_title: IPA.messages.association.add.memberallowcmd,
             remove_title: IPA.messages.association.remove.memberallowcmd
         }));
-        that.add_field(IPA.rule_association_table_widget({
+        that.add_field(IPA.association_table_widget({
             id: that.entity.name+'-memberallowcmd_sudocmdgroup',
             name: 'memberallowcmd_sudocmdgroup',
-            category: that.category,
             add_method: 'add_allow_command',
             remove_method: 'remove_allow_command',
             add_title: IPA.messages.association.add.memberallowcmd,
             remove_title: IPA.messages.association.remove.memberallowcmd
         }));
 
-        that.add_field(IPA.rule_association_table_widget({
+        that.add_field(IPA.association_table_widget({
             id: that.entity.name+'-memberdenycmd_sudocmd',
             name: 'memberdenycmd_sudocmd',
             add_method: 'add_deny_command',
@@ -707,7 +701,7 @@ IPA.sudo.rule_details_command_section = function(spec) {
             add_title: IPA.messages.association.add.memberdenycmd,
             remove_title: IPA.messages.association.remove.memberdenycmd
         }));
-        that.add_field(IPA.rule_association_table_widget({
+        that.add_field(IPA.association_table_widget({
             id: that.entity.name+'-memberdenycmd_sudocmdgroup',
             name: 'memberdenycmd_sudocmdgroup',
             add_method: 'add_deny_command',
@@ -834,7 +828,7 @@ IPA.sudo.rule_details_runas_section = function(spec) {
     var that = IPA.details_section(spec);
 
     function add_extra_fields(){
-        var category = that.add_field(
+        that.add_field(
             IPA.radio_widget({
                 name: 'ipasudorunasusercategory',
                 options:[
@@ -851,7 +845,6 @@ IPA.sudo.rule_details_runas_section = function(spec) {
         that.add_field(IPA.sudorule_association_table_widget({
             id: that.entity.name+'-runasruser_user',
             name: 'ipasudorunas_user',
-            category: category,
             add_method: 'add_runasuser',
             remove_method: 'remove_runasuser',
             add_title: IPA.messages.association.add.ipasudorunas,
@@ -860,14 +853,13 @@ IPA.sudo.rule_details_runas_section = function(spec) {
         that.add_field(IPA.sudorule_association_table_widget({
             id: that.entity.name+'-runasuser_group',
             name: 'ipasudorunas_group',
-            category: category,
             add_method: 'add_runasuser',
             remove_method: 'remove_runasuser',
             add_title: IPA.messages.association.add.ipasudorunas,
             remove_title: IPA.messages.association.remove.ipasudorunas
         }));
 
-        category = that.add_field(
+        that.add_field(
             IPA.radio_widget({
                 name: 'ipasudorunasgroupcategory',
                 options:[
@@ -885,7 +877,6 @@ IPA.sudo.rule_details_runas_section = function(spec) {
         that.add_field(IPA.sudorule_association_table_widget({
             id: that.entity.name+'-runasgroup_group',
             name: 'ipasudorunasgroup_group',
-            category: category,
             add_method: 'add_runasgroup',
             remove_method: 'remove_runasgroup',
             add_title: IPA.messages.association.add.ipasudorunasgroup,
@@ -1020,7 +1011,7 @@ IPA.sudorule_association_table_widget = function(spec) {
 
     spec = spec || {};
 
-    var that = IPA.rule_association_table_widget(spec);
+    var that = IPA.association_table_widget(spec);
 
     that.external = spec.external;
 
-- 
1.7.5.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to