HBAC Test validation message now contains all missing values in form of list of links instead of general 'missing values' message and redirection to first missing value's facet.

When a link is clicked user is redirected to value's facet.

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

Note: In a list I chose to display an option label instead of facet label. IMHO it seems better with message 'Missing values'.
--
Petr Vobornik
From 5781e74e6fd0f790f20f9063652132d0f0dd2d56 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Mon, 12 Mar 2012 14:13:11 +0100
Subject: [PATCH] Better hbactest validation message

HBAC Test validation message contains all missing values in form of list of links instead of general 'missing values' message and redirection to first missing value's facet.

When a link is clicked user is redirected to value's facet.

https://fedorahosted.org/freeipa/ticket/2182
---
 install/ui/dialog.js               |    2 +
 install/ui/hbactest.js             |  104 ++++++++++++++++++++++++++++++------
 install/ui/jsl.conf                |    1 +
 install/ui/test/data/ipa_init.json |    1 +
 ipalib/plugins/internal.py         |    1 +
 5 files changed, 92 insertions(+), 17 deletions(-)

diff --git a/install/ui/dialog.js b/install/ui/dialog.js
index 324eb9b93e8557af44a4dbcfe39609a6d149b44e..9003aa8202fe07d4b386c3d152578f3e82a6942c 100644
--- a/install/ui/dialog.js
+++ b/install/ui/dialog.js
@@ -664,5 +664,7 @@ IPA.message_dialog = function(spec) {
 
     init();
 
+    that.message_dialog_create = that.create;
+
     return that;
 };
diff --git a/install/ui/hbactest.js b/install/ui/hbactest.js
index 0e77083cafcd6a61170bf347fe9c5e428366eae3..cab579e13cc90972a523233385e2d4ab6c547c5d 100644
--- a/install/ui/hbactest.js
+++ b/install/ui/hbactest.js
@@ -410,19 +410,6 @@ IPA.hbac.test_select_facet = function(spec) {
     that.validate = function(record) {
         if (record[that.name]) return true;
 
-        var dialog = IPA.message_dialog({
-            title: IPA.messages.dialogs.validation_title,
-            message: IPA.messages.dialogs.validation_message
-        });
-
-        dialog.on_ok = function() {
-            var state = {};
-            state[that.entity.name+'-facet'] = that.name;
-            IPA.nav.push_state(state);
-        };
-
-        dialog.open();
-
         return false;
     };
 
@@ -691,22 +678,34 @@ IPA.hbac.test_run_facet = function(spec) {
         var command = IPA.command({ method: 'hbactest' });
 
         var options = {};
+        var validation_results = {
+            valid: true,
+            invalid_facets: []
+        };
 
         var facet = that.entity.get_facet('user');
         facet.save(options);
-        if (!facet.validate(options)) return;
+        that.validate_facet(facet, options, validation_results);
 
         facet = that.entity.get_facet('targethost');
         facet.save(options);
-        if (!facet.validate(options)) return;
+        that.validate_facet(facet, options, validation_results);
 
         facet = that.entity.get_facet('service');
         facet.save(options);
-        if (!facet.validate(options)) return;
+        that.validate_facet(facet, options, validation_results);
 
         facet = that.entity.get_facet('sourcehost');
         facet.save(options);
-        if (!facet.validate(options)) return;
+        that.validate_facet(facet, options, validation_results);
+
+        if (!validation_results.valid) {
+            var dialog = IPA.hbac.validation_dialog({
+                validation_results: validation_results
+            });
+            dialog.open();
+            return;
+        }
 
         facet = that.entity.get_facet('rules');
         facet.save(options);
@@ -721,6 +720,17 @@ IPA.hbac.test_run_facet = function(spec) {
         command.execute();
     };
 
+    that.validate_facet = function(facet, options, validation_results) {
+
+        var facet_valid = facet.validate(options);
+
+        validation_results.valid = facet_valid && validation_results.valid;
+
+        if (!facet_valid) {
+            validation_results.invalid_facets.push(facet);
+        }
+    };
+
     that.get_records_map = function(data) {
 
         var records_map = $.ordered_map();
@@ -759,4 +769,64 @@ IPA.hbac.test_run_facet = function(spec) {
     return that;
 };
 
+IPA.hbac.validation_dialog = function(spec)  {
+
+    spec = spec || {};
+    spec.title = spec.title || IPA.messages.dialogs.validation_title;
+    spec.message = spec.message || IPA.messages.dialogs.validation_message;
+
+    var that = IPA.message_dialog(spec);
+
+    that.validation_results = spec.validation_results;
+
+    that.create = function() {
+
+        if (that.message) {
+            that.message_dialog_create();
+        }
+
+        if (that.validation_results && that.validation_results.invalid_facets) {
+            var invalid_facets = that.validation_results.invalid_facets;
+
+            var ul;
+
+            if (invalid_facets.length > 0) {
+                var div = $('<div/>',{
+                     text: IPA.messages.objects.hbactest.missing_values
+                }).appendTo(that.container);
+                ul = $('<ul/>').appendTo(that.container);
+            }
+
+            for (var i=0; i<invalid_facets.length; i++) {
+
+                var facet = invalid_facets[i];
+
+                var li = $('<li />').appendTo(ul);
+
+                var metadata = IPA.get_command_option('hbactest', facet.name);
+
+                $('<a />', {
+                    href: '#'+facet.name,
+                    text: metadata.label,
+                    click: function(facet) {
+                        return function() {
+                            that.redirect_to_facet(facet);
+                            return false;
+                        };
+                    }(facet)
+                }).appendTo(li);
+            }
+        }
+    };
+
+    that.redirect_to_facet = function(facet) {
+        that.close();
+        var state = {};
+        state[facet.entity.name+'-facet'] = facet.name;
+        IPA.nav.push_state(state);
+    };
+
+    return that;
+};
+
 IPA.register('hbactest', IPA.hbac.test_entity);
diff --git a/install/ui/jsl.conf b/install/ui/jsl.conf
index e03212d45da5933764d1d0b568e9fd951def323e..3eebda4e8f6f6cb9ed9b3b502feec3558d723bc4 100644
--- a/install/ui/jsl.conf
+++ b/install/ui/jsl.conf
@@ -144,6 +144,7 @@
 +process user.js
 +process group.js
 +process hbac.js
++process hbactest.js
 +process host.js
 +process hostgroup.js
 +process netgroup.js
diff --git a/install/ui/test/data/ipa_init.json b/install/ui/test/data/ipa_init.json
index 0182aab733a5541d3149ea582bd975faf04db10a..3f27b663ce09c4a861157f6fb1f4b3cea6f56d1b 100644
--- a/install/ui/test/data/ipa_init.json
+++ b/install/ui/test/data/ipa_init.json
@@ -266,6 +266,7 @@
                             "include_enabled": "Include Enabled",
                             "label": "HBAC Test",
                             "matched": "Matched",
+                            "missing_values": "Missing values: ",
                             "new_test": "New Test",
                             "rules": "Rules",
                             "run_test": "Run Test",
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index deff866eee1c073f3f786686fd2e74f9261ba6b4..2dfa33b45f67a78581b74783b8ef227ea03c6374 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -404,6 +404,7 @@ class i18n_messages(Command):
                 "include_enabled": _("Include Enabled"),
                 "label": _("HBAC Test"),
                 "matched": _("Matched"),
+                "missing_values": _("Missing values: "),
                 "new_test": _("New Test"),
                 "rules": _("Rules"),
                 "run_test": _("Run Test"),
-- 
1.7.7.6

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

Reply via email to