On 11/21/2011 12:23 PM, Endi Sukma Dewata wrote:
The current code assumes that an entity will always have a corresponding
LDAPObject on the server, so it looks for the metadata in a fixed
location. This assumption doesn't work for HBAC Test since it is a
Command, not an LDAPObject, so the metadata has to be obtained from a
different location. A new method get_default_metadata() has been added
to allow each entity to find the metadata from the correct location.

Ticket #388

Updated patch attached.

--
Endi S. Dewata
From 6697f518e26ef44733d675951db8de9b23a95643 Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edew...@redhat.com>
Date: Wed, 16 Nov 2011 21:07:20 -0600
Subject: [PATCH] Fixed entity metadata resolution.

The current code assumes that an entity will always have a corresponding
LDAPObject on the server, so it looks for the metadata in a fixed location.
This assumption doesn't work for HBAC Test since it is a Command, not an
LDAPObject, so the metadata has to be obtained from a different location.
A new method get_default_metadata() has been added to allow each entity
to find the metadata from the correct location.

Ticket #388
---
 install/ui/aci.js                   |   25 +++++++++++++++----------
 install/ui/automount.js             |   15 +++++++++------
 install/ui/dns.js                   |   34 ++++++++++++++++++----------------
 install/ui/entitle.js               |    5 +++--
 install/ui/entity.js                |   33 +++++++++++++++++++++------------
 install/ui/group.js                 |    5 +++--
 install/ui/hbac.js                  |   15 +++++++++------
 install/ui/host.js                  |    5 +++--
 install/ui/hostgroup.js             |    5 +++--
 install/ui/ipa.js                   |   10 ++++------
 install/ui/netgroup.js              |    5 +++--
 install/ui/policy.js                |   10 ++++++----
 install/ui/serverconfig.js          |    5 +++--
 install/ui/service.js               |    5 +++--
 install/ui/sudo.js                  |   15 +++++++++------
 install/ui/test/details_tests.js    |   19 ++++++++++---------
 install/ui/test/entity_tests.js     |   10 +++++-----
 install/ui/test/navigation_tests.js |   22 +++++++++++++++-------
 install/ui/user.js                  |   13 +++++++------
 19 files changed, 149 insertions(+), 107 deletions(-)

diff --git a/install/ui/aci.js b/install/ui/aci.js
index 7f82714c1a409d35b4f82d53f5ba6499357f0e5d..8e9e5433b0211d7c87be2191f54e28442c7bb0e1 100644
--- a/install/ui/aci.js
+++ b/install/ui/aci.js
@@ -29,9 +29,10 @@ IPA.aci.permission_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.facet_groups([ 'privilege' , 'settings' ]).
+        that.builder.facet_groups([ 'privilege' , 'settings' ]).
         search_facet({
             columns: [ 'cn' ]
         }).
