Make facet and entity policies declarative

https://fedorahosted.org/freeipa/ticket/3235
This commit is contained in:
Petr Vobornik 2013-04-17 15:48:48 +02:00
parent 33b584f0a0
commit bee39848d3
12 changed files with 93 additions and 54 deletions

View File

@ -132,7 +132,10 @@ IPA.aci.permission_entity = function(spec) {
} }
], ],
policies: [ policies: [
IPA.permission_target_policy('target') {
$factory: IPA.permission_target_policy,
widget_name: 'target'
}
] ]
}). }).
association_facet({ association_facet({
@ -217,7 +220,10 @@ IPA.aci.permission_entity = function(spec) {
} }
], ],
policies: [ policies: [
IPA.permission_target_policy('target') {
$factory: IPA.permission_target_policy,
widget_name: 'target'
}
] ]
}); });
}; };
@ -740,13 +746,14 @@ IPA.permission_target_widget = function(spec) {
return that; return that;
}; };
IPA.permission_target_policy = function (widget_name) { IPA.permission_target_policy = function (spec) {
var that = IPA.facet_policy(); var that = IPA.facet_policy();
that.widget_name = spec.widget_name;
that.init = function() { that.init = function() {
that.permission_target = that.container.widgets.get_widget(widget_name); that.permission_target = that.container.widgets.get_widget(that.widget_name);
var widgets = that.permission_target.widgets; var widgets = that.permission_target.widgets;
var target_select = widgets.get_widget('target'); var target_select = widgets.get_widget('target');

View File

@ -45,14 +45,16 @@ IPA.automember.entity = function(spec) {
spec = spec || {}; spec = spec || {};
spec.policies = spec.policies || [ spec.policies = spec.policies || [
IPA.facet_update_policy({ {
$factory: IPA.facet_update_policy,
source_facet: 'usergrouprule', source_facet: 'usergrouprule',
dest_facet: 'searchgroup' dest_facet: 'searchgroup'
}), },
IPA.facet_update_policy({ {
$factory: IPA.facet_update_policy,
source_facet: 'hostgrouprule', source_facet: 'hostgrouprule',
dest_facet: 'searchhostgroup' dest_facet: 'searchhostgroup'
}) }
]; ];
var that = IPA.entity(spec); var that = IPA.entity(spec);

View File

@ -157,11 +157,12 @@ IPA.automount.key_entity = function(spec) {
spec = spec || {}; spec = spec || {};
spec.policies = spec.policies || [ spec.policies = spec.policies || [
IPA.facet_update_policy({ {
$factory: IPA.facet_update_policy,
source_facet: 'details', source_facet: 'details',
dest_entity: 'automountmap', dest_entity: 'automountmap',
dest_facet: 'keys' dest_facet: 'keys'
}) }
]; ];
var that = IPA.entity(spec); var that = IPA.entity(spec);

View File

@ -948,22 +948,25 @@ IPA.cert.entity = function(spec) {
spec = spec || {}; spec = spec || {};
spec.policies = spec.policies || [ spec.policies = spec.policies || [
IPA.search_facet_update_policy(), IPA.search_facet_update_policy,
IPA.details_facet_update_policy(), IPA.details_facet_update_policy,
IPA.cert.cert_update_policy({ {
$factory: IPA.cert.cert_update_policy,
source_facet: 'details', source_facet: 'details',
dest_facet: 'search' dest_facet: 'search'
}), },
IPA.cert.cert_update_policy({ {
$factory: IPA.cert.cert_update_policy,
source_facet: 'details', source_facet: 'details',
dest_entity: 'host', dest_entity: 'host',
dest_facet: 'details' dest_facet: 'details'
}), },
IPA.cert.cert_update_policy({ {
$factory: IPA.cert.cert_update_policy,
source_facet: 'details', source_facet: 'details',
dest_entity: 'service', dest_entity: 'service',
dest_facet: 'details' dest_facet: 'details'
}) }
]; ];
var that = IPA.entity(spec); var that = IPA.entity(spec);
@ -1174,11 +1177,15 @@ IPA.cert.entity = function(spec) {
} }
], ],
policies: [ policies: [
IPA.cert.load_policy({ has_reason: true}), {
IPA.hide_empty_row_policy({ $factory: IPA.cert.load_policy,
has_reason: true
},
{
$factory: IPA.hide_empty_row_policy,
widget: 'revocation_reason', widget: 'revocation_reason',
section: 'details' section: 'details'
}) }
] ]
}); });
}; };

View File

