On 11/08/2010 06:44 PM, Endi Sukma Dewata wrote:
On 11/8/2010 12:01 PM, Adam Young wrote:



The functionality works, but there are some issues:

1. The JSON files contain some trailing whitespaces.

2. The server seems to be using "true" and "False" for nsaccountlock value. So it might be safer to use case-insensitive comparison or normalize the value using toLowerCase().

3. The title & text variables are declared twice:

    var title = "Active";
    var text = "Active:  Click to Deactivate";
    if (locked) {
        var title = "Inactive";    // remove var
        var text = "Inactive:  Click to Activate";   // remove var
    }

4. As you described on IRC, after enabling/disabling the user the browser goes back to the search page immediately because of several reasons: the update and enable/disable operations aren't likely to be used together, and the server doesn't return the new account status in JSON response. I don't have any objection to this, but the behavior might be unexpected by users. I'd like to see how others think about this.



Fixed issues 1-3.
From 3c9fc345c1560c7520cf15621441643f434abd51 Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Mon, 8 Nov 2010 12:57:16 -0500
Subject: [PATCH] Disable Enable user

UI updated to use the enable and disable methods, and to correctly report them
Implementation has a few shortcomings:
1.  Status is displayed in Browser alert dialog, not JQueryUI themed
2.  Upon completion of RPC, navigate back to the Search page.

Still, this is much less broken than before.

With whitespace cleanup,
using toLowerCase for testing true
and removde dual declaration of variables
---
 install/static/test/data/user_disable.json |    9 ++
 install/static/test/data/user_enable.json  |    9 ++
 install/static/user.js                     |  124 ++++++++++------------------
 3 files changed, 63 insertions(+), 79 deletions(-)
 create mode 100644 install/static/test/data/user_disable.json
 create mode 100644 install/static/test/data/user_enable.json

