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

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