This patch is changing netgroup web ui to look more like hbac or sudo rule UI. This change allows to define and display user category, host category and external host.

The core of the change is changing member attributes (user, group, host, hostgroup) to use rule_details_widget instead of separate association facets. In host case it also allows to display and add external hosts.


https://fedorahosted.org/freeipa/ticket/2578

Note: compare to other plugins (HBAC, Sudo) netgroup plugins doesn't have member attrs in takes_param therefore labels for columns have to be explicitly set.

--
Petr Vobornik
From 2cfc983b882f7b86d82142f583ec3dca27617e34 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Wed, 28 Mar 2012 17:53:17 +0200
Subject: [PATCH] Reworked netgroup Web UI to allow setting user/host category

This patch is changing netgroup web ui to look more like hbac or sudo rule UI. This change allows to define and display user category, host category and external host.

The core of the change is changing member attributes (user, group, host, hostgroup) to use rule_details_widget instead of separate association facets. In host case it allows to display and add external hosts.

https://fedorahosted.org/freeipa/ticket/2578
---
 install/ui/netgroup.js             |  273 ++++++++++++++++++++++++++++++++----
 install/ui/test/data/ipa_init.json |   13 ++-
 ipalib/plugins/internal.py         |   11 ++
 3 files changed, 265 insertions(+), 32 deletions(-)

diff --git a/install/ui/netgroup.js b/install/ui/netgroup.js
index d54fdfd52eb943c3f35f65fd3e75ab994836ee12..05f9d0ddc9c6a35b3b63275d6137fd6bff74f3d3 100644
--- a/install/ui/netgroup.js
+++ b/install/ui/netgroup.js
@@ -22,7 +22,10 @@
 
 /* REQUIRES: ipa.js, details.js, search.js, add.js, facet.js, entity.js */
 
