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

--
Endi S. Dewata
From a309ce9e7ea55d9b475d6e4753b27b69505fe5c0 Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <[email protected]>
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 
b63660da3f7931765e1b6791cfb8c6d03c1d5870..bb10214192f22d7d96eef2607fa18f3d9256d096
 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' ]
         }).
@@ -106,9 +107,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',
@@ -162,9 +164,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',
@@ -211,9 +214,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' ]
         }).
@@ -252,9 +256,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 
a3fc1549dba506a3bb77e28a5035af8362eda56d..c0e4b89f248f54e012c4c70d26f79a828a71750a
 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 
36781f974473e795515f1ffea9a6d14b12c1866c..9fc3c3c3edec85e6882fbcbe78d09471f08f2ffa
 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' ]
@@ -449,16 +450,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 
bb06f154c8b08bebd822b28271541fede9ac238a..17dc9230f3580e685615e00f37c953fe907d243e
 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 
305fb400726dc4096945eec241a860a548627a10..dbeb07ba4913ce03f8bef2c84712e645d7f66d8a
 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 
31f789a84071bdcfd6e29c318d13d6444812bafe..902d4f18667a525398a7488f4bda0447e9a5d55a
 100644
--- a/install/ui/hbac.js
+++ b/install/ui/hbac.js
@@ -29,9 +29,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',
@@ -54,9 +55,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'
@@ -119,9 +121,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 
84f6204009492c27d35c4b2503828a0795ae93a0..5b6fd1255b61589002b61c848433fe019382b874
 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 
58e25e3f1867b37153727f8b1f7b0cae5cab77f4..246cfacdb9545df13b8810020de4ffc877b903f9
 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 
1dccbe665d00d94ac5dbbfe8c52f54d1c0d0f37e..0e2181dd767618a56c9fd467b613a79469c3ad4c
 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -189,15 +189,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 
dcec180feeb2ae67ad19e7ce12addc707ef165dd..01adfa05f8c56440651c26fa3e1920d66711021b
 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 
4726608c24376f5d0faedeb27d311accc24f9ba6..68610b18ffd50cdd4d8d41f1b7779335efd513fb
 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 
9ecf190c492409080d3d2fd697ada972fadaa720..251d0290460de1dd78cc1cecd173f2101e4f43bb
 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 
c425657a35cc4b81a834b78a14808b548ba7481c..a7a5e4ad7cf400693850e66475e3b88c38e74d2e
 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 
ff680027fd8242122e1238de931f0df5795353b7..9ad8296b02cad7722bb30c81f292a5137eb0cd5f
 100644
--- a/install/ui/sudo.js
+++ b/install/ui/sudo.js
@@ -28,9 +28,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',
@@ -52,9 +53,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'
@@ -117,9 +119,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 
80136649b9624c32867e639f6de82ec6f68d30f1..e8f2f7c709b73aa04cd95b9779a1616aba59e5fe
 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();
@@ -160,10 +161,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 
f655493882d639bc6113cf4525869fcf35ef64dd..d130647ed979d645bb14b6235d7ea04f9c27d20c
 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 
92a23eebe0eafc5ce28f39360cc5589ccd88a6cc..88daa1e04afd1c67792c48df3ec2603cb7fa74de
 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 
a0949d79470572fddac333fa377f1df6da893066..9f97c4ae8a4712bf6e6d73114d150c81b9eff441
 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
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to