Blame SOURCES/0001-WebUI-Fix-IPA-Error-3007-RequirmentError-while-addin_rhbz#1757045.patch

f56551
From c2ba333b9681d008d9c528a79dbdd76ce11a3ecd Mon Sep 17 00:00:00 2001
f56551
From: Serhii Tsymbaliuk <stsymbal@redhat.com>
f56551
Date: Thu, 28 May 2020 08:47:49 +0200
f56551
Subject: [PATCH 01/22] WebUI: Fix "IPA Error 3007: RequirmentError" while
f56551
 adding idoverrideuser association
f56551
f56551
Add builder for association adder dialog which allows to override behavior of the component.
f56551
Replace default implementation with a custom one for idoverrideuser.
f56551
Replace text filter with 'ID view' select box in the idoverrideuser dialog.
f56551
f56551
Ticket: https://pagure.io/freeipa/issue/8335
f56551
f56551
Signed-off-by: Serhii Tsymbaliuk <stsymbal@redhat.com>
f56551
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
f56551
---
f56551
 install/ui/src/freeipa/association.js | 13 ++++-
f56551
 install/ui/src/freeipa/dialog.js      | 73 ++++++++++++++++-----------
f56551
 install/ui/src/freeipa/group.js       | 14 +++++
f56551
 install/ui/src/freeipa/idviews.js     | 58 +++++++++++++++++++++
f56551
 ipaserver/plugins/internal.py         |  6 +++
f56551
 5 files changed, 133 insertions(+), 31 deletions(-)
