Widgets in host enrollment sections were modified. They now serve only for displaying of has_key and has_password status. Functionality for setting otp and unprovisioning was moved to separate dialogs. Execution points for opening of these dialogs are items in new action panel in enrollment section.

https://fedorahosted.org/freeipa/ticket/2251
--
Petr Vobornik
From 83cafa76316efe492d5cba308245f0c9db64c296 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Wed, 6 Jun 2012 17:52:15 +0200
Subject: [PATCH] Action panel for host enrollment

Widgets in host enrollment sections were modified. They now serve only for displaying of has_key and has_password status. Functionality for setting otp and unprovisioning was moved to separate dialogs. Execution points for opening of these dialogs are items in new action panel in enrollment section.

https://fedorahosted.org/freeipa/ticket/2251
---
 install/ui/details.js |   56 ++++++++
 install/ui/facet.js   |    4 +-
 install/ui/host.js    |  372 ++++++++++++++++++++++++++++++-------------------
 install/ui/ipa.css    |    2 +-
 install/ui/widget.js  |    2 +
 5 files changed, 289 insertions(+), 147 deletions(-)

diff --git a/install/ui/details.js b/install/ui/details.js
index d5f6bfc8066fe93cb546dcdff47e015b38afc1eb..48c8adb6034fdc246f8cc523e8a932832b4aea3d 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -1008,6 +1008,62 @@ IPA.acl_state_evaluator = function(spec) {
     return that;
 };
 
