pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0141-WebUI-services-without-canonical-name-are-shown-corr.patch

fef02c
From 014aab243a4e7185ad5ebdc0a71e7de81553e501 Mon Sep 17 00:00:00 2001
fef02c
From: Pavel Vomacka <pvomacka@redhat.com>
fef02c
Date: Mon, 17 Oct 2016 14:33:07 +0200
fef02c
Subject: [PATCH] WebUI: services without canonical name are shown correctly
fef02c
fef02c
There is a change introduced in 4.4 that new services have canonical name. The old ones
fef02c
didn't have it, therefore these services were not correctly displayed in WebUI.
fef02c
fef02c
This patch adds support for this type of services. Service name is taken from
fef02c
'krbprincipalname' attribute in case that 'krbcanonicalname' attribute is not present
fef02c
in server response.
fef02c
fef02c
https://fedorahosted.org/freeipa/ticket/6397
fef02c
fef02c
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
fef02c
---
fef02c
 install/ui/src/freeipa/field.js   | 41 ++++++++++++++++++++++++++++++
fef02c
 install/ui/src/freeipa/service.js | 52 ++++++++++++++++++++++++++++++++++++++-
fef02c
 2 files changed, 92 insertions(+), 1 deletion(-)
fef02c
fef02c
diff --git a/install/ui/src/freeipa/field.js b/install/ui/src/freeipa/field.js
fef02c
index d8b957f5ab28b5ee4bc4ebce2ae6f454083bc4fd..efa2fb6ef4d4b5384661e9023ace511730954153 100644
fef02c
--- a/install/ui/src/freeipa/field.js
fef02c
+++ b/install/ui/src/freeipa/field.js
fef02c
@@ -1306,6 +1306,46 @@ field.ObjectAdapter = declare([field.Adapter], {
fef02c
 
fef02c
 
fef02c
 /**
fef02c
+ * Custom adapter for fields which handles situations when there is no value
fef02c
+ * for attribute (name) of the field and we want to use alternative attribute
fef02c
+ * from response. We can set the alternative attribute name to the 'alt_attr'
fef02c
+ * attribute of the adapter.
fef02c
+ * This adapter is used i.e. in table in search facet for services. Handles
fef02c
+ * situations where older services don't have canonical name.
fef02c
+ *
fef02c
+ * @class
fef02c
+ * @extends field.Adapter
fef02c
+ */
fef02c
+field.AlternateAttrFieldAdapter = declare([field.Adapter], {
fef02c
+    /**
fef02c
+     * In case that the value is not get using field name then use alternative
fef02c
+     * name.
fef02c
+     * @param {Object} data Object which contains the record or the record
fef02c
+     * @param {string} [attribute] attribute name - overrides `context.param`
fef02c
+     * @param {Mixed} [def_val] default value - overrides `context.default_value`
fef02c
+     * @returns {Array} attribute value
fef02c
+     */
fef02c
+    load: function(data, attribute, def_val) {
fef02c
+        var record = this.get_record(data);
fef02c
+        var value = null;
fef02c
+        var attr = attribute || this.context.param;
fef02c
+        var def = def_val || this.context.default_value;
fef02c
+        if (record) {
fef02c
+            value = this.get_value(record, attr);
fef02c
+            if (util.is_empty(value) && this.context.adapter.alt_attr) {
fef02c
+                value = this.get_value(record, this.context.adapter.alt_attr);
fef02c
+            }
fef02c
+        }
fef02c
+        if (util.is_empty(value) && !util.is_empty(def)) {
fef02c
+            value = util.normalize_value(def);
fef02c
+        }
fef02c
+        value = rpc.extract_objects(value);
fef02c
+        return value;
fef02c
+    }
fef02c
+});
fef02c
+
fef02c
+
fef02c
+/**
fef02c
  * Field for enabling/disabling entity
fef02c
  *
fef02c
  * - expects radio widget
fef02c
@@ -1577,6 +1617,7 @@ field.register = function() {
fef02c
 
fef02c
     l.register('adapter', field.Adapter);
fef02c
     l.register('object_adapter', field.ObjectAdapter);
fef02c
+    l.register('alternate_attr_field_adapter', field.AlternateAttrFieldAdapter);
fef02c
 };
fef02c
 phases.on('registration', field.register);
fef02c
 
fef02c
diff --git a/install/ui/src/freeipa/service.js b/install/ui/src/freeipa/service.js
fef02c
index 30e336c35b8eece2e5e3ef55629d0c98f097fbf5..a6607d22e83047fb2d0dcc7775891445df4910b7 100644
fef02c
--- a/install/ui/src/freeipa/service.js
fef02c
+++ b/install/ui/src/freeipa/service.js
fef02c
@@ -58,7 +58,16 @@ return {
fef02c
     facets: [
fef02c
         {
fef02c
             $type: 'search',
fef02c
-            columns: [ 'krbcanonicalname' ]
fef02c
+            $factory: IPA.service.search_facet,
fef02c
+            columns: [
fef02c
+                {
fef02c
+                    name: 'krbcanonicalname',
fef02c
+                    adapter: {
fef02c
+                        $type: 'alternate_attr_field_adapter',
fef02c
+                        alt_attr: 'krbprincipalname'
fef02c
+                    }
fef02c
+                }
fef02c
+            ]
fef02c
         },
fef02c
         {
fef02c
             $type: 'details',
fef02c
@@ -403,6 +412,47 @@ return {
fef02c
     }
fef02c
 };};
fef02c
 
fef02c
+
fef02c
+/**
fef02c
+ * Custom search facet for services. It has alternative primary key, in case
fef02c
+ * that the service doesn't have canonical name.
fef02c
+ */
fef02c
+IPA.service.search_facet = function(spec) {
fef02c
+    spec = spec || {};
fef02c
+
fef02c
+    spec.alternative_pkey = spec.alternative_pkey || 'krbprincipalname';
fef02c
+
fef02c
+    var that = IPA.search_facet(spec);
fef02c
+
fef02c
+    that.alternative_pkey = spec.alternative_pkey;
fef02c
+
fef02c
+    that.get_records_map = function(data) {
fef02c
+
fef02c
+        var records_map = $.ordered_map();
fef02c
+
fef02c
+        var result = data.result.result;
fef02c
+        var pkey_name = that.managed_entity.metadata.primary_key ||
fef02c
+                                                        that.primary_key_name;
fef02c
+        var adapter = builder.build('adapter', 'adapter', {context: that});
fef02c
+
fef02c
+        for (var i=0; i
fef02c
+            var record = result[i];
fef02c
+            var pkey = adapter.load(record, pkey_name)[0];
fef02c
+            if (pkey === undefined && that.alternative_pkey) {
fef02c
+                pkey = adapter.load(record, that.alternative_pkey)[0];
fef02c
+            }
fef02c
+            if (that.filter_records(records_map, pkey, record)) {
fef02c
+                records_map.put(pkey, record);
fef02c
+            }
fef02c
+        }
fef02c
+
fef02c
+        return records_map;
fef02c
+    };
fef02c
+
fef02c
+    return that;
fef02c
+};
fef02c
+
fef02c
+
fef02c
 IPA.service.details_facet = function(spec, no_init) {
fef02c
 
fef02c
     var that = IPA.details_facet(spec, true);
fef02c
-- 
fef02c
2.7.4
fef02c