f56551
f56551
diff --git a/install/ui/src/freeipa/association.js b/install/ui/src/freeipa/association.js
f56551
index f10ccb2a5..b083a79f9 100644
f56551
--- a/install/ui/src/freeipa/association.js
f56551
+++ b/install/ui/src/freeipa/association.js
f56551
@@ -25,6 +25,7 @@
f56551
 define([
f56551
     'dojo/_base/lang',
f56551
     'dojo/Deferred',
f56551
+    './builder',
f56551
     './metadata',
f56551
     './ipa',
f56551
     './jquery',
f56551
@@ -38,7 +39,7 @@ define([
f56551
     './facet',
f56551
     './search',
f56551
     './dialog'],
f56551
-        function(lang, Deferred, metadata_provider, IPA, $, metadata,
f56551
+        function(lang, Deferred, builder, metadata_provider, IPA, $, metadata,
f56551
                  navigation, phases, reg, rpc, su, text) {
f56551
 
f56551
 /**
f56551
@@ -1209,7 +1210,8 @@ exp.association_facet = IPA.association_facet = function (spec, no_init) {
f56551
 
f56551
         var pkeys = that.data.result.result[that.get_attribute_name()];
f56551
 
f56551
-        var dialog = IPA.association_adder_dialog({
f56551
+        var dialog = builder.build('association_adder_dialog', {
f56551
+            $type: that.other_entity.name,
f56551
             title: title,
f56551
             entity: that.entity,
f56551
             pkey: pkey,
f56551
@@ -1675,6 +1677,13 @@ IPA.attr_read_only_evaluator = function(spec) {
f56551
     return that;
f56551
 };
f56551
 
f56551
+// Create a registry for adder dialogs where key is name of 'other entity'.
f56551
+// It allows to override dialogs for some specific cases of association
f56551
+// creation.
f56551
+var dialog_builder = builder.get('association_adder_dialog');
f56551
+dialog_builder.factory = IPA.association_adder_dialog;
f56551
+reg.set('association_adder_dialog', dialog_builder.registry);
f56551
+
f56551
 phases.on('registration', function() {
f56551
     var w = reg.widget;
f56551
     var f = reg.field;
f56551
diff --git a/install/ui/src/freeipa/dialog.js b/install/ui/src/freeipa/dialog.js
f56551
index c153120df..d67d63b6d 100644
f56551
--- a/install/ui/src/freeipa/dialog.js
f56551
+++ b/install/ui/src/freeipa/dialog.js
f56551
@@ -919,35 +919,7 @@ IPA.adder_dialog = function(spec) {
f56551
             'class': 'input-group col-md-12 adder-dialog-top'
f56551
         }).appendTo(container);
f56551
 
f56551
-        var filter_placeholder = text.get('@i18n:association.filter_placeholder');
f56551
-        filter_placeholder = filter_placeholder.replace('${other_entity}',
f56551
-            that.other_entity.metadata.label);
f56551
-
f56551
-        that.filter_field = $('<input/>', {
f56551
-            type: 'text',
f56551
-            name: 'filter',
f56551
-            'class': 'form-control',
f56551
-            'placeholder': filter_placeholder,
f56551
-            keyup: function(event) {
f56551
-                if (event.keyCode === keys.ENTER) {
f56551
-                    that.search();
f56551
-                    return false;
f56551
-                }
f56551
-            }
f56551
-        }).appendTo(input_group);
f56551
-
f56551
-        var input_group_btn = $('
', {
f56551
-            'class': 'input-group-btn'
f56551
-        }).appendTo(input_group);
f56551
-
f56551
-        that.find_button = IPA.button({
f56551
-            name: 'find',
f56551
-            label: '@i18n:buttons.filter',
f56551
-            click: function() {
f56551
-                that.search();
f56551
-                return false;
f56551
-            }
f56551
-        }).appendTo(input_group_btn);
f56551
+        that.filter_field = that.get_filter_field(input_group);
f56551
 
f56551
         var row = $('
', { 'class': 'row adder-dialog-main'}).appendTo(container);
f56551
         //
f56551
@@ -1132,6 +1104,49 @@ IPA.adder_dialog = function(spec) {
f56551
         return that.filter_field.val();
f56551
     };
f56551
 
f56551
+    /**
f56551
+     * Return field for filtering available items
f56551
+     *
f56551
+     * Default implementation returns text input + "Filter" button.
f56551
+     * It can be overridden.
f56551
+     *
f56551
+     * @param {HTMLElement} input_group - container for a filter field
f56551
+     * @return {HTMLElement}
f56551
+     */
f56551
+    that.get_filter_field = function(input_group) {
f56551
+        var filter_placeholder = text.get(
f56551
+            '@i18n:association.filter_placeholder'
f56551
+        ).replace('${other_entity}', that.other_entity.metadata.label);
f56551
+
f56551
+        var filter_field = $('<input/>', {
f56551
+            type: 'text',
f56551
+            name: 'filter',
f56551
+            'class': 'form-control',
f56551
+            'placeholder': filter_placeholder,
f56551
+            keyup: function(event) {
f56551
+                if (event.keyCode === keys.ENTER) {
f56551
+                    that.search();
f56551
+                    return false;
f56551
+                }
f56551
+            }
f56551
+        }).appendTo(input_group);
f56551
+
f56551
+        var input_group_btn = $('
', {
f56551
+            'class': 'input-group-btn'
f56551
+        }).appendTo(input_group);
f56551
+
f56551
+        that.find_button = IPA.button({
f56551
+            name: 'find',
f56551
+            label: '@i18n:buttons.filter',
f56551
+            click: function() {
f56551
+                that.search();
f56551
+                return false;
f56551
+            }
f56551
+        }).appendTo(input_group_btn);
f56551
+
f56551
+        return filter_field;
f56551
+    };
f56551
+
f56551
     /**
f56551
      * Clear rows in available table
f56551
      */
f56551
diff --git a/install/ui/src/freeipa/group.js b/install/ui/src/freeipa/group.js
f56551
index e46d8c7e3..2984bd4b2 100644
f56551
--- a/install/ui/src/freeipa/group.js
f56551
+++ b/install/ui/src/freeipa/group.js
f56551
@@ -205,6 +205,20 @@ return {
f56551
             add_title: '@i18n:objects.group.add_into_sudo',
f56551
             remove_method: 'remove_user',
f56551
             remove_title: '@i18n:objects.group.remove_from_sudo'
f56551
+        },
f56551
+        {
f56551
+            $type: 'association',
f56551
+            name: 'member_idoverrideuser',
f56551
+            associator: IPA.serial_associator,
f56551
+            add_title: '@i18n:objects.group.add_idoverride_user',
f56551
+            remove_title: '@i18n:objects.group.remove_idoverride_users',
f56551
+            columns: [
f56551
+                {
f56551
+                    name: 'ipaanchoruuid',
f56551
+                    label: '@i18n:objects.idoverrideuser.anchor_label',
f56551
+                    link: false
f56551
+                }
f56551
+            ]
f56551
         }
f56551
     ],
f56551
     standard_association_facets: true,
f56551
diff --git a/install/ui/src/freeipa/idviews.js b/install/ui/src/freeipa/idviews.js
f56551
index 35dc998c8..a4fca6205 100644
f56551
--- a/install/ui/src/freeipa/idviews.js
f56551
+++ b/install/ui/src/freeipa/idviews.js
f56551
@@ -966,6 +966,58 @@ idviews.unapply_action = function(spec) {
f56551
     return that;
f56551
 };
f56551
 
f56551
+idviews.idoverrideuser_adder_dialog = function(spec) {
f56551
+
f56551
+    spec = spec || {};
f56551
+
f56551
+    var that = IPA.association_adder_dialog(spec);
f56551
+
f56551
+    that.base_search = that.search;
f56551
+
f56551
+    that.search = function() {
f56551
+        // Search for users only in case a ID view is selected
f56551
+        if (that.get_filter()) {
f56551
+            that.base_search();
f56551
+        }
f56551
+    };
f56551
+
f56551
+    /**
f56551
+     * Replace default text filter with a select box for filtering by ID view
f56551
+     */
f56551
+    that.get_filter_field = function(input_group) {
f56551
+
f56551
+        var filter_field = $('<select/>', {
f56551
+            name: 'filter',
f56551
+            'class': 'form-control',
f56551
+            change: function(event) {
f56551
+                that.search();
f56551
+            }
f56551
+        }).appendTo(input_group);
f56551
+
f56551
+        rpc.command({
f56551
+            entity: 'idview',
f56551
+            method: 'find',
f56551
+            on_success: function(data) {
f56551
+                var results = data.result;
f56551
+
f56551
+                for (var i=0; i
f56551
+                    var result = results.result[i];
f56551
+                    $('<option/>', {
f56551
+                        text: result.cn[0],
f56551
+                        value: result.cn[0]
f56551
+                    }).appendTo(filter_field);
f56551
+                }
f56551
+
f56551
+                that.search();
f56551
+            }
f56551
+        }).execute();
f56551
+
f56551
+        return filter_field;
f56551
+    };
f56551
+
f56551
+    return that;
f56551
+};
f56551
+
f56551
 /**
f56551
  * ID View entity specification object
f56551
  * @member idviews
f56551
@@ -993,6 +1045,7 @@ idviews.register = function() {
f56551
     var f = reg.facet;
f56551
     var a = reg.action;
f56551
     var w = reg.widget;
f56551
+    var ad = reg.association_adder_dialog;
f56551
 
f56551
     e.register({type: 'idview', spec: idviews.spec});
f56551
     e.register({
f56551
@@ -1012,6 +1065,11 @@ idviews.register = function() {
f56551
 
f56551
     w.register('idviews_certs', idviews.idviews_certs_widget);
f56551
     w.register('cert_textarea', idviews.cert_textarea_widget);
f56551
+
f56551
+    ad.register({
f56551
+        type: 'idoverrideuser',
f56551
+        factory: idviews.idoverrideuser_adder_dialog
f56551
+    });
f56551
 };
f56551
 
f56551
 phases.on('registration', idviews.register);
f56551
diff --git a/ipaserver/plugins/internal.py b/ipaserver/plugins/internal.py
f56551
index 5f2b1fdc2..7622e65dc 100644
f56551
--- a/ipaserver/plugins/internal.py
f56551
+++ b/ipaserver/plugins/internal.py
f56551
@@ -835,6 +835,9 @@ class i18n_messages(Command):
f56551
                     "Remove users from member managers for user group "
f56551
                     "'${primary_key}'"
f56551
                 ),
f56551
+                "add_idoverride_user": _(
f56551
+                    "Add user ID override into user group '${primary_key}'"
f56551
+                ),
f56551
                 "details": _("Group Settings"),
f56551
                 "external": _("External"),
f56551
                 "groups": _("Groups"),
f56551
@@ -868,6 +871,9 @@ class i18n_messages(Command):
f56551
                 "remove_users": _(
f56551
                     "Remove users from user group '${primary_key}'"
f56551
                 ),
f56551
+                "remove_idoverride_users": _(
f56551
+                    "Remove user ID overrides from user group '${primary_key}'"
f56551
+                ),
f56551
                 "type": _("Group Type"),
f56551
                 "user_groups": _("User Groups"),
f56551
             },
f56551
-- 
f56551
2.26.2
f56551