URL: https://github.com/freeipa/freeipa/pull/166 Author: pvomacka Title: #166: WebUI: services without canonical name are shown correctly Action: opened
PR body: """ 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 """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/166/head:pr166 git checkout pr166
From 581ab0ea485dad118fc6ffebf8708e198e7025be Mon Sep 17 00:00:00 2001 From: Pavel Vomacka <pvoma...@redhat.com> Date: Mon, 17 Oct 2016 14:33:07 +0200 Subject: [PATCH] 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 --- install/ui/src/freeipa/service.js | 92 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/install/ui/src/freeipa/service.js b/install/ui/src/freeipa/service.js index 30e336c..f8d3fbd 100644 --- a/install/ui/src/freeipa/service.js +++ b/install/ui/src/freeipa/service.js @@ -28,11 +28,12 @@ define([ './reg', './rpc', './text', + './util', './details', './search', './association', './entity'], - function(declare, field_mod, builder, IPA, $, phases, reg, rpc, text) { + function(declare, field_mod, builder, IPA, $, phases, reg, rpc, text, util) { var exp =IPA.service = {}; @@ -58,7 +59,16 @@ return { facets: [ { $type: 'search', - columns: [ 'krbcanonicalname' ] + $factory: IPA.service.search_facet, + columns: [ + { + name: 'krbcanonicalname', + adapter: { + $type: 'service_adapter', + alt_attr: 'krbprincipalname' + } + } + ] }, { $type: 'details', @@ -403,6 +413,82 @@ 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; +}; + + +/** + * Custom adapter for column in table in search facet. + * This adapter handles situations where older services don't have canonical + * name. Therefore the adapter has to take value from + * + */ +IPA.service.SearchTableColumnFieldAdapter = declare([field_mod.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; + } +}); + + IPA.service.details_facet = function(spec, no_init) { var that = IPA.details_facet(spec, true); @@ -686,12 +772,14 @@ phases.on('registration', function() { var w = reg.widget; var f = reg.field; var a = reg.action; + var l = reg.adapter; e.register({type: 'service', spec: exp.entity_spec}); f.register('service_provisioning_status', IPA.field); w.register('service_provisioning_status', IPA.service_provisioning_status_widget); a.register('service_unprovision', IPA.service.unprovision_action); + l.register('service_adapter', IPA.service.SearchTableColumnFieldAdapter); });
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code