On 08/17/2011 05:38 PM, Petr Vobornik wrote:
Ticket #1628 - https://fedorahosted.org/freeipa/ticket/1628
Unreported insufficient access error

This patch is dependant on
freeipa-pvoborni-0004-1-error-dialog-for-batch-command.patch.

This may be only a checking if approach of this patch is good.

I was not sure if this type of error message (result.failed property) is
more general or it only appears in adding members. So I put error
handling in serial_associator instead of command. If it would be put in
command and success will be transformed to error, it will change the
behaviour of executing commands - other commands after error won't be
executed. If the approach is good, it could be probably better to change
it a little and offer same logic for batch_associator.

It should be working for adding users to groups, netgroups, roles and
assigning hbac rules (tested as non admin user).


Modified association test - data in success handler should not be
undefined.



_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel
Modified to work with bulk association.

--
Petr Vobornik
From cd0afe270583ce5b90317d7479412a9547048c94 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Wed, 17 Aug 2011 15:06:41 +0200
Subject: [PATCH] Show error in adding associations

https://fedorahosted.org/freeipa/ticket/1628
---
 install/ui/association.js            |   47 ++++++++++++++++++++++++++++++++-
 install/ui/ipa.js                    |   45 ++++++++++++++++++-------------
 install/ui/test/association_tests.js |    4 +-
 3 files changed, 73 insertions(+), 23 deletions(-)

diff --git a/install/ui/association.js b/install/ui/association.js
index 2c6a1d2003be0668b61b230b8317263b06a822a5..d8722fac36f781563dfc040b9ecdf0d3a80ed646 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -41,9 +41,41 @@ IPA.associator = function (spec) {
     that.on_success = spec.on_success;
     that.on_error = spec.on_error;
 
+    that.errors = IPA.errors();
+
     that.execute = function() {
     };
 
+    that.check_for_errors = function(command, data, text_status, xhr) {
+        var result = data.result;
+        if(result && result.failed) {
+            for(var association in result.failed) {
+                for(var member_name in result.failed[association]) {
+                    var member = result.failed[association][member_name];
+                    if(member.length > 0 && member[0].length > 1) {
+                        var name = 'Association Error';
+                        var message = member[0][1];
+                        that.errors.add_error(command, name, message, text_status);
+                    }
+                }
+            }
+        }
+    };
+
+    that.show_errors = function () {
+        if(that.errors.errors.length > 0) {
+            var dialog = IPA.error_dialog({
+                error_thrown: {
+                    name: IPA.messages.dialogs.batch_error_title,
+                    message: IPA.messages.dialogs.batch_error_message
+                },
+                errors: that.errors.errors,
+                visible_buttons: ['ok']
+            });
+            dialog.open();
+        }
+    };
+
     return that;
 };
 
