diff options
| author | Pavel Vomacka <pvomacka@redhat.com> | 2016-10-17 14:33:07 +0200 |
|---|---|---|
| committer | Petr Vobornik <pvoborni@redhat.com> | 2016-10-31 16:18:19 +0100 |
| commit | 4f760dffa011a3656b6072c74088b497ff416a8d (patch) | |
| tree | 2d33d962c8dad57c76a264364bfa3058ea0702f2 /install/ui/src | |
| parent | d0c17b4d9afb95db2abcd93096fa6626fd61870e (diff) | |
| download | freeipa-4f760dffa011a3656b6072c74088b497ff416a8d.tar.gz freeipa-4f760dffa011a3656b6072c74088b497ff416a8d.tar.xz freeipa-4f760dffa011a3656b6072c74088b497ff416a8d.zip | |
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>
Diffstat (limited to 'install/ui/src')
| -rw-r--r-- | install/ui/src/freeipa/field.js | 41 | ||||
| -rw-r--r-- | install/ui/src/freeipa/service.js | 52 |
2 files changed, 92 insertions, 1 deletions
diff --git a/install/ui/src/freeipa/field.js b/install/ui/src/freeipa/field.js index 3088e2241..d70a77890 100644 --- a/install/ui/src/freeipa/field.js +++ b/install/ui/src/freeipa/field.js @@ -1361,6 +1361,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 * * - expects radio widget @@ -1632,6 +1672,7 @@ field.register = function() { l.register('adapter', field.Adapter); l.register('object_adapter', field.ObjectAdapter); + l.register('alternate_attr_field_adapter', field.AlternateAttrFieldAdapter); }; phases.on('registration', field.register); diff --git a/install/ui/src/freeipa/service.js b/install/ui/src/freeipa/service.js index 30e336c35..a6607d22e 100644 --- a/install/ui/src/freeipa/service.js +++ b/install/ui/src/freeipa/service.js @@ -58,7 +58,16 @@ return { facets: [ { $type: 'search', - columns: [ 'krbcanonicalname' ] + $factory: IPA.service.search_facet, + columns: [ + { + name: 'krbcanonicalname', + adapter: { + $type: 'alternate_attr_field_adapter', + alt_attr: 'krbprincipalname' + } + } + ] }, { $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) { var that = IPA.details_facet(spec, true); |
