r22324: Another step closer to nice listing of user accounts.
authorRafal Szczesniak <mimir@samba.org>
Tue, 17 Apr 2007 23:10:57 +0000 (23:10 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:51:02 +0000 (14:51 -0500)
rafal

services/samba/ejsnet.esp
webapps/swat/source/class/swat/module/netmgr/Fsm.js
webapps/swat/source/class/swat/module/netmgr/Gui.js

index 15b6b9b907b7c6e644bf087ea2025b8236e4487a..00424f2cae430c028608abbef07c087ac1c7b872 100644 (file)
@@ -11,57 +11,67 @@ jsonrpc_include("resources.esp");
 
 function _NetContext(params, error)
 {
-  var credParams, credentials;
-  var resName;
+  var hostName, credParams, credentials;
+  var resName = "netCtx";
 
-  if (params.length < 1)
-  {
-    /* create default NetContext based on already provided credentials */
-    credentials = session.authinfo.credentials;
-    resName = "netCtx";
-  }
-  else
+  credentials = session.authinfo.credentials;
+
+  if (params.length > 0)
   {
-    /* create user specified credentials object */
-    credParams = params[0];
-    if (typeof(credParams) != "object")
+    /* first expected argument is host name that this context is going
+       to be attached to */
+    hostName = params[0];
+    if (typeof(hostName) != "string" || hostName == "")
     {
       error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
-                    "credentials parameter is expected to be an object");
+                    "hostName parameter is expected to be a valid non zero-length string");
       return error;
     }
-  
-    if (typeof(credParams.domain) != "string")
+
+    resName = "netCtx[" + hostName + "]";
+    
+    /* check whether credentials are supplied as well */
+    if (params.length > 1)
     {
-      error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
-                    "a valid string is expected in credentials.domain");
-      return error;
-    }
+      /* create user specified credentials object */
+      credParams = params[1];
+      if (typeof(credParams) != "object")
+      {
+        error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
+                      "credentials parameter is expected to be an object");
+       return error;
+      }
+
+      if (typeof(credParams.domain) != "string")
+      {
+       error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
+                      "a valid string is expected in credentials.domain");
+       return error;
+      }
+      
+      if (typeof(credParams.username) != "string")
+      {
+       error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
+                      "a valid string is expected in credentials.username");
+       return error;
+      }
+    
+      if (typeof(credParams.username) != "string")
+      {
+       error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
+                      "a valid string is expected in credentials.password");
+       return error;
+      }
   
-    if (typeof(credParams.username) != "string")
-    {
-      error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
-                    "a valid string is expected in credentials.username");
-      return error;
+      credentials = credentials_init();
+      credentials.set_domain(credParams.domain);
+      credentials.set_username(credParams.username);
+      credentials.set_password(credParams.password);
     }
-  
-    if (typeof(credParams.username) != "string")
-    {
-      error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
-                    "a valid string is expected in credentials.password");
-      return error;
-    }
-  
-    credentials = credentials_init();
-    credentials.set_domain(credParams.domain);
-    credentials.set_username(credParams.username);
-    credentials.set_password(credParams.password);
-
-    resName = "netCtx[" + credParams.domain + "/" + credParams.username + "]";
   }
 
   /* was this NetContext created yet ? */
