Hi,

The attached patch should fix the following bug:
https://fedorahosted.org/freeipa/ticket/672

A section has been added to the SUDO command details page for managing
the association with SUDO command groups. New test data has been added
as well.

--
Endi S. Dewata
From e47452b56b5f57ca5e385a9718069c5fe9c62d9c Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Tue, 11 Jan 2011 17:07:46 +0700
Subject: [PATCH] Added group association table for SUDO command.

A section has been added to the SUDO command details page for managing
the association with SUDO command groups. New test data has been added
as well.
---
 install/static/sudocmd.js                          |  159 ++++++++++++++++++++
 install/static/sudocmdgroup.js                     |    1 +
 install/static/test/data/sudocmd_memberof_add.json |   53 +++++++
 .../static/test/data/sudocmd_memberof_remove.json  |   50 ++++++
 .../static/test/data/sudocmd_memberof_show.json    |   61 ++++++++
 install/static/test/data/sudocmd_show.json         |    4 +
 6 files changed, 328 insertions(+), 0 deletions(-)
 create mode 100644 install/static/test/data/sudocmd_memberof_add.json
 create mode 100644 install/static/test/data/sudocmd_memberof_remove.json
 create mode 100644 install/static/test/data/sudocmd_memberof_show.json

diff --git a/install/static/sudocmd.js b/install/static/sudocmd.js
index 864063f629a9bb932bfd813cc22cfa546b321e39..307f0990055e0e7b9a6a43386bb1e467a71c5480 100755
--- a/install/static/sudocmd.js
+++ b/install/static/sudocmd.js
@@ -107,8 +107,167 @@ function ipa_sudocmd_details_facet(spec) {
         section.create_field({'name': 'sudocmd'});
         section.create_field({'name': 'description'});
 
+        section = ipa_details_section({
+            'name': 'groups',
+            'label': 'Groups'
+        });
+        that.add_section(section);
+
+        var field = ipa_sudocmd_member_sudocmdgroup_table_widget({
+            'name': 'memberof',
+            'label': 'Groups',
+            'other_entity': 'sudocmdgroup',
+            'save_values': false
+        });
+        section.add_field(field);
+
         that.details_facet_init();
     };
 
     return that;
+}
+
+function ipa_sudocmd_member_sudocmdgroup_table_widget(spec) {
+
+    spec = spec || {};
+
+    var that = ipa_association_table_widget(spec);
+
+    that.init = function() {
+
+        var column = that.create_column({
+            name: 'cn',
+            primary_key: true,
+            width: '150px'
+        });
+
+        column.setup = function(container, record) {
+            container.empty();
+
+            var value = record[column.name];
+            value = value ? value.toString() : '';
+
+            $('<a/>', {
+                'href': '#'+value,
+                'html': value,
+                'click': function (value) {
+                    return function() {
+                        var state = IPA.tab_state(that.other_entity);
+                        state[that.other_entity + '-facet'] = 'details';
+                        state[that.other_entity + '-pkey'] = value;
+                        $.bbq.pushState(state);
+                        return false;
+                    }
+                }(value)
+            }).appendTo(container);
+        };
+
+        that.create_column({
+            name: 'description',
+            label: 'Description',
+            width: '150px'
+        });
+
+        that.create_adder_column({
+            name: 'cn',
+            primary_key: true,
+            width: '100px'
+        });
+
+        that.create_adder_column({
+            name: 'description',
+            width: '100px'
+        });
+
+        that.association_table_widget_init();
+    };
+
+    that.get_records = function(on_success, on_error) {
+
+        if (!that.values.length) return;
+
+        var batch = ipa_batch_command({
+            'name': that.entity_name+'_'+that.name+'_show',
+            'on_success': on_success,
+            'on_error': on_error
+        });
+
+        for (var i=0; i<that.values.length; i++) {
+            var dn = that.values[i];
+            var j = dn.indexOf('=');
+            var k = dn.indexOf(',');
+            var value = dn.substring(j+1, k);
+
+            var command = ipa_command({
+                'method': that.other_entity+'_show',
+                'args': [value],
+                'options': {
+                    'all': true,
+                    'rights': true
+                }
+            });
+
+            batch.add_command(command);
+        }
+
+        batch.execute();
+    };
+
+    that.add = function(values, on_success, on_error) {
+
+        if (!values.length) return;
+
+        var batch = ipa_batch_command({
+            'name': that.entity_name+'_'+that.name+'_add',
+            'on_success': on_success,
+            'on_error': on_error
+        });
+
+        var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
+
+        for (var i=0; i<values.length; i++) {
+            var value = values[i];
+
+            var command = ipa_command({
+                'method': that.other_entity+'_add_member',
+                'args': [value]
+            });
+
+            command.set_option('sudocmd', pkey);
+
+            batch.add_command(command);
+        }
+
+        batch.execute();
+    };
+
+    that.remove = function(values, on_success, on_error) {
+
+        if (!values.length) return;
+
+        var batch = ipa_batch_command({
+            'name': that.entity_name+'_'+that.name+'_remove',
+            'on_success': on_success,
+            'on_error': on_error
+        });
+
+        var pkey = $.bbq.getState(that.entity_name + '-pkey', true) || '';
+
+        for (var i=0; i<values.length; i++) {
+            var value = values[i];
+
+            var command = ipa_command({
+                'method': that.other_entity+'_remove_member',
+                'args': [value]
+            });
+
+            command.set_option('sudocmd', pkey);
+
+            batch.add_command(command);
+        }
+
+        batch.execute();
+    };
+
+    return that;
 }