@@ -203,9 +204,10 @@ IPA.aci.privilege_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.facet_groups([ 'role', 'settings', 'permission' ]).
+        that.builder.facet_groups([ 'role', 'settings', 'permission' ]).
         search_facet({
             columns: [
                 'cn',
@@ -259,9 +261,10 @@ IPA.aci.role_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.facet_groups([ 'member', 'settings', 'privilege' ]).
+        that.builder.facet_groups([ 'member', 'settings', 'privilege' ]).
         search_facet({
             columns: [
                 'cn',
@@ -308,9 +311,10 @@ IPA.aci.selfservice_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             pagination: false,
             columns: [ 'aciname' ]
         }).
@@ -349,9 +353,10 @@ IPA.aci.delegation_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             pagination: false,
             columns: [ 'aciname' ]
         }).
diff --git a/install/ui/automount.js b/install/ui/automount.js
index 11034ea250d8f4d00ea50e3341a0451770fac8a5..8db08e384126db595244c6f597e5f07355c5f2c4 100644
--- a/install/ui/automount.js
+++ b/install/ui/automount.js
@@ -29,9 +29,10 @@ IPA.automount.location_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.facet_groups([ 'automountmap', 'settings' ]).
+        that.builder.facet_groups([ 'automountmap', 'settings' ]).
         search_facet({
             title: IPA.metadata.objects.automountlocation.label,
             columns:['cn']
@@ -64,9 +65,10 @@ IPA.automount.map_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.containing_entity('automountlocation').
+        that.builder.containing_entity('automountlocation').
         facet_groups([ 'automountkey', 'settings' ]).
         nested_search_facet({
             facet_group: 'automountkey',
@@ -153,9 +155,10 @@ IPA.automount.key_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.containing_entity('automountmap').
+        that.builder.containing_entity('automountmap').
         details_facet({
             sections: [
                 {
diff --git a/install/ui/dns.js b/install/ui/dns.js
index e9505dc8536250009dc9fd40f83760334b3b4c1b..5f8a0d12a77cd71ee4776348dccb2d9fe9e38ceb 100644
--- a/install/ui/dns.js
+++ b/install/ui/dns.js
@@ -29,16 +29,17 @@ IPA.dns.zone_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    if (!IPA.dns_enabled) {
-        var except = {
-            expected: true
-        };
-        throw except;
-    }
+    that.init = function() {
 
-    that.init = function(params) {
+        if (!IPA.dns_enabled) {
+            throw {
+                expected: true
+            };
+        }
 
-        params.builder.facet_groups([ 'dnsrecord', 'settings' ]).
+        that.entity_init();
+
+        that.builder.facet_groups([ 'dnsrecord', 'settings' ]).
         search_facet({
             title: IPA.metadata.objects.dnszone.label,
             columns: [ 'idnsname' ]
@@ -483,16 +484,17 @@ IPA.dns.record_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    if (!IPA.dns_enabled) {
-        var except = {
-            expected: true
-        };
-        throw except;
-    }
+    that.init = function() {
 
-    that.init = function(params) {
+        if (!IPA.dns_enabled) {
+            throw {
+                expected: true
+            };
+        }
 
-        params.builder.containing_entity('dnszone').
+        that.entity_init();
+
+        that.builder.containing_entity('dnszone').
         details_facet({
             post_update_hook:function(data){
                 var result = data.result.result;
diff --git a/install/ui/entitle.js b/install/ui/entitle.js
index 0a87e3eae07230a0a12840b8374dc827059ecbf9..ea838e2cb4d42cc4d8809206cd0c0ec3de736558 100644
--- a/install/ui/entitle.js
+++ b/install/ui/entitle.js
@@ -37,9 +37,10 @@ IPA.entitle.entity = function(spec) {
 
     that.status = IPA.entitle.unregistered;
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.facet_groups([ 'account', 'certificates' ]).
+        that.builder.facet_groups([ 'account', 'certificates' ]).
         details_facet({
             factory: IPA.entitle.details_facet,
             label: IPA.messages.objects.entitle.account,
diff --git a/install/ui/entity.js b/install/ui/entity.js
index 4e5c724472a6c2eac1bd6c562f75e408d3d9828e..a701009a3fa9f19c80fdd602c099e676ca25e638 100644
--- a/install/ui/entity.js
+++ b/install/ui/entity.js
@@ -32,10 +32,12 @@ IPA.entity = function(spec) {
     spec = spec || {};
 
     var that = {};
-    that.metadata = spec.metadata;
+
     that.name = spec.name;
-    that.label = spec.label || spec.metadata.label || spec.name;
-    that.title = spec.title || that.label;
+    that.label = spec.label;
+
+    that.metadata = spec.metadata;
+    that.builder = spec.builder;
 
     that.dialogs = $.ordered_map();
     that.dialog_specs = spec.dialogs || [];
@@ -52,7 +54,21 @@ IPA.entity = function(spec) {
     that.redirect_facet = spec.redirect_facet;
     that.containing_entity = null;
 
-    that.init = function(params) {
+    that.init = function() {
+        if (!that.metadata) {
+            that.metadata = that.get_default_metadata();
+            if (!that.metadata) {
+                throw {
+                    expected: true,
+                    message: "Entity " + that.name + " not supported by server."
+                };
+            }
+        }
+        that.label = that.label || that.metadata.label || that.name;
+    };
+
+    that.get_default_metadata = function() {
+        return IPA.metadata.objects[that.name];
     };
 
     that.get_containing_entity = function() {
@@ -210,6 +226,7 @@ IPA.entity = function(spec) {
         pkey.unshift(IPA.nav.get_state(current_entity.name+'-pkey'));
         return pkey;
     };
+
     /* most entites only require -pkey for their primary keys, but some
        are more specific.  This call allows those entites a place
        to override the other parameters. */
@@ -305,14 +322,6 @@ IPA.entity_builder = function() {
             spec = { name: spec };
         }
 
-        spec.metadata = spec.metadata || IPA.metadata.objects[spec.name];
-        if (!spec.metadata) {
-            throw {
-                expected: true,
-                message: "Entity " + spec.name + "not supported by server."
-            };
-        }
-
         entity = factory(spec);
 
         that.facet_groups([
diff --git a/install/ui/group.js b/install/ui/group.js
index 959a96c40458ece4d8dab704b6ceb2072224cd5c..3604271df648cd8986fd7d5e854c13916d94b00d 100644
--- a/install/ui/group.js
+++ b/install/ui/group.js
@@ -30,9 +30,10 @@ IPA.group.entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns: [
                 'cn',
                 'gidnumber',
diff --git a/install/ui/hbac.js b/install/ui/hbac.js
index cf13e459ee2128aefd0e539ac4e4aa86950c069b..a65ab3711883affd516be1caf7d318d55daca17e 100644
--- a/install/ui/hbac.js
+++ b/install/ui/hbac.js
@@ -33,9 +33,10 @@ IPA.hbac.rule_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             search_all: true,
             columns: [
                 'cn',
@@ -60,9 +61,10 @@ IPA.hbac.service_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns: [
                 'cn',
                 'description'
@@ -125,9 +127,10 @@ IPA.hbac.service_group_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns: [
                 'cn',
                 'description'
diff --git a/install/ui/host.js b/install/ui/host.js
index 357eb3f8f11232e4341d22fcb75d744f8a9ebf5a..94dd6465f6c9e4c432328d1cb32fa58fbfc38b87 100644
--- a/install/ui/host.js
+++ b/install/ui/host.js
@@ -30,9 +30,10 @@ IPA.host.entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns: [
                 'fqdn',
                 'description',
diff --git a/install/ui/hostgroup.js b/install/ui/hostgroup.js
index 00f76f2c6bb90c822874e8f307126fc1f822d028..20e7179fb6e58a3f75bac4e50f6189cab555e2a9 100644
--- a/install/ui/hostgroup.js
+++ b/install/ui/hostgroup.js
@@ -28,9 +28,10 @@ IPA.hostgroup.entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns: [
                 'cn',
                 'description'
diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index 64df8a651b9a59f4ee6338942ac44092d99ffeca..f95e440a3c118b19bdcc0cf3a993e0de11fdbe54 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -191,15 +191,13 @@ var IPA = function() {
 
             builder.entity({
                 factory: factory,
-                name: name
-            });
-
-            var entity = builder.build();
-
-            entity.init({
+                name: name,
                 builder: builder
             });
 
+            var entity = builder.build();
+            entity.init();
+
             return entity;
 
         } catch (e) {
diff --git a/install/ui/netgroup.js b/install/ui/netgroup.js
index 6546c53d54bf446097e6f716652f99b7812b6f60..d54fdfd52eb943c3f35f65fd3e75ab994836ee12 100644
--- a/install/ui/netgroup.js
+++ b/install/ui/netgroup.js
@@ -28,9 +28,10 @@ IPA.netgroup.entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns: [
                 'cn',
                 'description'
diff --git a/install/ui/policy.js b/install/ui/policy.js
index fbabd08302dddf9046e58a4e622bf0857b31cab5..d48cacc493bf02d50c378af59ba0e61ef1084c73 100644
--- a/install/ui/policy.js
+++ b/install/ui/policy.js
@@ -29,9 +29,10 @@ IPA.pwpolicy.entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns:['cn','cospriority']}).
         details_facet({
             sections:[
@@ -79,9 +80,10 @@ IPA.krbtpolicy.entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.details_facet({
+        that.builder.details_facet({
             title: IPA.metadata.objects.krbtpolicy.label,
             sections: [
                 {
diff --git a/install/ui/serverconfig.js b/install/ui/serverconfig.js
index b120c4242db6112991e022d2a4dd3771f62f48b6..e6da7953a87354149b12c89346f21946bfaff62d 100644
--- a/install/ui/serverconfig.js
+++ b/install/ui/serverconfig.js
@@ -29,9 +29,10 @@ IPA.config.entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.details_facet({
+        that.builder.details_facet({
             title: IPA.metadata.objects.config.label,
             sections: [
                 {
diff --git a/install/ui/service.js b/install/ui/service.js
index 5f46822e80f3c05cfc66f7ee08457821e92c3e76..e41da2f990d97969f2be410d17e43047b23cdc95 100644
--- a/install/ui/service.js
+++ b/install/ui/service.js
@@ -29,9 +29,10 @@ IPA.service.entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns: [ 'krbprincipalname' ]
         }).
         details_facet({
diff --git a/install/ui/sudo.js b/install/ui/sudo.js
index 9af6b75a4c26712589aea45782b32ad7e052edf3..1affd0a377fedbd3934a89ada08ed2914fdec5df 100644
--- a/install/ui/sudo.js
+++ b/install/ui/sudo.js
@@ -32,9 +32,10 @@ IPA.sudo.rule_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns: [
                 'cn',
                 'ipaenabledflag',
@@ -58,9 +59,10 @@ IPA.sudo.command_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns: [
                 'sudocmd',
                 'description'
@@ -123,9 +125,10 @@ IPA.sudo.command_group_entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    that.init = function(params) {
+    that.init = function() {
+        that.entity_init();
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns: [
                 'cn',
                 'description'
diff --git a/install/ui/test/details_tests.js b/install/ui/test/details_tests.js
index 0a914920c299bf60ae918cf237da91b154537221..fee170ba0193f2154b82a56135ebf5862bb6f8ab 100644
--- a/install/ui/test/details_tests.js
+++ b/install/ui/test/details_tests.js
@@ -40,12 +40,13 @@ module('details', {
 
         details_container = $('<div id="details"/>').appendTo(document.body);
 
-        var obj_name = 'user';
-        IPA.entity_factories.user=
-            function(){
-                return IPA.entity({name:obj_name,
-                                   metadata:IPA.metadata.objects.user});
-            };
+        IPA.register('user', function(spec) {
+
+            return IPA.entity({
+                name: 'user',
+                metadata: IPA.metadata.objects.user
+            });
+        });
     },
     teardown: function() {
         details_container.remove();
@@ -175,10 +176,10 @@ test("Testing details lifecycle: create, load.", function(){
 
         var that = IPA.entity(spec);
 
-        that.init = function(params) {
-            that.entity_init(params);
+        that.init = function() {
+            that.entity_init();
 
-            params.builder.details_facet({
+            that.builder.details_facet({
                 sections: [
                     {
                         name: 'identity',
diff --git a/install/ui/test/entity_tests.js b/install/ui/test/entity_tests.js
index aa53613a3e1751805326543280d7b0b5dd106179..a81e0b89204e3e06a70f028ebb68848d576da4ba 100644
--- a/install/ui/test/entity_tests.js
+++ b/install/ui/test/entity_tests.js
@@ -35,12 +35,12 @@ module('entity',{
 
                     var that = IPA.entity(spec);
 
-                    that.init = function(params) {
-                        that.entity_init(params);
+                    that.init = function() {
+                        that.entity_init();
 
-                            params.builder.search_facet({
-                                columns: [ 'uid' ]
-                            });
+                        that.builder.search_facet({
+                            columns: [ 'uid' ]
+                        });
                     };
 
                     return that;
diff --git a/install/ui/test/navigation_tests.js b/install/ui/test/navigation_tests.js
index f55e296759e9493e2f9b0fb6426de7cc8dda648e..2fb1e814a0e221752932544c2e5e72d4f5651158 100644
--- a/install/ui/test/navigation_tests.js
+++ b/install/ui/test/navigation_tests.js
@@ -41,10 +41,11 @@ test("Testing IPA.navigation.create().", function() {
     //Force reset of entities
     IPA.entities = $.ordered_map();
 
-    IPA.entity_factories.user =  function() {
+    IPA.register('user', function(spec) {
+
         var that = IPA.entity({
             name: 'user',
-            metadata:IPA.metadata.objects.user,
+            metadata: IPA.metadata.objects.user,
             facets: [
                 {
                     type: 'search'
@@ -57,18 +58,25 @@ test("Testing IPA.navigation.create().", function() {
             same(container.attr('name'), 'user', 'user container name');
             same(container[0].nodeName, 'DIV', 'user container element');
         };
+
         return that;
-    };
-    IPA.entity_factories.group = function(){
-        var that  = IPA.entity({name: 'group',
-                               metadata:IPA.metadata.objects.group});
+    });
+
+    IPA.register('group', function(spec) {
+
+        var that = IPA.entity({
+            name: 'group',
+            metadata: IPA.metadata.objects.group
+        });
+
         that.display = function(container){
             group_mock_called = true;
             same(container.attr('name'), 'group','user container name');
             same(container[0].nodeName, 'DIV', 'user container element');
         };
+
         return that;
-    };
+    });
 
     var navigation_container = $('<div id="navigation"/>').appendTo(document.body);
     var entity_container = $('<div id="content"/>').appendTo(document.body);
diff --git a/install/ui/user.js b/install/ui/user.js
index e06cd42f2037e2deb4efc7139e649119b07b2909..09b4b2a3c8461f09882b2008aefad0d3397c8ca3 100644
--- a/install/ui/user.js
+++ b/install/ui/user.js
@@ -29,14 +29,15 @@ IPA.user.entity = function(spec) {
 
     var that = IPA.entity(spec);
 
-    var link = true;
-    if (IPA.nav && IPA.nav.name == 'self-service') {
-        link = false;
-    }
+    that.init = function() {
+        that.entity_init();
 
-    that.init = function(params) {
+        var link = true;
+        if (IPA.nav && IPA.nav.name == 'self-service') {
+            link = false;
+        }
 
-        params.builder.search_facet({
+        that.builder.search_facet({
             columns: [
                 'uid',
                 'givenname',
-- 
1.7.5.1

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

Reply via email to