-  var resId = session.resources.find(key, error);
+  var resId = session.resources.find(resName, error);
   if (resId != undefined)
   {
     /* yes, return its resource id */
@@ -76,10 +86,93 @@ function _NetContext(params, error)
 jsonrpc.method.NetContext = _NetContext;
 
 
-/*
- * Local Variables:
- * mode: c
- * End:
- */
+function _NetContextCreds(params, error)
+{
+  if (params.length != 1)
+  {
+    error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
+                   "missing resource id parameter");
+    return error;
+  }
+
+  var resId = params[0];
+  if (typeof(resId) != "number")
+  {
+    error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
+                  "an integer parameter is required");
+    return error;
+  }
+  
+  var netCtx = session.resources.get(resId, error);
+  if (typeof(netCtx) != "object")
+  {
+    return null;
+  }
+
+  var creds = netCtx.credentials;
+  var result = new Object();
+  result.username = creds.get_username();
+  result.domain   = creds.get_domain();
+
+  return result;
+}
+jsonrpc.method.NetContextCreds = _NetContextCreds;
+
+
+function _UserMgr(params, error)
+{
+  var domainName = null, netCtxId;
+  var resId = -1;
+  var resName = "usrCtx";
+  var netCtx = undefined;
+  var usrCtx = undefined;
+
+  if (params.length == 0)
+  {
+    error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
+                  "NetContext parameter missing");
+    return error;
+  }
+
+  /* checking NetContext parameter */
+  netCtxId = params[0];
+  if (netCtxId == undefined || typeof(netCtxId) != "number")
+  {
+    error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
+                  "NetContext parameter is expected to be a number");
+  }
+  
+  netCtx = session.resources.get(netCtxId, error);
+  if (netCtx == undefined || typeof(netCtx) != "object")
+  {
+    error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
+                  "Incorrect NetContext passed");
+    return error;
+  }
+
+  if (params.length > 1)
+  {
+    domainName = params[1];
+    if (domainName == undefined || typeof(domainName) != "string")
+    {
+      error.setError(jsonrpc.Constant.ServerError.ParameterMismatch,
+                    "domainName parameter is expected to be a valid non zero-length string");
+      return error;
+    }
+  }
+  
+  if (domainName == "")
+  {
+    usrCtx = netCtx.UserMgr();
+  }
+  else
+  {
+    usrCtx = netCtx.UserMgr(domainName);
+  }
+
+  resId = session.resources.set(usrCtx, resName, error);
+  return resId;
+}
+jsonrpc.method.UserMgr = _UserMgr;
 
 %>
index f35e644241f5caa74d625085aca979a9cdb86589..56cc244912b0914de39ae56f49ed30ab165540be 100644 (file)
@@ -70,7 +70,13 @@ qx.Proto.buildFsm = function(module)
          "changeSelection" :
          {
            "tree" :
-             "Transition_Idle_to_AwaitRpcResult_via_tree_selection_changed"
+             "Transition_Idle_to_Idle_via_tree_selection_changed"
+          },
+
+         "changeNetCtx" :
+         {
+           "swat.module.netmgr.Gui" :
+             "Transition_Idle_to_AwaitRpcResult_via_netCtx_changed"
          }
         }
     });
@@ -85,6 +91,7 @@ qx.Proto.buildFsm = function(module)
 
       "ontransition" : function(fsm, event)
       {
+       // Create default NetContext
         var request = _this.callRpc(fsm, "samba.ejsnet", "NetContext", []);
        request.setUserData("requestType", "NetContext");
       }
@@ -111,9 +118,9 @@ qx.Proto.buildFsm = function(module)
   state.addTransition(trans);
 
   var trans = new qx.util.fsm.Transition(
-    "Transition_Idle_to_AwaitRpcResult_via_tree_selection_changed",
+    "Transition_Idle_to_Idle_via_tree_selection_changed",
     {
-      "nextState" : "State_AwaitRpcResult",
+      "nextState" : "State_Idle",
 
       "ontransition" : function(fsm, event)
       {
@@ -122,8 +129,38 @@ qx.Proto.buildFsm = function(module)
 
        var gui = swat.module.netmgr.Gui.getInstance();
        var parentNode = gui.getParentNode(module, selectedNode);
-       
-        var params = (parentNode.credentials == undefined) ? [] : [ parentNode.credentials ];
+
+       // Change current NetContext if necessary for this host
+       if (parentNode.netCtx != undefined)
+        {
+         module.setNetCtx(parentNode.netCtx);
+       }
+
+       var nodeName = selectedNode.label;
+       var callName = undefined;               // rpc call name
+       var callArgs = [ gui.getNetCtx() ];       // NetContex goes first
+
+       switch (nodeName)
+        {
+       case "Users":
+         callName = "UserMgr";
+         break;
+
+       case "Groups":
+       case "Domain":
+       case "Services":
+         alert("View not implemented yet");
+         break;
+
+       default:
+         alert("Undefined call selected for node=['" + nodeName + "']");
+       }
+
+       // Bail out if no appropriate call name has been found
+       if (callName == undefined) return;
+
+       var req = _this.callRpc(fsm, "samba.ejsnet", callName, callArgs);
+       req.setUserData("requestType", "UserMgr");
       }
       
     });