@@ -60,12 +92,14 @@ IPA.serial_associator = function(spec) {
     that.execute = function() {
 
         if (!that.values || !that.values.length) {
+            that.show_errors();
             that.on_success();
             return;
         }
 
         var value = that.values.shift();
         if (!value) {
+            that.show_errors();
             that.on_success();
             return;
         }
@@ -79,7 +113,10 @@ IPA.serial_associator = function(spec) {
             method: that.method,
             args: args,
             options: options,
-            on_success: that.execute,
+            on_success: function(data, text_status, xhr) {
+                that.check_for_errors(command, data, text_status, xhr);
+                that.execute();
+            },
             on_error: that.on_error
         });
 
@@ -104,12 +141,14 @@ IPA.bulk_associator = function(spec) {
     that.execute = function() {
 
         if (!that.values || !that.values.length) {
+            that.show_errors();
             that.on_success();
             return;
         }
 
         var value = that.values.shift();
         if (!value) {
+            that.show_errors();
             that.on_success();
             return;
         }
@@ -127,7 +166,11 @@ IPA.bulk_associator = function(spec) {
             method: that.method,
             args: args,
             options: options,
-            on_success: that.on_success,
+            on_success: function(data, text_status, xhr) {
+                that.check_for_errors(command, data, text_status, xhr);
+                that.show_errors();
+                that.on_success();
+            },
             on_error: that.on_error
         });
 
diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index 9a252f1e50fdaf544cb872fe0dbed9377e791559..142a3210a3af16df415c693277135fed1625eeeb 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -417,7 +417,7 @@ IPA.batch_command = function (spec) {
     var that = IPA.command(spec);
 
     that.commands = [];
-    that.errors = [];
+    that.errors = IPA.errors();
     that.error_message = spec.error_message || (IPA.messages.dialogs ?
             IPA.messages.dialogs.batch_error_message : 'Some operations failed.');
     that.show_error = typeof spec.show_error == 'undefined' ?
@@ -434,21 +434,8 @@ IPA.batch_command = function (spec) {
         }
     };
 
-    var clear_errors = function() {
-        that.errors = [];
-    };
-
-    var add_error = function(command, name, message, status) {
-        that.errors.push({
-            command: command,
-            name: name,
-            message: message,
-            status: status
-        });
-    };
-
     that.execute = function() {
-        clear_errors();
+        that.errors.clear_errors();
 
         IPA.command({
             name: that.name,
@@ -470,7 +457,7 @@ IPA.batch_command = function (spec) {
                         name = 'Internal Error '+xhr.status;
                         message = result ? xhr.statusText : "Internal error";
 
-                        add_error(command, name, message, text_status);
+                        that.errors.add_error(command, name, message, text_status);
 
                         if (command.on_error) command.on_error.call(
                             this,
@@ -486,7 +473,7 @@ IPA.batch_command = function (spec) {
                         name = 'IPA Error ' + (result.error.code || '');
                         message = result.error.message || result.error;
 
-                        add_error(command, name, message, text_status);
+                        that.errors.add_error(command, name, message, text_status);
 
                         if (command.on_error) command.on_error.call(
                             this,
@@ -503,7 +490,7 @@ IPA.batch_command = function (spec) {
                     }
                 }
                 //check for partial errors and show error dialog
-                if(that.show_error && that.errors.length > 0) {
+                if(that.show_error && that.errors.errors.length > 0) {
                     var dialog = IPA.error_dialog({
                         xhr: xhr,
                         text_status: text_status,
@@ -513,7 +500,7 @@ IPA.batch_command = function (spec) {
                             message: that.error_message
                         },
                         command: that,
-                        errors: that.errors,
+                        errors: that.errors.errors,
                         visible_buttons: ['ok']
                     });
                     dialog.open();
@@ -785,3 +772,23 @@ IPA.error_dialog = function(spec) {
 
     return that;
 };
+
+IPA.errors = function() {
+    var that = {};
+
+    that.clear_errors = function() {
+        that.errors = [];
+    };
+
+    that.add_error = function(command, name, message, status) {
+        that.errors.push({
+            command: command,
+            name: name,
+            message: message,
+            status: status
+        });
+    };
+
+    that.clear_errors();
+    return that;
+};
diff --git a/install/ui/test/association_tests.js b/install/ui/test/association_tests.js
index 769355ae8bd4356d0243450b9664d33271948d57..1cdc17ccb954832fa85d82dfa50fac57b12342b5 100644
--- a/install/ui/test/association_tests.js
+++ b/install/ui/test/association_tests.js
@@ -60,7 +60,7 @@ test("Testing serial_associator().", function() {
                 'Checking IPA.command() parameter: primary key'
             );
 
-            that.on_success();
+            that.on_success({});
         };
 
         return that;
@@ -115,7 +115,7 @@ test("Testing bulk_associator().", function() {
                 'Checking IPA.command() parameter: options[\""+params.other_entity+"\"]'
             );
 
-            that.on_success();
+            that.on_success({});
         };
 
         return that;
-- 
1.7.6

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to