Fixed adding host without DNS reverse zone

https://fedorahosted.org/freeipa/ticket/1481

Shows status dialog instead of error dialog (error 4304 is treated like
success).

This patch is fixing the problem, but maybe in a wrong way.

Main problem was that error has to be treated like success. This
decision is done in command.execute() method.

There are two ways to do it
1) Interrupt error handling - transform error to success
2) Interrupt success handling - don't let success to be transformed into
error.

Solution is using the second option. But I think first option is better.
But there are obstacles:
- handling is done in private function (for me ipa.js line ~ 290)
- there is an extend point - setting on_error method. Problem is that
this method is executed only if command.retry is false (default is
true). Setting it to false will disable usage of error dialog (which is
private function). So I would lose functionality for normal errors.
Reordering these lines isn't an option because it would affect a lot of
code.
- one way would be to extract code for error dialog and make it a
regular reusable dialog (with command as parameter). This way it can be
used in custom error handler.


Is it ACKable, or is it better to do it as described?

Petr



>From 3601c857fd4425c3df998e66a39235b67c441813 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Tue, 26 Jul 2011 09:59:19 +0200
Subject: [PATCH] Fixed adding host without DNS reverse zone

https://fedorahosted.org/freeipa/ticket/1481

Shows status dialog instead of error dialog (error 4304 is treated like success).
---
 install/ui/add.js    |   10 +++++++---
 install/ui/dialog.js |   29 +++++++++++++++++++++++++++++
 install/ui/host.js   |   32 +++++++++++++++++++++++++++++++-
 install/ui/ipa.js    |   13 +++++++++++++
 4 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/install/ui/add.js b/install/ui/add.js