-IPA.netgroup = {};
+IPA.netgroup = {
+    remove_method_priority: IPA.config.default_priority - 1,
+    enable_priority: IPA.config.default_priority + 1
+};
 
 IPA.netgroup.entity = function(spec) {
 
@@ -31,42 +34,17 @@ IPA.netgroup.entity = function(spec) {
     that.init = function() {
         that.entity_init();
 
-        that.builder.search_facet({
+        that.builder.facet_groups(['settings', 'member', 'memberof']).
+        search_facet({
             columns: [
                 'cn',
                 'description'
             ]
         }).
         details_facet({
-            sections: [
-                {
-                    name: 'identity',
-                    fields: [
-                        'cn',
-                        {
-                            type: 'textarea',
-                            name: 'description'
-                        },
-                        'nisdomainname'
-                    ]
-                }
-            ]
-        }).
-        association_facet({
-            name: 'memberhost_host',
-            facet_group: 'member'
-        }).
-        association_facet({
-            name: 'memberhost_hostgroup',
-            facet_group: 'member'
-        }).
-        association_facet({
-            name: 'memberuser_user',
-            facet_group: 'member'
-        }).
-        association_facet({
-            name: 'memberuser_group',
-            facet_group: 'member'
+            factory: IPA.netgroup.details_facet,
+            entity: that,
+            command_mode: 'info'
         }).
         association_facet({
             name: 'memberof_netgroup',
@@ -87,4 +65,237 @@ IPA.netgroup.entity = function(spec) {
     return that;
 };
 
+IPA.netgroup.details_facet = function(spec) {
+
+    var entity_name = spec.entity.name;
+
+    //
+    // Identity
+    //
+
+    spec.fields = [
+        {
+            name: 'cn',
+            widget: 'identity.cn'
+        },
+        {
+            type: 'textarea',
+            name: 'description',
+            widget: 'identity.description'
+        },
+        {
+            name: 'nisdomainname',
+            widget: 'identity.nisdomainname'
+        }
+    ];
+
+    spec.widgets = [
+        {
+            type: 'details_table_section',
+            name: 'identity',
+            label: IPA.messages.details.general,
+            widgets: [
+                {
+                    name: 'cn'
+                },
+                {
+                    type: 'textarea',
+                    name: 'description'
+                },
+                {
+                    name: 'nisdomainname',
+                    widget: 'general.nisdomainname'
+                }
+            ]
+        }
+    ];
+
+    //
+    // Users
+    //
+
+    spec.fields.push(
+        {
+            type: 'radio',
+            name: 'usercategory',
+            widget: 'user.rule.usercategory'
+        },
+        {
+            type: 'rule_association_table',
+            name: 'memberuser_user',
+            widget: 'user.rule.memberuser_user',
+            priority: IPA.netgroup.remove_method_priority
+        },
+        {
+            type: 'rule_association_table',
+            name: 'memberuser_group',
+            widget: 'user.rule.memberuser_group',
+            priority: IPA.netgroup.remove_method_priority
+        }
+    );
+
+    spec.widgets.push(
+        {
+            factory: IPA.collapsible_section,
+            name: 'user',
+            label: IPA.messages.objects.netgroup.user,
+            widgets: [
+                {
+                    factory: IPA.rule_details_widget,
+                    name: 'rule',
+                    radio_name: 'usercategory',
+                    options: [
+                        { value: 'all',
+                        label: IPA.messages.objects.netgroup.anyone },
+                        { value: '',
+                        label: IPA.messages.objects.netgroup.specified_users }
+                    ],
+                    tables: [
+                        { name: 'memberuser_user' },
+                        { name: 'memberuser_group' }
+                    ],
+                    widgets: [
+                        {
+                            type: 'rule_association_table',
+                            id: entity_name+'-memberuser_user',
+                            name: 'memberuser_user',
+                            add_method: 'add_member',
+                            remove_method: 'remove_member',
+                            add_title: IPA.messages.association.add.member,
+                            remove_title: IPA.messages.association.remove.member,
+                            columns: [
+                                {
+                                    name: 'memberuser_user',
+                                    label: IPA.messages.objects.netgroup.users
+                                }
+                            ]
+                        },
+                        {
+                            type: 'rule_association_table',
+                            id: entity_name+'-memberuser_group',
+                            name: 'memberuser_group',
+                            add_method: 'add_member',
+                            remove_method: 'remove_member',
+                            add_title: IPA.messages.association.add.member,
+                            remove_title: IPA.messages.association.remove.member,
+                            columns: [
+                                {
+                                    name: 'memberuser_group',
+                                    label: IPA.messages.objects.netgroup.usergroups
+                                }
+                            ]
+                        }
+                    ]
+                }
+            ]
+        }
+    );
+
+    //
+    // Hosts
+    //
+
+    spec.fields.push(
+        {
+            type: 'radio',
+            name: 'hostcategory',
+            widget: 'host.rule.hostcategory'
+        },
+        {
+            type: 'rule_association_table',
+            name: 'memberhost_host',
+            widget: 'host.rule.memberhost_host',
+            priority: IPA.netgroup.remove_method_priority,
+            external: 'externalhost'
+        },
+        {
+            type: 'rule_association_table',
+            name: 'memberhost_hostgroup',
+            widget: 'host.rule.memberhost_hostgroup',
+            priority: IPA.netgroup.remove_method_priority
+        }
+    );
+
+    spec.widgets.push(
+        {
+            factory: IPA.collapsible_section,
+            name: 'host',
+            label: IPA.messages.objects.netgroup.host,
+            widgets: [
+                {
+                    factory: IPA.rule_details_widget,
+                    name: 'rule',
+                    radio_name: 'hostcategory',
+                    options: [
+                        {
+                            'value': 'all',
+                            'label': IPA.messages.objects.netgroup.any_host
+                        },
+                        {
+                            'value': '',
+                            'label': IPA.messages.objects.netgroup.specified_hosts
+                        }
+                    ],
+                    tables: [
+                        { 'name': 'memberhost_host' },
+                        { 'name': 'memberhost_hostgroup' }
+                    ],
+                    widgets: [
+                        {
+                            type: 'rule_association_table',
+                            id: entity_name+'-memberhost_host',
+                            name: 'memberhost_host',
+                            add_method: 'add_member',
+                            remove_method: 'remove_member',
+                            external: 'externalhost',
+                            add_title: IPA.messages.association.add.member,
+                            remove_title: IPA.messages.association.remove.member,
+                            columns: [
+                                {
+                                    name: 'memberhost_host',
+                                    label: IPA.messages.objects.netgroup.hosts
+                                },
+                                {
+                                    name: 'externalhost',
+                                    label: IPA.messages.objects.netgroup.external,
+                                    formatter: IPA.boolean_formatter(),
+                                    width: '200px'
+                                }
+                            ]
+                        },
+                        {
+                            type: 'rule_association_table',
+                            id: entity_name+'-memberhost_hostgroup',
+                            name: 'memberhost_hostgroup',
+                            add_method: 'add_member',
+                            remove_method: 'remove_member',
+                            add_title: IPA.messages.association.add.member,
+                            remove_title: IPA.messages.association.remove.member,
+                            columns: [
+                                {
+                                    name: 'memberhost_hostgroup',
+                                    label: IPA.messages.objects.netgroup.hostgroups
+                                }
+                            ]
+                        }
+                    ]
+                }
+            ]
+        }
+    );
+
+    var that = IPA.details_facet(spec);
+
+    that.update_on_success = function(data, text_status, xhr) {
+        that.refresh();
+        that.on_update.notify();
+    };
+
+    that.update_on_error = function(xhr, text_status, error_thrown) {
+        that.refresh();
+    };
+
+    return that;
+};
+
 IPA.register('netgroup', IPA.netgroup.entity);
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index 6eed01e924abac09eaba843be7d2be8d5b75ce9c..7dc1344d1e683ab0be9119147ad7449c5368213e 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -312,7 +312,18 @@
                             "identity": "Kerberos Ticket Policy"
                         },
                         "netgroup": {
-                            "identity": "Netgroup Settings"
+                            "any_host": "Any Host",
+                            "anyone": "Anyone",
+                            "external": "External",
+                            "host": "Host",
+                            "hostgroups": "Host Groups",
+                            "hosts": "Hosts",
+                            "identity": "Netgroup Settings",
+                            "specified_hosts": "Specified Hosts and Groups",
+                            "specified_users": "Specified Users and Groups",
+                            "user": "User",
+                            "usergroups": "User Groups",
+                            "users": "Users"
                         },
                         "permission": {
                             "identity": "Identity",
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index 8ce3a00678fec4396cf5bbcdcd2b596bdb751820..2f0948aea904dc11325d850b8ea78ccf228fe9f4 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -450,7 +450,18 @@ class i18n_messages(Command):
                 "identity": _("Kerberos Ticket Policy"),
                 },
             "netgroup": {
+                "any_host": _("Any Host"),
+                "anyone": _("Anyone"),
+                "external": _("External"),
+                "host": _("Host"),
+                "hostgroups": _("Host Groups"),
+                "hosts": _("Hosts"),
                 "identity": _("Netgroup Settings"),
+                "specified_hosts": _("Specified Hosts and Groups"),
+                "specified_users": _("Specified Users and Groups"),
+                "user": _("User"),
+                "usergroups": _("User Groups"),
+                "users": _("Users"),
                 },
             "permission": {
                 "identity": _("Identity"),
-- 
1.7.7.6

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

Reply via email to