@ -24,6 +24,7 @@
/* IPA Object Details - populating definiton lists from entry data */ /* IPA Object Details - populating definiton lists from entry data */
define([ define([
'./builder',
'./ipa', './ipa',
'./jquery', './jquery',
'./phases', './phases',
@ -31,7 +32,7 @@ define([
'./text', './text',
'./facet', './facet',
'./add'], './add'],
function(IPA, $, phases, reg, text) { function(builder, IPA, $, phases, reg, text) {
var exp = {}; var exp = {};
@ -232,7 +233,9 @@ exp.facet_policies = IPA.facet_policies = function(spec) {
} }
}; };
that.add_policies(spec.policies); var policies = builder.build('', spec.policies, {},
{ $factory: exp.facet_policy }) || [];
that.add_policies(policies);
return that; return that;
}; };

View File

@ -325,7 +325,7 @@ IPA.dns.zone_entity = function(spec) {
} }
], ],
policies: [ policies: [
IPA.add_dns_zone_name_policy() IPA.add_dns_zone_name_policy
] ]
}); });
}; };
@ -1134,12 +1134,13 @@ IPA.dns.record_entity = function(spec) {
spec = spec || {}; spec = spec || {};
spec.policies = spec.policies || [ spec.policies = spec.policies || [
IPA.facet_update_policy({ {
$factory: IPA.facet_update_policy,
source_facet: 'details', source_facet: 'details',
dest_entity: 'dnszone', dest_entity: 'dnszone',
dest_facet: 'records' dest_facet: 'records'
}), },
IPA.adder_facet_update_policy() IPA.adder_facet_update_policy
]; ];
var that = IPA.entity(spec); var that = IPA.entity(spec);
@ -1212,9 +1213,10 @@ IPA.dns.record_entity = function(spec) {
} }
], ],
policies: [ policies: [
IPA.dnsrecord_adder_dialog_type_policy({ {
$factory: IPA.dnsrecord_adder_dialog_type_policy,
type_field: 'record_type' type_field: 'record_type'
}) }
] ]
}); });
}; };

View File

@ -21,16 +21,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
define(['./ipa', './jquery', './text', './facets', './facet'], define([
function(IPA, $, text, facet_reg) { './builder',
'./ipa',
'./jquery',
'./text',
'./facets',
'./facet'],
function(builder, IPA, $, text, facet_reg) {
IPA.entity = function(spec) { IPA.entity = function(spec) {
spec = spec || {}; spec = spec || {};
spec.policies = spec.policies || [ spec.policies = spec.policies || [
IPA.search_facet_update_policy(), IPA.search_facet_update_policy,
IPA.details_facet_update_policy() IPA.details_facet_update_policy
]; ];
var that = IPA.object(); var that = IPA.object();
@ -487,7 +493,9 @@ IPA.entity_policies = function(spec) {
} }
}; };
that.add_policies(spec.policies); var policies = builder.build('', spec.policies, {},
{ $factory: IPA.entity_policy }) || [];
that.add_policies(policies);
return that; return that;
}; };

View File

@ -38,18 +38,20 @@ IPA.host.entity = function(spec) {
spec = spec || {}; spec = spec || {};
spec.policies = spec.policies || [ spec.policies = spec.policies || [
IPA.search_facet_update_policy(), IPA.search_facet_update_policy,
IPA.details_facet_update_policy(), IPA.details_facet_update_policy,
IPA.cert.cert_update_policy({ {
$factory: IPA.cert.cert_update_policy,
source_facet: 'details', source_facet: 'details',
dest_entity: 'cert', dest_entity: 'cert',
dest_facet: 'details' dest_facet: 'details'
}), },
IPA.cert.cert_update_policy({ {
$factory: IPA.cert.cert_update_policy,
source_facet: 'details', source_facet: 'details',
dest_entity: 'cert', dest_entity: 'cert',
dest_facet: 'search' dest_facet: 'search'
}) }
]; ];
var that = IPA.entity(spec); var that = IPA.entity(spec);
@ -176,8 +178,8 @@ IPA.host.entity = function(spec) {
] ]
}, },
policies: [ policies: [
IPA.host.enrollment_policy(), IPA.host.enrollment_policy,
IPA.host.certificate_policy() IPA.host.certificate_policy
] ]
}). }).
association_facet({ association_facet({

View File

@ -148,9 +148,10 @@ IPA.idrange.entity = function(spec) {
} }
], ],
policies: [ policies: [
IPA.multiple_choice_section_policy({ {
$factory: IPA.multiple_choice_section_policy,
widget: 'type' widget: 'type'
}) }
] ]
}); });
}; };

View File

@ -37,18 +37,20 @@ IPA.service.entity = function(spec) {
spec = spec || {}; spec = spec || {};
spec.policies = spec.policies || [ spec.policies = spec.policies || [
IPA.search_facet_update_policy(), IPA.search_facet_update_policy,
IPA.details_facet_update_policy(), IPA.details_facet_update_policy,
IPA.cert.cert_update_policy({ {
$factory: IPA.cert.cert_update_policy,
source_facet: 'details', source_facet: 'details',
dest_entity: 'cert', dest_entity: 'cert',
dest_facet: 'details' dest_facet: 'details'
}), },
IPA.cert.cert_update_policy({ {
$factory: IPA.cert.cert_update_policy,
source_facet: 'details', source_facet: 'details',
dest_entity: 'cert', dest_entity: 'cert',
dest_facet: 'search' dest_facet: 'search'
}) }
]; ];
var that = IPA.entity(spec); var that = IPA.entity(spec);
@ -164,7 +166,7 @@ IPA.service.entity = function(spec) {
] ]
}, },
policies: [ policies: [
IPA.service.certificate_policy() IPA.service.certificate_policy
] ]
}). }).
association_facet({ association_facet({

View File

@ -174,9 +174,10 @@ IPA.trust.entity = function(spec) {
} }
], ],
policies: [ policies: [
IPA.multiple_choice_section_policy({ {
$factory: IPA.multiple_choice_section_policy,
widget: 'method' widget: 'method'
}) }
] ]
}); });
}; };

View File

@ -115,7 +115,10 @@ module('aci', {
} }
], ],
policies: [ policies: [
IPA.permission_target_policy('target') {
$factory: IPA.permission_target_policy,
widget_name: 'target'
}
] ]
}); });
entity.add_facet('details', target_facet); entity.add_facet('details', target_facet);