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
This commit is contained in:
Endi Sukma Dewata
2011-11-16 21:07:20 -06:00
committed by Endi S. Dewata
parent 6f0c16e428
commit a8ea42bda8
19 changed files with 148 additions and 106 deletions

View File

@@ -29,9 +29,10 @@ IPA.aci.permission_entity = function(spec) {
var that = IPA.entity(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({ search_facet({
columns: [ 'cn' ] columns: [ 'cn' ]
}). }).
@@ -203,9 +204,10 @@ IPA.aci.privilege_entity = function(spec) {
var that = IPA.entity(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({ search_facet({
columns: [ columns: [
'cn', 'cn',
@@ -259,9 +261,10 @@ IPA.aci.role_entity = function(spec) {
var that = IPA.entity(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({ search_facet({
columns: [ columns: [
'cn', 'cn',
@@ -308,9 +311,10 @@ IPA.aci.selfservice_entity = function(spec) {
var that = IPA.entity(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, pagination: false,
columns: [ 'aciname' ] columns: [ 'aciname' ]
}). }).
@@ -349,9 +353,10 @@ IPA.aci.delegation_entity = function(spec) {
var that = IPA.entity(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, pagination: false,
columns: [ 'aciname' ] columns: [ 'aciname' ]
}). }).

View File

@@ -29,9 +29,10 @@ IPA.automount.location_entity = function(spec) {
var that = IPA.entity(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({ search_facet({
title: IPA.metadata.objects.automountlocation.label, title: IPA.metadata.objects.automountlocation.label,
columns:['cn'] columns:['cn']
@@ -64,9 +65,10 @@ IPA.automount.map_entity = function(spec) {
var that = IPA.entity(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' ]). facet_groups([ 'automountkey', 'settings' ]).
nested_search_facet({ nested_search_facet({
facet_group: 'automountkey', facet_group: 'automountkey',
@@ -153,9 +155,10 @@ IPA.automount.key_entity = function(spec) {
var that = IPA.entity(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({ details_facet({
sections: [ sections: [
{ {

View File

@@ -29,16 +29,17 @@ IPA.dns.zone_entity = function(spec) {
var that = IPA.entity(spec); var that = IPA.entity(spec);
that.init = function() {
if (!IPA.dns_enabled) { if (!IPA.dns_enabled) {
var except = { throw {
expected: true expected: true
}; };
throw except;
} }
that.init = function(params) { that.entity_init();
params.builder.facet_groups([ 'dnsrecord', 'settings' ]). that.builder.facet_groups([ 'dnsrecord', 'settings' ]).
search_facet({ search_facet({
title: IPA.metadata.objects.dnszone.label, title: IPA.metadata.objects.dnszone.label,
columns: [ 'idnsname' ] columns: [ 'idnsname' ]
@@ -483,16 +484,17 @@ IPA.dns.record_entity = function(spec) {
var that = IPA.entity(spec); var that = IPA.entity(spec);
that.init = function() {
if (!IPA.dns_enabled) { if (!IPA.dns_enabled) {
var except = { throw {
expected: true expected: true
}; };
throw except;
} }
that.init = function(params) { that.entity_init();
params.builder.containing_entity('dnszone'). that.builder.containing_entity('dnszone').
details_facet({ details_facet({
post_update_hook:function(data){ post_update_hook:function(data){
var result = data.result.result; var result = data.result.result;

View File

@@ -37,9 +37,10 @@ IPA.entitle.entity = function(spec) {
that.status = IPA.entitle.unregistered; 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({ details_facet({
factory: IPA.entitle.details_facet, factory: IPA.entitle.details_facet,
label: IPA.messages.objects.entitle.account, label: IPA.messages.objects.entitle.account,

View File

@@ -32,10 +32,12 @@ IPA.entity = function(spec) {
spec = spec || {}; spec = spec || {};
var that = {}; var that = {};
that.metadata = spec.metadata;
that.name = spec.name; that.name = spec.name;
that.label = spec.label || spec.metadata.label || spec.name; that.label = spec.label;
that.title = spec.title || that.label;
that.metadata = spec.metadata;
that.builder = spec.builder;
that.dialogs = $.ordered_map(); that.dialogs = $.ordered_map();
that.dialog_specs = spec.dialogs || []; that.dialog_specs = spec.dialogs || [];
@@ -52,7 +54,21 @@ IPA.entity = function(spec) {
that.redirect_facet = spec.redirect_facet; that.redirect_facet = spec.redirect_facet;
that.containing_entity = null; 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() { that.get_containing_entity = function() {
@@ -210,6 +226,7 @@ IPA.entity = function(spec) {
pkey.unshift(IPA.nav.get_state(current_entity.name+'-pkey')); pkey.unshift(IPA.nav.get_state(current_entity.name+'-pkey'));
return pkey; return pkey;
}; };
/* most entites only require -pkey for their primary keys, but some /* most entites only require -pkey for their primary keys, but some
are more specific. This call allows those entites a place are more specific. This call allows those entites a place
to override the other parameters. */ to override the other parameters. */
@@ -305,14 +322,6 @@ IPA.entity_builder = function() {
spec = { name: spec }; 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); entity = factory(spec);
that.facet_groups([ that.facet_groups([

View File

@@ -30,9 +30,10 @@ IPA.group.entity = function(spec) {
var that = IPA.entity(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: [ columns: [
'cn', 'cn',
'gidnumber', 'gidnumber',

View File

@@ -33,9 +33,10 @@ IPA.hbac.rule_entity = function(spec) {
var that = IPA.entity(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, search_all: true,
columns: [ columns: [
'cn', 'cn',
@@ -60,9 +61,10 @@ IPA.hbac.service_entity = function(spec) {
var that = IPA.entity(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: [ columns: [
'cn', 'cn',
'description' 'description'
@@ -125,9 +127,10 @@ IPA.hbac.service_group_entity = function(spec) {
var that = IPA.entity(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: [ columns: [
'cn', 'cn',
'description' 'description'

View File

@@ -30,9 +30,10 @@ IPA.host.entity = function(spec) {
var that = IPA.entity(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: [ columns: [
'fqdn', 'fqdn',
'description', 'description',

View File

@@ -28,9 +28,10 @@ IPA.hostgroup.entity = function(spec) {
var that = IPA.entity(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: [ columns: [
'cn', 'cn',
'description' 'description'

View File

@@ -191,14 +191,12 @@ var IPA = function() {
builder.entity({ builder.entity({
factory: factory, factory: factory,
name: name name: name,
builder: builder
}); });
var entity = builder.build(); var entity = builder.build();
entity.init();
entity.init({
builder: builder
});
return entity; return entity;

View File

@@ -28,9 +28,10 @@ IPA.netgroup.entity = function(spec) {
var that = IPA.entity(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: [ columns: [
'cn', 'cn',
'description' 'description'

View File

@@ -29,9 +29,10 @@ IPA.pwpolicy.entity = function(spec) {
var that = IPA.entity(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']}). columns:['cn','cospriority']}).
details_facet({ details_facet({
sections:[ sections:[
@@ -79,9 +80,10 @@ IPA.krbtpolicy.entity = function(spec) {
var that = IPA.entity(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, title: IPA.metadata.objects.krbtpolicy.label,
sections: [ sections: [
{ {

View File

@@ -29,9 +29,10 @@ IPA.config.entity = function(spec) {
var that = IPA.entity(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, title: IPA.metadata.objects.config.label,
sections: [ sections: [
{ {

View File

@@ -29,9 +29,10 @@ IPA.service.entity = function(spec) {
var that = IPA.entity(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' ] columns: [ 'krbprincipalname' ]
}). }).
details_facet({ details_facet({

View File

@@ -32,9 +32,10 @@ IPA.sudo.rule_entity = function(spec) {
var that = IPA.entity(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: [ columns: [
'cn', 'cn',
'ipaenabledflag', 'ipaenabledflag',
@@ -58,9 +59,10 @@ IPA.sudo.command_entity = function(spec) {
var that = IPA.entity(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: [ columns: [
'sudocmd', 'sudocmd',
'description' 'description'
@@ -123,9 +125,10 @@ IPA.sudo.command_group_entity = function(spec) {
var that = IPA.entity(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: [ columns: [
'cn', 'cn',
'description' 'description'

View File

@@ -40,12 +40,13 @@ module('details', {
details_container = $('<div id="details"/>').appendTo(document.body); details_container = $('<div id="details"/>').appendTo(document.body);
var obj_name = 'user'; IPA.register('user', function(spec) {
IPA.entity_factories.user=
function(){ return IPA.entity({
return IPA.entity({name:obj_name, name: 'user',
metadata:IPA.metadata.objects.user}); metadata: IPA.metadata.objects.user
}; });
});
}, },
teardown: function() { teardown: function() {
details_container.remove(); details_container.remove();
@@ -175,10 +176,10 @@ test("Testing details lifecycle: create, load.", function(){
var that = IPA.entity(spec); var that = IPA.entity(spec);
that.init = function(params) { that.init = function() {
that.entity_init(params); that.entity_init();
params.builder.details_facet({ that.builder.details_facet({
sections: [ sections: [
{ {
name: 'identity', name: 'identity',

View File

@@ -35,10 +35,10 @@ module('entity',{
var that = IPA.entity(spec); var that = IPA.entity(spec);
that.init = function(params) { that.init = function() {
that.entity_init(params); that.entity_init();
params.builder.search_facet({ that.builder.search_facet({
columns: [ 'uid' ] columns: [ 'uid' ]
}); });
}; };

View File

@@ -41,10 +41,11 @@ test("Testing IPA.navigation.create().", function() {
//Force reset of entities //Force reset of entities
IPA.entities = $.ordered_map(); IPA.entities = $.ordered_map();
IPA.entity_factories.user = function() { IPA.register('user', function(spec) {
var that = IPA.entity({ var that = IPA.entity({
name: 'user', name: 'user',
metadata:IPA.metadata.objects.user, metadata: IPA.metadata.objects.user,
facets: [ facets: [
{ {
type: 'search' type: 'search'
@@ -57,18 +58,25 @@ test("Testing IPA.navigation.create().", function() {
same(container.attr('name'), 'user', 'user container name'); same(container.attr('name'), 'user', 'user container name');
same(container[0].nodeName, 'DIV', 'user container element'); same(container[0].nodeName, 'DIV', 'user container element');
}; };
return that; return that;
}; });
IPA.entity_factories.group = function(){
var that = IPA.entity({name: 'group', IPA.register('group', function(spec) {
metadata:IPA.metadata.objects.group});
var that = IPA.entity({
name: 'group',
metadata: IPA.metadata.objects.group
});
that.display = function(container){ that.display = function(container){
group_mock_called = true; group_mock_called = true;
same(container.attr('name'), 'group','user container name'); same(container.attr('name'), 'group','user container name');
same(container[0].nodeName, 'DIV', 'user container element'); same(container[0].nodeName, 'DIV', 'user container element');
}; };
return that; return that;
}; });
var navigation_container = $('<div id="navigation"/>').appendTo(document.body); var navigation_container = $('<div id="navigation"/>').appendTo(document.body);
var entity_container = $('<div id="content"/>').appendTo(document.body); var entity_container = $('<div id="content"/>').appendTo(document.body);

View File

@@ -29,14 +29,15 @@ IPA.user.entity = function(spec) {
var that = IPA.entity(spec); var that = IPA.entity(spec);
that.init = function() {
that.entity_init();
var link = true; var link = true;
if (IPA.nav && IPA.nav.name == 'self-service') { if (IPA.nav && IPA.nav.name == 'self-service') {
link = false; link = false;
} }
that.init = function(params) { that.builder.search_facet({
params.builder.search_facet({
columns: [ columns: [
'uid', 'uid',
'givenname', 'givenname',