Hello,

This patch adds option to add host dialog which allows to show generated OTP. The patch also changes the way of informing user about success of adding host
but only when the 'Generate OTP' option is checked.

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

--
Pavel^3 Vomacka
>From 28ce87a474fa1488cb3b61d32cb4790a482348c7 Mon Sep 17 00:00:00 2001
From: Pavel Vomacka <pvoma...@redhat.com>
Date: Wed, 30 Mar 2016 10:19:39 +0200
Subject: [PATCH] Add option to show OTP when adding host

Add option to add host dialog which allows to show generated OTP.
This patch also changed the way of informing user about success of adding host
but only when the 'Generate OTP' option is checked.

https://fedorahosted.org/freeipa/ticket/4602
---
 install/ui/src/freeipa/host.js     | 105 +++++++++++++++++++++++++++++++++++++
 install/ui/test/data/ipa_init.json |   3 ++
 ipalib/plugins/internal.py         |   3 ++
 3 files changed, 111 insertions(+)

diff --git a/install/ui/src/freeipa/host.js b/install/ui/src/freeipa/host.js
index 764e551b40a00d3a35ea4e8ec99de9164bc97be3..88776bb5d173dad1158fc905058c16cb9d859541 100644
--- a/install/ui/src/freeipa/host.js
+++ b/install/ui/src/freeipa/host.js
@@ -347,6 +347,12 @@ return {
                         $type: 'force_host_add_checkbox',
                         name: 'force',
                         metadata: '@mc-opt:host_add:force'
+                    },
+                    {
+                        $type: 'checkbox',
+                        name: 'random',
+                        label: '@i18n:objects.host.generate_otp',
+                        title: '@i18n:objects.host.generate_otp'
                     }
                 ]
             }
@@ -534,6 +540,105 @@ IPA.host_adder_dialog = function(spec) {
         that.container.addClass('host-adder-dialog');
     };
 
+    that.get_random_password = function(data) {
+        return data.result.result.randompassword;
+    };
+
+    that.on_add = function() {
+        that.hide_message();
+        that.add(
+            function(data, text_status, xhr) {
+                that.added.notify([data], that);
+                that.close();
+                that.handle_notifications(data);
+            },
+            that.on_error);
+    };
+
+    that.get_button('add_and_add_another').click = function() {
+        that.hide_message();
+        that.add(
+            function(data, text_status, xhr) {
+                that.added.notify([data], that);
+                that.show_message(that.get_success_message(data), 'success');
+                if (that.get_field('random').get_value()[0]) {
+                    var message = that.get_random_password(data);
+                    message = text.get('@i18n:objects.host.generated_otp') +
+                        ": " + message;
+                    that.show_message(message);
+                }
+                that.reset();
+                that.focus_first_element();
+            },
+            that.on_error);
+    };
+
+    that.get_button('add_and_edit').click = function() {
+        that.hide_message();
+        that.add(
+            function(data, text_status, xhr) {
+                that.added.notify([data], that);
+                that.close();
+                var result = data.result.result;
+                that.show_edit_page(that.entity, result);
+                that.handle_notifications(data);
+            },
+            that.on_error);
+    };
+
+    that.handle_notifications = function(data) {
+        if (that.get_field('random').get_value()[0]) {
+            var dialog = that.open_result_dialog(data);
+            dialog.show_message(that.get_success_message(data), 'success');
+        }
+        else {
+            that.notify_success(data);
+        }
+    };
+
+    that.create_result_dialog = function() {
+        spec = {
+            title: text.get('@i18n:dialogs.result'),
+            sections: [
+                {
+                    show_header: false,
+                    fields: [
+                        {
+                            $type: 'text',
+                            name: 'randompassword',
+                            label: '@i18n:objects.host.generated_otp',
+                            read_only: true,
+                            writable: true
+                        }
+                    ]
+                }
+            ]
+        };
+
+        var dialog = IPA.dialog(spec);
+
+        dialog.create_button({
+            name: 'close',
+            label: text.get('@i18n:buttons.close'),
+            click: function() {
+                dialog.close();
+            }
+        });
+
+        return dialog;
+    };
+
+    that.open_result_dialog = function(data) {
+        var dialog = that.create_result_dialog();
+
+        dialog.open();
+
+        var field = dialog.get_field('randompassword');
+        field.load(data);
+
+        return dialog;
+    };
+
     that.on_error = rpc.create_4304_error_handler(that);
 
     return that;
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index 852b953736da0ccb8a7803259e2bd5d4c4108ab9..f410049f13ae61dcd64dfb057ec834e28d14c5af 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -119,6 +119,7 @@
                         "redirection": "Redirection",
                         "remove_empty": "Select entries to be removed.",
                         "remove_title": "Remove ${entity}",
+                        "result": "Result",
                         "show_details": "Show details",
                         "success": "Success",
                         "validation_message": "Input form contains invalid or missing values.",
@@ -381,6 +382,8 @@
                             "enrolled": "Enrolled",
                             "enrollment": "Enrollment",
                             "fqdn": "Fully Qualified Host Name",
+                            "generate_otp": "Generate OTP",
+                            "generated_otp": "Generated OTP",
                             "keytab": "Kerberos Key",
                             "keytab_missing": "Kerberos Key Not Present",
                             "keytab_present": "Kerberos Key Present, Host Provisioned",
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index 7156d4f47004dd702d3896ca736cc1f42227a321..b0dbe997d9bc73fe95cbc699874f5c27dfae73e5 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -262,6 +262,7 @@ class i18n_messages(Command):
             "redirection": _("Redirection"),
             "remove_empty": _("Select entries to be removed."),
             "remove_title": _("Remove ${entity}"),
+            "result": _("Result"),
             "show_details": _("Show details"),
             "success": _("Success"),
             "validation_title": _("Validation error"),
@@ -526,6 +527,8 @@ class i18n_messages(Command):
                 "enrolled": _("Enrolled"),
                 "enrollment": _("Enrollment"),
                 "fqdn": _("Fully Qualified Host Name"),
+                "generate_otp": _("Generate OTP"),
+                "generated_otp": _("Generated OTP"),
                 "keytab": _("Kerberos Key"),
                 "keytab_missing": _("Kerberos Key Not Present"),
                 "keytab_present": _("Kerberos Key Present, Host Provisioned"),
-- 
2.5.5

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to