index 614a209056070cfa973c3cffa6cec935443ceb6e..9ebfb48bb65b0656bbfb1e3cd8f9c361b59c3d12 100644
--- a/install/ui/add.js
+++ b/install/ui/add.js
@@ -31,6 +31,8 @@ IPA.add_dialog = function (spec) {
 
     that.method = spec.method || 'add';
     that.pre_execute_hook = spec.pre_execute_hook;
+    that.is_custom_success = spec.is_custom_success;
+    that.on_custom_success = spec.on_custom_success;
 
     function show_edit_page(entity_name,result){
         var pkey_name = IPA.metadata.objects[entity_name].primary_key;
@@ -49,7 +51,7 @@ IPA.add_dialog = function (spec) {
             that.save(record);
             that.add(
                 record,
-                function(data, text_status, xhr) {
+                function(data, text_status, xhr) {                   
                     var facet = IPA.current_entity.get_facet();
                     var table = facet.table;
                     table.refresh();
@@ -64,7 +66,7 @@ IPA.add_dialog = function (spec) {
             that.save(record);
             that.add(
                 record,
-                function(data, text_status, xhr) {
+                function(data, text_status, xhr) {                   
                     var facet = IPA.current_entity.get_facet();
                     var table = facet.table;
                     table.refresh();
@@ -104,7 +106,9 @@ IPA.add_dialog = function (spec) {
             entity: that.entity_name,
             method: that.method,
             on_success: on_success,
-            on_error: on_error
+            on_error: on_error,
+            is_custom_success: that.is_custom_success,
+            on_custom_success: that.on_custom_success
         });
 
         pkey_prefix = IPA.get_entity(that.entity_name).get_primary_key_prefix();
diff --git a/install/ui/dialog.js b/install/ui/dialog.js
index ada30b0f481267899f2e1ee6fe4b784da9e1f4ba..f055e18b0b64fb39b15ded847213806227aaf0a8 100644
--- a/install/ui/dialog.js
+++ b/install/ui/dialog.js
@@ -660,3 +660,32 @@ IPA.deleter_dialog =  function (spec) {
 
     return that;
 };
+
+IPA.message_dialog = function(spec) {                        
+        
+    var that = IPA.dialog(spec);      
+    
+    var init = function(spec) {
+        spec = spec || {};
+        that.message = spec.message || '';
+        that.on_ok = spec.on_ok;
+    };
+    that.message_dialog_init = init;
+    
+    that.create = function() {
+        $('<p/>', {
+            'text': that.message
+        }).appendTo(that.container);       
+    };    
+      
+    that.add_button(IPA.messages.buttons.ok, function() {         
+        that.close();
+        if(that.on_ok) {
+            that.on_ok();
+        }
+    });      
+    
+    init(spec);            
+    
+    return that;
+};
diff --git a/install/ui/host.js b/install/ui/host.js
index bbac4edd77c7528f4be97e5d50e24385e8bd5549..b7b5b6d910a54d5b9886707170ebb6db1da7109c 100644
--- a/install/ui/host.js
+++ b/install/ui/host.js
@@ -102,6 +102,7 @@ IPA.entity_factories.host = function () {
         }).
         standard_association_facets().
         adder_dialog({
+            factory: IPA.host_adder_dialog,
             width: 400,
             height: 250,
             fields:[
@@ -120,7 +121,7 @@ IPA.entity_factories.host = function () {
                     label:  IPA.get_method_option('host_add','ip_address')['label'],
                     tooltip: IPA.get_method_option('host_add','ip_address')['doc']
                 }
-            ]
+            ]            
         }).
         deleter_dialog({
             factory: IPA.host_deleter_dialog
@@ -128,6 +129,35 @@ IPA.entity_factories.host = function () {
         build();
 };
 
+IPA.host_adder_dialog = function(spec)
+{
+    spec = spec || {};  
+    
+    var that = IPA.add_dialog(spec);
+    
+    that.is_custom_success = function(data) {
+        return (data.error && data.error.code === 4304);    
+    };
+    
+    that.on_custom_success = function(data, text_status, xhr) {
+        var command = this;
+        var dialog = IPA.message_dialog({
+            message: data.error.message,
+            title: spec.title,
+            on_ok: function() {                
+                data.result = {
+                    result: {
+                        fqdn: that.get_field('fqdn').save()
+                    }
+                };                
+                command.on_success(data, text_status, xhr);
+            }
+        });
+        dialog.open(that.container);        
+    };
+    return that;
+};
+
 IPA.host_deleter_dialog = function(spec) {
 
     spec = spec || {};
diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index a6c9694cb8e213956ac290647e3218835a4f333e..ff8c9f20f34a4cfa5701051691b548bc9a06f673 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -200,6 +200,9 @@ IPA.command = function(spec) {
 
     that.on_success = spec.on_success;
     that.on_error = spec.on_error;
+    
+    that.is_custom_success = spec.is_custom_success;
+    that.on_custom_success = spec.on_custom_success;
 
     that.retry = typeof spec.retry == 'undefined' ? true : spec.retry;
 
@@ -333,6 +336,10 @@ IPA.command = function(spec) {
                     message: data ? xhr.statusText : 'No response'
                 });
 
+            } else if (that.is_custom_success && that.on_custom_success &&
+                that.is_custom_success(data, text_status, xhr)) {
+                IPA.hide_activity_icon();
+                that.on_custom_success(data, text_status, xhr);
             } else if (data.error) {
                 // error_handler() calls IPA.hide_activity_icon()
                 error_handler.call(this, xhr, text_status,  /* error_thrown */ {
@@ -443,6 +450,12 @@ IPA.batch_command = function (spec) {
                             }
                         );
 
+                    } else if (command.is_custom_success && 
+                              command.on_custom_success &&
+                              command.is_custom_success(result,                                                         result, 
+                                                        text_status,
+                                                        xhr)) {                        
+                        command.on_custom_success(result, text_status, xhr);
                     } else if (result.error) {
                         if (command.on_error) command.on_error(
                             xhr,
-- 
1.7.6

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

Reply via email to