+IPA.value_state_evaluator = function(spec) {
+
+    spec.name = spec.name || 'value_state_evaluator';
+    spec.event = spec.event || 'post_load';
+
+    var that = IPA.state_evaluator(spec);
+    that.attribute = spec.attribute;
+    that.value = spec.value;
+    that.representation = spec.representation;
+
+    that.on_event = function(data) {
+
+        var old_state, record, state, value, loaded_value;
+
+        old_state = that.state;
+        record = data.result.result;
+        value = that.normalize_value(that.value);
+        loaded_value = record[that.attribute];
+        loaded_value = that.normalize_value(loaded_value);
+
+        that.state = [];
+
+        if (!IPA.array_diff(value, loaded_value)) {
+            that.state.push(that.get_state_text());
+        }
+
+        that.notify_on_change(old_state);
+    };
+
+    that.normalize_value = function(original) {
+
+        var value = original;
+
+        if (!(value instanceof Array)) {
+            value = [value];
+        }
+        return value;
+    };
+
+    that.get_state_text = function() {
+
+        var representation, value;
+
+        representation = that.representation;
+
+        if (!representation) {
+            value = that.normalize_value(that.value);
+            representation = that.attribute + '_' + value[0];
+        }
+
+        return representation;
+    };
+
+    return that;
+};
+
 IPA.object_action = function(spec) {
 
     spec = spec || {};
diff --git a/install/ui/facet.js b/install/ui/facet.js
index 62950f6c41756fdd914da813eedcf1b76c77d11b..550407bb7c974295602dffb83631f6dc551e2794 100644
--- a/install/ui/facet.js
+++ b/install/ui/facet.js
@@ -1523,6 +1523,7 @@ IPA.state_evaluator = function(spec) {
     //when state changes. Params: state, Context: this
     that.changed = IPA.observer();
     that.state = [];
+    that.first_pass = true;
 
     that.init = function(facet) {
 
@@ -1536,8 +1537,9 @@ IPA.state_evaluator = function(spec) {
 
     that.notify_on_change = function(old_state) {
 
-        if (IPA.array_diff(that.state, old_state)) {
+        if (that.first_pass || IPA.array_diff(that.state, old_state)) {
             that.changed.notify([that.state], that);
+            that.first_pass = false;
         }
     };
 
diff --git a/install/ui/host.js b/install/ui/host.js
index d07d63d951de52b5e8315225ff180db4c626876a..e693f5f8e0f0b7118687523c2e3ab5da67cd2a16 100644
--- a/install/ui/host.js
+++ b/install/ui/host.js
@@ -77,6 +77,11 @@ IPA.host.entity = function(spec) {
                 },
                 {
                     name: 'enrollment',
+                    action_panel: {
+                        factory: IPA.action_panel,
+                        name: 'enrollment_actions',
+                        actions: ['unprovision', 'set_otp', 'reset_otp']
+                    },
                     fields: [
                         {
                             factory: IPA.host_keytab_widget,
@@ -101,6 +106,31 @@ IPA.host.entity = function(spec) {
                     ]
                 }
             ],
+            actions: [
+                IPA.host.unprovision_action,
+                {
+                    factory: IPA.host.set_otp_action,
+                    name: 'set_otp',
+                    label: IPA.messages.objects.host.password_set_title,
+                    status: 'missing',
+                    hide_cond: ['has_password']
+                },
+                {
+                    factory: IPA.host.set_otp_action,
+                    name: 'reset_otp',
+                    label: IPA.messages.objects.host.password_reset_title,
+                    status: 'present',
+                    show_cond: ['has_password']
+                }
+            ],
+            state: {
+                evaluators: [
+                    IPA.host.has_password_evaluator,
+                    IPA.host.has_keytab_evaluator,
+                    IPA.host.userpassword_acl_evaluator,
+                    IPA.host.krbprincipalkey_acl_evaluator
+                ]
+            },
             policies: [
                 IPA.host_enrollment_policy()
             ]
@@ -530,58 +560,65 @@ IPA.host_keytab_widget = function(spec) {
         that.present_span.append(' ');
 
         that.present_span.append(IPA.messages.objects.host.keytab_present);
+    };
 
-        that.present_span.append(': ');
+    that.update = function(values) {
+        set_status(values[0] ? 'present' : 'missing');
+    };
 
-        IPA.button({
-            name: 'unprovision',
-            label: IPA.messages.objects.host.delete_key_unprovision,
-            click: function() {
-                that.show_unprovision_dialog();
-                return false;
-            }
-        }).appendTo(that.present_span);
+    that.clear = function() {
+        that.present_span.css('display', 'none');
+        that.missing_span.css('display', 'none');
     };
 
-    that.show_unprovision_dialog = function() {
+    function set_status(status) {
+        that.present_span.css('display', status == 'present' ? 'inline' : 'none');
+        that.missing_span.css('display', status == 'missing' ? 'inline' : 'none');
+    }
+
+    return that;
+};
+
+IPA.host_unprovision_dialog = function(spec) {
 
-        var label = that.entity.metadata.label_singular;
-        var title = IPA.messages.objects.host.unprovision_title;
-        title = title.replace('${entity}', label);
+    spec.title = spec.title || IPA.messages.objects.host.unprovision_title;
 
-        var dialog = IPA.dialog({
-            'title': title
-        });
+    spec = spec || {};
+
+    var that = IPA.dialog(spec);
+    that.facet = spec.facet;
+
+    that.title = that.title.replace('${entity}', that.entity.metadata.label_singular);
+
+    that.create = function() {
+        that.container.append(IPA.messages.objects.host.unprovision_confirmation);
+    };
 
-        dialog.create = function() {
-            dialog.container.append(IPA.messages.objects.host.unprovision_confirmation);
-        };
+    that.create_buttons = function() {
 
-        dialog.create_button({
+        that.create_button({
             name: 'unprovision',
             label: IPA.messages.objects.host.unprovision,
             click: function() {
                 that.unprovision(
                     function(data, text_status, xhr) {
-                        set_status('missing');
-                        dialog.close();
+                        that.facet.refresh();
+                        that.close();
                     },
                     function(xhr, text_status, error_thrown) {
-                        dialog.close();
+                        that.close();
                     }
                 );
             }
         });
 
-        dialog.create_button({
+        that.create_button({
             name: 'cancel',
             label: IPA.messages.buttons.cancel,
             click: function() {
-                dialog.close();
+                that.close();
             }
         });
-
-        dialog.open(that.container);
     };
 
     that.unprovision = function(on_success, on_error) {
@@ -601,20 +638,50 @@ IPA.host_keytab_widget = function(spec) {
         command.execute();
     };
 
-    that.update = function(values) {
-        set_status(values[0] ? 'present' : 'missing');
-    };
+    that.create_buttons();
+
+    return that;
+};
+
+IPA.host.unprovision_action = function(spec) {
+
+    spec = spec || {};
+    spec.name = spec.name || 'unprovision';
+    spec.label = spec.label || IPA.messages.objects.host.unprovision;
+    spec.enable_cond = spec.enable_cond || ['has_keytab', 'krbprincipalkey_w'];
+
+    var that = IPA.action(spec);
+
+    that.execute_action = function(facet) {
 
-    that.clear = function() {
-        that.present_span.css('display', 'none');
-        that.missing_span.css('display', 'none');
+        var dialog = IPA.host_unprovision_dialog({
+            entity: facet.entity,
+            facet: facet
+        });
+
+        dialog.open();
     };
 
-    function set_status(status) {
-        that.present_span.css('display', status == 'present' ? 'inline' : 'none');
-        that.missing_span.css('display', status == 'missing' ? 'inline' : 'none');
-    }
+    return that;
+};
+
+IPA.host.krbprincipalkey_acl_evaluator = function(spec) {
+
+    spec.name = spec.name || 'unprovision_acl_evaluator';
+    spec.attribute = spec.attribute || 'krbprincipalkey';
+
+    var that = IPA.acl_state_evaluator(spec);
+    return that;
+};
+
+IPA.host.has_keytab_evaluator = function(spec) {
+
+    spec.name = spec.name || 'has_keytab_evaluator';
+    spec.attribute = spec.attribute || 'has_keytab';
+    spec.value = spec.value || [true];
+    spec.representation = spec.representation || 'has_keytab';
 
+    var that = IPA.value_state_evaluator(spec);
     return that;
 };
 
@@ -624,8 +691,6 @@ IPA.host_password_widget = function(spec) {
 
     var that = IPA.input_widget(spec);
 
-    that.password_change_request = IPA.observer();
-
     that.create = function(container) {
 
         that.widget_create(container);
@@ -656,62 +721,82 @@ IPA.host_password_widget = function(spec) {
         that.present_span.append(' ');
 
         that.present_span.append(IPA.messages.objects.host.password_present);
+    };
 
-        container.append(': ');
+    that.update = function(values) {
+        set_status(values[0] ? 'present' : 'missing');
+    };
 
-        that.set_password_button = IPA.button({
+    that.clear = function() {
+        that.missing_span.css('display', 'none');
+        that.present_span.css('display', 'none');
+    };
+
+    function set_status(status) {
+
+        that.status = status;
+
+        if (status == 'missing') {
+            that.missing_span.css('display', 'inline');
+            that.present_span.css('display', 'none');
+        } else {
+            that.missing_span.css('display', 'none');
+            that.present_span.css('display', 'inline');
+        }
+    }
+
+    return that;
+};
+
+IPA.widget_factories['host_password'] = IPA.host_password_widget;
+IPA.field_factories['host_password'] = IPA.field;
+
+IPA.host.set_otp_dialog = function(spec) {
+
+    spec = spec || {};
+    spec.width = spec.width || 400;
+    spec.sections = spec.sections || [
+        {
+            fields: [
+                {
+                    name: 'password1',
+                    label: IPA.messages.password.new_password,
+                    type: 'password'
+                },
+                {
+                    name: 'password2',
+                    label: IPA.messages.password.verify_password,
+                    type: 'password'
+                }
+            ]
+        }
+    ];
+
+    var that = IPA.dialog(spec);
+    that.facet = spec.facet;
+
+    that.set_status = function(status) {
+
+        var button = that.get_button('set_password');
+
+        if (status == 'missing') {
+            that.title = IPA.messages.objects.host.password_set_title;
+            button.label = IPA.messages.objects.host.password_set_button;
+        } else {
+            that.title = IPA.messages.objects.host.password_reset_title;
+            button.label = IPA.messages.objects.host.password_reset_button;
+        }
+    };
+
+    that.create_buttons = function() {
+
+        that.create_button({
             name: 'set_password',
             label: IPA.messages.objects.host.password_set_button,
             click: function() {
-                that.show_password_dialog();
-                return false;
-            }
-        }).appendTo(container);
-    };
-
-    that.show_password_dialog = function() {
-
-        var title;
-        var label;
-
-        if (that.status == 'missing') {
-            title = IPA.messages.objects.host.password_set_title;
-            label = IPA.messages.objects.host.password_set_button;
-        } else {
-            title = IPA.messages.objects.host.password_reset_title;
-            label = IPA.messages.objects.host.password_reset_button;
-        }
-
-
-        var dialog = that.dialog = IPA.dialog({
-            title: title,
-            width: 400,
-            sections: [
-                {
-                    fields: [
-                        {
-                            name: 'password1',
-                            label: IPA.messages.password.new_password,
-                            type: 'password'
-                        },
-                        {
-                            name: 'password2',
-                            label: IPA.messages.password.verify_password,
-                            type: 'password'
-                        }
-                    ]
-                }
-            ]
-        });
-
-
-        dialog.create_button({
-            name: 'set_password',
-            label: label,
-            click: function() {
 
                 var record = {};
-                dialog.save(record);
+                that.save(record);
 
                 var new_password = record.password1[0];
                 var repeat_password = record.password2[0];
@@ -721,68 +806,22 @@ IPA.host_password_widget = function(spec) {
                     return;
                 }
 
-                that.password_change_request.notify([new_password], that);
+                that.set_otp(new_password);
 
-                dialog.close();
+                that.close();
             }
         });
 
-        dialog.create_button({
+        that.create_button({
             name: 'cancel',
             label: IPA.messages.buttons.cancel,
             click: function() {
-                dialog.close();
+                that.close();
             }
         });
-
-        dialog.open(that.container);
-    };
-
-    that.update = function(values) {
-        set_status(values[0] ? 'present' : 'missing');
-    };
-
-    that.clear = function() {
-        that.missing_span.css('display', 'none');
-        that.present_span.css('display', 'none');
-        var password_label = $('.button-label', that.set_password_button);
-        password_label.text('');
-    };
-
-    function set_status(status) {
-
-        that.status = status;
-        var password_label = $('.button-label', that.set_password_button);
-
-        if (status == 'missing') {
-            that.missing_span.css('display', 'inline');
-            that.present_span.css('display', 'none');
-            password_label.text(IPA.messages.objects.host.password_set_button);
-
-        } else {
-            that.missing_span.css('display', 'none');
-            that.present_span.css('display', 'inline');
-            password_label.text(IPA.messages.objects.host.password_reset_button);
-        }
-    }
-
-    return that;
-};
-
-IPA.host_password_field = function (spec) {
-
-    spec = spec || {};
-
-    var that = IPA.field(spec);
-
-    that.widgets_created = function() {
-
-        that.field_widgets_created();
-        that.widget.password_change_request.attach(that.set_password);
-        that.widget.search = that.search;
     };
 
-    that.set_password = function(password) {
+    that.set_otp = function(password) {
         var pkey = that.entity.get_primary_key();
 
         var command = IPA.command({
@@ -794,24 +833,67 @@ IPA.host_password_field = function (spec) {
                 rights: true,
                 userpassword: password
             },
-            on_success: function(result) {
-                that.load(result.result.result);
-                that.widget.dialog.close();
+            on_success: function(data) {
+                that.facet.load(data);
+                that.close();
             },
             on_error: function() {
-                that.widget.dialog.close();
+                that.close();
             }
         });
 
         command.execute();
     };
 
+    that.create_buttons();
 
     return that;
 };
 
-IPA.widget_factories['host_password'] = IPA.host_password_widget;
-IPA.field_factories['host_password'] = IPA.host_password_field;
+IPA.host.set_otp_action = function(spec) {
+
+    spec = spec || {};
+    spec.name = spec.name || 'set_otp';
+    spec.label = spec.label || IPA.messages.objects.host.password_set_title;
+    spec.enable_cond = spec.enable_cond || ['userpassword_w'];
+
+    var that = IPA.action(spec);
+    that.status = spec.status || 'missing';
+
+    that.execute_action = function(facet) {
+
+        var dialog = IPA.host.set_otp_dialog({
+            entity: facet.entity,
+            facet: facet
+        });
+
+        dialog.set_status(that.status);
+
+        dialog.open();
+    };
+
+    return that;
+};
+
+IPA.host.userpassword_acl_evaluator = function(spec) {
+
+    spec.name = spec.name || 'userpassword_acl_evaluator';
+    spec.attribute = spec.attribute || 'userpassword';
+
+    var that = IPA.acl_state_evaluator(spec);
+    return that;
+};
+
+IPA.host.has_password_evaluator = function(spec) {
+
+    spec.name = spec.name || 'has_password_evaluator';
+    spec.attribute = spec.attribute || 'has_password';
+    spec.value = spec.value || [true];
+    spec.representation = spec.representation || 'has_password';
+
+    var that = IPA.value_state_evaluator(spec);
+    return that;
+};
 
 IPA.host.certificate_status_field = function(spec) {
 
diff --git a/install/ui/ipa.css b/install/ui/ipa.css
index 5371070a1c875c0bab4d058eebc5a353df29a79f..c69fc80ded3dfef8a9fa645dbe74ac96d069f73a 100644
--- a/install/ui/ipa.css
+++ b/install/ui/ipa.css
@@ -1720,7 +1720,7 @@ form#login {
 .action-panel {
     position: absolute;
     right: 0;
-    top: 0;
+    top: -30px;
 
     width: 150px;
 
diff --git a/install/ui/widget.js b/install/ui/widget.js
index d3dbd4c37135d4f06ae9b6c637f30531cd7850df..ccda2aef3a6843ea1330d8ac5281cdec03f276c7 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -3238,6 +3238,8 @@ IPA.action_panel = function(spec) {
 
         var classes, state, li, a;
 
+        if (!action.visible) return;
+
         classes = ['action'];
         state = action.enabled ? 'enabled' : 'disabled';
         classes.push(state);
-- 
1.7.7.6

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

Reply via email to