WebUI: services without canonical name are shown correctly

There is a change introduced in 4.4 that new services have canonical name. The old ones
didn't have it, therefore these services were not correctly displayed in WebUI.

This patch adds support for this type of services. Service name is taken from
'krbprincipalname' attribute in case that 'krbcanonicalname' attribute is not present
in server response.

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

Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
This commit is contained in:
Pavel Vomacka 2016-10-17 14:33:07 +02:00 committed by Petr Vobornik
parent f32e68349b
commit 599a7ff90d
2 changed files with 92 additions and 1 deletions

View File

@ -1360,6 +1360,46 @@ field.ObjectAdapter = declare([field.Adapter], {
}); });
/**
* Custom adapter for fields which handles situations when there is no value
* for attribute (name) of the field and we want to use alternative attribute
* from response. We can set the alternative attribute name to the 'alt_attr'
* attribute of the adapter.
* This adapter is used i.e. in table in search facet for services. Handles
* situations where older services don't have canonical name.
*
* @class
* @extends field.Adapter
*/
field.AlternateAttrFieldAdapter = declare([field.Adapter], {
/**
* In case that the value is not get using field name then use alternative
* name.
* @param {Object} data Object which contains the record or the record
* @param {string} [attribute] attribute name - overrides `context.param`
* @param {Mixed} [def_val] default value - overrides `context.default_value`
* @returns {Array} attribute value
*/
load: function(data, attribute, def_val) {
var record = this.get_record(data);
var value = null;
var attr = attribute || this.context.param;
var def = def_val || this.context.default_value;
if (record) {
value = this.get_value(record, attr);
if (util.is_empty(value) && this.context.adapter.alt_attr) {
value = this.get_value(record, this.context.adapter.alt_attr);
}
}
if (util.is_empty(value) && !util.is_empty(def)) {
value = util.normalize_value(def);
}
value = rpc.extract_objects(value);
return value;
}
});
/** /**
* Field for enabling/disabling entity * Field for enabling/disabling entity
* *
@ -1632,6 +1672,7 @@ field.register = function() {
l.register('adapter', field.Adapter); l.register('adapter', field.Adapter);
l.register('object_adapter', field.ObjectAdapter); l.register('object_adapter', field.ObjectAdapter);
l.register('alternate_attr_field_adapter', field.AlternateAttrFieldAdapter);
}; };
phases.on('registration', field.register); phases.on('registration', field.register);

View File

@ -58,7 +58,16 @@ return {
facets: [ facets: [
{ {
$type: 'search', $type: 'search',
columns: [ 'krbcanonicalname' ] $factory: IPA.service.search_facet,
columns: [
{
name: 'krbcanonicalname',
adapter: {
$type: 'alternate_attr_field_adapter',
alt_attr: 'krbprincipalname'
}
}
]
}, },
{ {
$type: 'details', $type: 'details',
@ -403,6 +412,47 @@ return {
} }
};}; };};
/**
* Custom search facet for services. It has alternative primary key, in case
* that the service doesn't have canonical name.
*/
IPA.service.search_facet = function(spec) {
spec = spec || {};
spec.alternative_pkey = spec.alternative_pkey || 'krbprincipalname';
var that = IPA.search_facet(spec);
that.alternative_pkey = spec.alternative_pkey;
that.get_records_map = function(data) {
var records_map = $.ordered_map();
var result = data.result.result;
var pkey_name = that.managed_entity.metadata.primary_key ||
that.primary_key_name;
var adapter = builder.build('adapter', 'adapter', {context: that});
for (var i=0; i<result.length; i++) {
var record = result[i];
var pkey = adapter.load(record, pkey_name)[0];
if (pkey === undefined && that.alternative_pkey) {
pkey = adapter.load(record, that.alternative_pkey)[0];
}
if (that.filter_records(records_map, pkey, record)) {
records_map.put(pkey, record);
}
}
return records_map;
};
return that;
};
IPA.service.details_facet = function(spec, no_init) { IPA.service.details_facet = function(spec, no_init) {
var that = IPA.details_facet(spec, true); var that = IPA.details_facet(spec, true);