@@ -131,6 +168,21 @@ qx.Proto.buildFsm = function(module)
   // Add the new transition
   state.addTransition(trans);
   
+  var trans = new qx.util.fsm.Transition(
+    "Transition_Idle_to_AwaitRpcResult_via_netCtx_changed",
+    {
+      "nextState" : "State_AwaitRpcResult",
+
+      "ontransition" : function(fsm, event)
+      {
+       var netCtxId = 0;
+       var req = _this.callRpc(fsm, "samba.ejsnet", "NetContextCreds", [ netCtxId ]);
+       req.setUserData("requestType", "NetContextCreds");
+      }
+    });
+
+  state.addTransition(trans);
+
   blockedEvents =
   {
     "appear":
index 44bba3f5abce4c574792a616a8e1776bcdb5a75e..b78d484f51b45ffe5545ab3f5247f01736fda317 100644 (file)
@@ -5,20 +5,38 @@
 /**
  * Swat Net Manager class graphical user interface
  */
-qx.OO.defineClass("swat.module.netmgr.Gui", qx.core.Object,
+qx.OO.defineClass("swat.module.netmgr.Gui", qx.core.Target,
 function()
 {
-  qx.core.Object.call(this);
+  qx.core.Target.call(this);
 });
 
 
 //qx.OO.addProperty({ name : "_tree", type : "object" });
 //qx.OO.addProperty({ name : "_panel", type : "object" });
+//qx.OO.addProperty({ name : "_view", type : "object" });
+//qx.OO.addProperty({ name : "_txtDomain", type : "object" });
+//qx.OO.addProperty({ name : "_txtUsername", type : "object" });
+
+/* NetContex resource number assigned on the server side.
+   Necessary for every ejsnet call */
+qx.OO.addProperty({ name : "netCtx", type : "number" });
+
 
 qx.Proto.buildGui = function(module)
 {
   var fsm = module.fsm;
+  
+  // Main layout composing the whole form
+  var vlayout = new qx.ui.layout.VerticalBoxLayout();
+  vlayout.set({
+                top: 20,
+                left: 20,
+                width: "100%",
+                bottom: 20
+              });
 
+  // Horizontal layout holding TreeView and a "panel" for ListView
   var hlayout = new qx.ui.layout.HorizontalBoxLayout();
   hlayout.set({
                 top: 0,
@@ -55,38 +73,105 @@ qx.Proto.buildGui = function(module)
   
   panel.set({
               top: 0,
-              right: 20,
+              left: 10,
               width: "80%",
               height: "100%"
             });
+
+  // Setup some initial columns and (empty) item list - to be replaced soon
+  // with default view loading
+  var columns = { name : { label: "Name", width: 120, type: "text" }};
+  var items = [];
+
+  // Setup the list view
+  this._view = new qx.ui.listview.ListView(items, columns);
+  var view = this._view;
+  view.setBorder(qx.renderer.border.BorderPresets.getInstance().shadow);
+  view.setBackgroundColor("white");
+  view.set({
+             top: 0,
+             left: 0,
+             width: "80%",
+             height: "100%"
+           });
+
+  // Give a list view name to handle
+  fsm.addObject("view", view);
+
+  // and the list view to the panel
+  panel.add(view);
   
   // Add the tree view and panel for list view to the layout
   hlayout.add(tree);
   hlayout.add(panel);
 
+  // Status layout containing informative labels and status information
   var statusLayout = new qx.ui.layout.HorizontalBoxLayout();
   statusLayout.set({
-                     top: 0,
+                     top: 10,
                      left: 0,
                      right: 0,
                      height: "100%"
                    });
 
-  var vlayout = new qx.ui.layout.VerticalBoxLayout();
-  vlayout.set({
-                top: 20,
-                left: 20,
-                width: "100%",
-                bottom: 20
-              });
+  // First "column" of status fields
+  var colALayout = new qx.ui.layout.VerticalBoxLayout();
+  colALayout.set({
+                  top: 0,
+                  left: 0,
+                  width: 150,
+                  height: "100%"
+                });
+
+  // Domain name (credentials) - label and text box
+  var statusDomain = new qx.ui.layout.HorizontalBoxLayout();
+  statusDomain.set({ top: 0, left: 0, width: "100%", height: 20,
+                      verticalChildrenAlign: "middle" });
+  
+  var lblDomain = new qx.ui.basic.Atom();
+  lblDomain.setLabel("Domain:");
+  lblDomain.set({ width: 70, right: 5, horizontalChildrenAlign: "right" });
+
+  var txtDomain = new qx.ui.form.TextField();
+  txtDomain.set({ width: 80, readOnly: true });
+  this._txtDomain = txtDomain;
 
+  statusDomain.add(lblDomain);
+  statusDomain.add(txtDomain);
+  
+  // Username (credentials) - label and text box
+  var statusUsername = new qx.ui.layout.HorizontalBoxLayout();
+  statusUsername.set({ top: 0, left: 0, width: "100%", height: 20,
+                       verticalChildrenAlign: "middle" });
+
+  var lblUsername = new qx.ui.basic.Atom();
+  lblUsername.setLabel("Username:");
+  lblUsername.set({ width: 70, right: 5, horizontalChildrenAlign: "right" });
+  
+  var txtUsername = new qx.ui.form.TextField();
+  txtUsername.set({ width: 80, readOnly: true });
+  this._txtUsername = txtUsername;
+  
+  statusUsername.add(lblUsername);
+  statusUsername.add(txtUsername);
+  
+  colALayout.add(statusDomain);
+  colALayout.add(statusUsername);
+
+  statusLayout.add(colALayout);
+  
   vlayout.add(hlayout);
   vlayout.add(statusLayout);
 
   vlayout.addEventListener("appear", fsm.eventListener, fsm);
   fsm.addObject("vlayout", vlayout);
 
+  // place everything on canvas
   module.canvas.add(vlayout);
+
+  // Add event handler to netCtx property change
+  this.addEventListener("changeNetCtx", fsm.eventListener, fsm);
+  fsm.addObject("swat.module.netmgr.Gui", this);
 };
 
 
@@ -107,13 +192,21 @@ qx.Proto.displayData = function(module, rpcRequest)
   switch (requestType)
   {
     case "hostname":
-      // Add local host node
-      this._addHostNode(module, rpcRequest, true);
-      break;
+    // Add local host node
+    this._addHostNode(module, rpcRequest, true);
+    break;
 
     case "NetContext":
-      this._initNetContext(module, rpcRequest);
-      break;
+    this._initNetContext(module, rpcRequest);
+    break;
+
+    case "NetContextCreds":
+    this._updateNetContextCreds(module, rpcRequest);
+    break;
+
+    case "UserMgr":
+    this._initUserManager(module, rpcRequest);
+    break;
   }
 
   qx.ui.core.Widget.flushGlobalQueues();
@@ -163,8 +256,8 @@ qx.Proto._addHostNode = function(module, rpcRequest, local)
   var hostNode = dataModel.getData()[hostNodeId];
 
   // Set host-specific properties
-  hostNode.credentials = undefined;
-  hostNode.local = local
+  hostNode.netCtx = undefined;
+  hostNode.local = local;
 };
 
 
@@ -172,7 +265,23 @@ qx.Proto._initNetContext = function(module, rpcRequest)
 {
   // Gather obtained NetContext handle
   var result = rpcRequest.getUserData("result").data;
-  module.netCtx = result;
+  this.setNetCtx(result);
+};
+
+
+qx.Proto._updateNetContextCreds = function(module, rpcRequest)
+{
+  // Get requested credentials from the current NetContext
+  var result = rpcRequest.getUserData("result").data;
+  this._txtUsername.setValue(result.username);
+  this._txtDomain.setValue(result.domain);
+};
+
+
+qx.Proto._initUserManager = function(module, rpcRequest)
+{
+  // Get obtained UsrCtx handle
+  var result = rpcRequest.getUserData("result").data;
 };