\ No newline at end of file
diff --git a/install/static/sudocmdgroup.js b/install/static/sudocmdgroup.js
index 1fb5e18991d0820f5f65bcb3025108ec00664403..a78d088b6dad2c8a773d6c9649d2805406de9bad 100755
--- a/install/static/sudocmdgroup.js
+++ b/install/static/sudocmdgroup.js
@@ -169,6 +169,7 @@ function ipa_sudocmdgroup_member_sudocmd_table_widget(spec) {
         };
 
         that.create_column({
+            name: 'description',
             label: 'Description',
             width: '150px'
         });
diff --git a/install/static/test/data/sudocmd_memberof_add.json b/install/static/test/data/sudocmd_memberof_add.json
new file mode 100644
index 0000000000000000000000000000000000000000..e263007d80d3b9c20d95304b4252c122a658b1bf
--- /dev/null
+++ b/install/static/test/data/sudocmd_memberof_add.json
@@ -0,0 +1,53 @@
+{
+    "error": null,
+    "id": 0,
+    "result": {
+        "count": 2,
+        "results": [
+            {
+                "completed": 1,
+                "error": null,
+                "failed": {
+                    "member": {
+                        "sudocmd": [],
+                        "sudocmdgroup": []
+                    }
+                },
+                "result": {
+                    "cn": [
+                        "group1"
+                    ],
+                    "description": [
+                        "Group 1"
+                    ],
+                    "dn": "cn=group1,cn=sudocmdgroups,cn=accounts,dc=ipa",
+                    "member_sudocmd": [
+                        "/usr/bin/less"
+                    ]
+                }
+            },
+            {
+                "completed": 1,
+                "error": null,
+                "failed": {
+                    "member": {
+                        "sudocmd": [],
+                        "sudocmdgroup": []
+                    }
+                },
+                "result": {
+                    "cn": [
+                        "group2"
+                    ],
+                    "description": [
+                        "Group 2"
+                    ],
+                    "dn": "cn=group2,cn=sudocmdgroups,cn=accounts,dc=ipa",
+                    "member_sudocmd": [
+                        "/usr/bin/more"
+                    ]
+                }
+            }
+        ]
+    }
+}
diff --git a/install/static/test/data/sudocmd_memberof_remove.json b/install/static/test/data/sudocmd_memberof_remove.json
new file mode 100644
index 0000000000000000000000000000000000000000..347b5cdedb5ef6424a5df6cc18d0cd4e426baa50
--- /dev/null
+++ b/install/static/test/data/sudocmd_memberof_remove.json
@@ -0,0 +1,50 @@
+{
+    "error": null,
+    "id": 0,
+    "result": {
+        "count": 2,
+        "results": [
+            {
+                "completed": 1,
+                "error": null,
+                "failed": {
+                    "member": {
+                        "sudocmd": [],
+                        "sudocmdgroup": []
+                    }
+                },
+                "result": {
+                    "cn": [
+                        "group1"
+                    ],
+                    "description": [
+                        "Group 1"
+                    ],
+                    "dn": "cn=group1,cn=sudocmdgroups,cn=accounts,dc=ipa"
+                }
+            },
+            {
+                "completed": 1,
+                "error": null,
+                "failed": {
+                    "member": {
+                        "sudocmd": [],
+                        "sudocmdgroup": []
+                    }
+                },
+                "result": {
+                    "cn": [
+                        "group2"
+                    ],
+                    "description": [
+                        "Group 2"
+                    ],
+                    "dn": "cn=group2,cn=sudocmdgroups,cn=accounts,dc=ipa",
+                    "memberindirect_sudocmd": [
+                        "/usr/bin/more"
+                    ]
+                }
+            }
+        ]
+    }
+}
diff --git a/install/static/test/data/sudocmd_memberof_show.json b/install/static/test/data/sudocmd_memberof_show.json
new file mode 100644
index 0000000000000000000000000000000000000000..9b7f3af23789edafeee4e3c58490e92ca4d6175d
--- /dev/null
+++ b/install/static/test/data/sudocmd_memberof_show.json
@@ -0,0 +1,61 @@
+{
+    "error": null,
+    "id": 0,
+    "result": {
+        "count": 2,
+        "results": [
+            {
+                "error": null,
+                "result": {
+                    "cn": [
+                        "group1"
+                    ],
+                    "description": [
+                        "Group 1"
+                    ],
+                    "dn": "cn=group1,cn=sudocmdgroups,cn=accounts,dc=ipa",
+                    "ipauniqueid": [
+                        "fc775d2e-1d56-11e0-b7cd-00163e2fe6de"
+                    ],
+                    "member_sudocmd": [
+                        "/usr/bin/less"
+                    ],
+                    "objectclass": [
+                        "ipaobject",
+                        "ipasudocmdgrp",
+                        "groupOfNames",
+                        "top"
+                    ]
+                },
+                "summary": null,
+                "value": "group1"
+            },
+            {
+                "error": null,
+                "result": {
+                    "cn": [
+                        "group2"
+                    ],
+                    "description": [
+                        "Group 2"
+                    ],
+                    "dn": "cn=group2,cn=sudocmdgroups,cn=accounts,dc=ipa",
+                    "ipauniqueid": [
+                        "b90c1930-1d5b-11e0-ac89-00163e2fe6de"
+                    ],
+                    "member_sudocmd": [
+                        "/usr/bin/more"
+                    ],
+                    "objectclass": [
+                        "ipaobject",
+                        "ipasudocmdgrp",
+                        "groupOfNames",
+                        "top"
+                    ]
+                },
+                "summary": null,
+                "value": "group2"
+            }
+        ]
+    }
+}
diff --git a/install/static/test/data/sudocmd_show.json b/install/static/test/data/sudocmd_show.json
index f9eacc39b07ed0ad53a361948caf6329c4abb4df..a08401d7bf150deaa8bd3436b9b0a8d01143e6cd 100644
--- a/install/static/test/data/sudocmd_show.json
+++ b/install/static/test/data/sudocmd_show.json
@@ -15,6 +15,10 @@
             "ipauniqueid": [
                 "06708d0e-f454-11df-9273-00163e72f2d9"
             ],
+            "memberof": [
+                "cn=group1,cn=sudocmdgroups,cn=accounts,dc=dev,dc=example,dc=com",
+                "cn=group2,cn=sudocmdgroups,cn=accounts,dc=dev,dc=example,dc=com"
+            ],
             "objectclass": [
                 "ipaobject",
                 "ipasudocmd"
-- 
1.6.6.1

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

Reply via email to