diff --git a/install/static/test/data/user_disable.json b/install/static/test/data/user_disable.json
new file mode 100644
index 0000000..75a71fd
--- /dev/null
+++ b/install/static/test/data/user_disable.json
@@ -0,0 +1,9 @@
+{
+    "error": null,
+    "id": 6,
+    "result": {
+        "result": true,
+        "summary": "Disabled user account \"rfrank\"",
+        "value": "rfrank"
+    }
+}
\ No newline at end of file
diff --git a/install/static/test/data/user_enable.json b/install/static/test/data/user_enable.json
new file mode 100644
index 0000000..c596c81
--- /dev/null
+++ b/install/static/test/data/user_enable.json
@@ -0,0 +1,9 @@
+{
+    "error": null,
+    "id": 6,
+    "result": {
+        "result": true,
+        "summary": "Enabled user account \"rfrank\"",
+        "value": "rfrank"
+    }
+}
\ No newline at end of file
diff --git a/install/static/user.js b/install/static/user.js
index 1b6054d..7846239 100644
--- a/install/static/user.js
+++ b/install/static/user.js
@@ -48,7 +48,8 @@ ipa_entity_set_details_definition('user', [
         input({name:'displayname', label:'Dispaly Name'}).
         input({name:'initials', label:'Initials'}),
     ipa_stanza({name:'account', label:'Account Details'}).
-        input({name:'status', label:'Account Status', load:user_status_load}).
+        input({name:'nsaccountlock', label:'Account Status',
+               load:user_status_load}).
         input({name:'uid', label:'Login'}).
         input({name:'userpassword',
                label:'Password',
@@ -81,96 +82,61 @@ ipa_entity_set_association_definition('user', {
     'taskgroup': { associator: 'serial' }
 });
 
-/* Account status Toggle button */
-
-function toggle_on_click(obj)
-{
-    var jobj = $(obj);
-    var val = jobj.attr('title');
-    if (val == 'Active') {
-        ipa_cmd(
-            'lock', [qs['pkey']], {}, on_lock_win, on_fail,
-            IPA.metadata['user']['name']
-        );
-    } else {
-        ipa_cmd(
-            'unlock', [qs['pkey']], {}, on_lock_win, on_fail,
-            IPA.metadata['user']['name']
-        );
-    }
-    return (false);
-}
 
-function on_lock_win(data, textStatus, xhr)
-{
-    if (data['error']) {
-        alert(data['error']['message']);
-        return;
-    }
 
-    var jobj = $('a[title=Active]');
-    if (jobj.length) {
-        if (ipa_details_cache) {
-            var memberof = ipa_details_cache['memberof'];
-            if (memberof) {
-                memberof.push(
-                    'cn=inactivated,cn=account inactivation'
-                );
-            } else {
-                memberof = ['cn=inactivated,cn=account inactivation'];
-            }
-            ipa_details_cache['memberof'] = memberof;
-            a_status(jobj.parent().prev(), ipa_details_cache);
-            jobj.parent().remove()
-        }
-        return;
-    }
 
-    var jobj = $('a[title=Inactive]');
-    if (jobj.length) {
-        if (ipa_details_cache) {
-            var memberof = ipa_details_cache['memberof'];
-            if (memberof) {
-                for (var i = 0; i < memberof.length; ++i) {
-                    if (memberof[i].indexOf('cn=inactivated,cn=account inactivation') != -1) {
-                        memberof.splice(i, 1);
-                        break;
-                    }
-                }
-            } else {
-                memberof = [];
-            }
-            ipa_details_cache['memberof'] = memberof;
-            a_status(jobj.parent().prev(), ipa_details_cache);
-            jobj.parent().remove();
-        }
-        return;
-    }
-}
 
 /* ATTRIBUTE CALLBACKS */
 
-var toggle_temp = 'S <a href="jslink" onclick="return (toggle_on_click(this))" title="S">Toggle</a>';
+
 function user_status_load(container, result) {
+    var lock_field = 'nsaccountlock';
+
     var dt = $('dt[title='+this.name+']', container);
     if (!dt.length) return;
 
-    var memberof = result['memberof'];
-    var dd;
-
-    if (memberof) {
-        for (var i = 0; i < memberof.length; ++i) {
-            if (memberof[i].indexOf('cn=inactivated,cn=account inactivation') != -1) {
-                var t = toggle_temp.replace(/S/g, 'Inactive');
-                dd = ipa_create_first_dd(this.name, t);
-                dt.after(dd);
-                return;
-            }
-        }
+    var locked  = result[lock_field] &&
+        result[lock_field][0].toLowerCase() === 'true';
+    var title = "Active";
+    var text = "Active:  Click to Deactivate";
+    if (locked) {
+        title = "Inactive";
+        text = "Inactive:  Click to Activate";
     }
 
-    dd = ipa_create_first_dd(this.name, toggle_temp.replace(/S/g, 'Inactive'));
-    dt.after(dd);
+    function on_lock_win(data, textStatus, xhr){
+        alert(data.result.summary);
+        $.bbq.pushState('user-facet','search');
+        return false;
+    }
+
+    function on_lock_fail(data, textStatus, xhr){
+        $("#userstatuslink").text = "Error changing account status";
+        return false;
+    }
+
+    var status_field =
+        $('<a/>',
+          {
+              id: 'userstatuslink',
+              title: title,
+              href: "jslink",
+              text: text,
+              click: function() {
+                  var jobj = $(this);
+                  var val = jobj.attr('title');
+                  var pkey =  $.bbq.getState('user-pkey');
+                  var command = 'user_enable';
+                  if (val == 'Active') {
+                      command = 'user_disable';
+                  }
+                  ipa_cmd(command, [pkey], {}, on_lock_win,on_lock_fail);
+
+                  return (false);
+              }
+          });
+
+    dt.after(ipa_create_first_dd(this.name, status_field));
 }
 
 
-- 
1.7.1

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

Reply via email to