Made this class work again when there is no
actual user session and it just represents a database record that represents a user. This should fix all bugs where the user specific methods didn't work unless the user object represented a user that was actually active at the time of calling.
This commit is contained in:
parent
4f28990143
commit
ce781df919
1 changed files with 16 additions and 6 deletions
|
@ -5,13 +5,14 @@ package helma.scripting.fesi;
|
||||||
|
|
||||||
import helma.framework.core.*;
|
import helma.framework.core.*;
|
||||||
import helma.objectmodel.*;
|
import helma.objectmodel.*;
|
||||||
|
import helma.objectmodel.db.Node;
|
||||||
import FESI.Interpreter.*;
|
import FESI.Interpreter.*;
|
||||||
import FESI.Exceptions.*;
|
import FESI.Exceptions.*;
|
||||||
import FESI.Data.*;
|
import FESI.Data.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ESUser is a special kind of Node object that represents a user of
|
* The ESUser is a special kind of Node object that represents a user of
|
||||||
* a HOP application. The actual user session data are kept in class User.
|
* a Helma application. The actual user session data are kept in class User.
|
||||||
* If the user is logged in as a registered member, the wrapped node represents
|
* If the user is logged in as a registered member, the wrapped node represents
|
||||||
* the user object in the database, while for anonymous surfers the node object
|
* the user object in the database, while for anonymous surfers the node object
|
||||||
* is just a transient node. <p>
|
* is just a transient node. <p>
|
||||||
|
@ -39,6 +40,8 @@ public class ESUser extends ESNode {
|
||||||
* Overrides getProperty to return the uid (which is not a regular property)
|
* Overrides getProperty to return the uid (which is not a regular property)
|
||||||
*/
|
*/
|
||||||
public ESValue getProperty (String propname, int hash) throws EcmaScriptException {
|
public ESValue getProperty (String propname, int hash) throws EcmaScriptException {
|
||||||
|
// if there is a user session object, we expose some of its properties.
|
||||||
|
// Otherwise, we call the parent's class getProperty method.
|
||||||
if ("uid".equals (propname)) {
|
if ("uid".equals (propname)) {
|
||||||
if (user == null || user.getUID () == null)
|
if (user == null || user.getUID () == null)
|
||||||
return ESNull.theNull;
|
return ESNull.theNull;
|
||||||
|
@ -51,7 +54,7 @@ public class ESUser extends ESNode {
|
||||||
else
|
else
|
||||||
return new ESString (user.getSessionID ());
|
return new ESString (user.getSessionID ());
|
||||||
}
|
}
|
||||||
if ("cache".equals (propname))
|
if ("cache".equals (propname) && user != null)
|
||||||
return cacheWrapper;
|
return cacheWrapper;
|
||||||
return super.getProperty (propname, hash);
|
return super.getProperty (propname, hash);
|
||||||
}
|
}
|
||||||
|
@ -62,6 +65,10 @@ public class ESUser extends ESNode {
|
||||||
* own node, but just reach through to the session user object instead.
|
* own node, but just reach through to the session user object instead.
|
||||||
*/
|
*/
|
||||||
public void setNode (INode node) {
|
public void setNode (INode node) {
|
||||||
|
// this only makes sense if this wrapper represents an active user
|
||||||
|
if (user == null)
|
||||||
|
return;
|
||||||
|
// set the node on the transient user session object
|
||||||
user.setNode (node);
|
user.setNode (node);
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
|
@ -71,8 +78,8 @@ public class ESUser extends ESNode {
|
||||||
this.node = user.getNode ();
|
this.node = user.getNode ();
|
||||||
}
|
}
|
||||||
// set node handle to wrapped node
|
// set node handle to wrapped node
|
||||||
if (node instanceof helma.objectmodel.db.Node)
|
if (node instanceof Node)
|
||||||
handle = ((helma.objectmodel.db.Node) node).getHandle ();
|
handle = ((Node) node).getHandle ();
|
||||||
else
|
else
|
||||||
handle = null;
|
handle = null;
|
||||||
// we don't take over the transient cache from the node,
|
// we don't take over the transient cache from the node,
|
||||||
|
@ -80,10 +87,13 @@ public class ESUser extends ESNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateNodeFromUser () {
|
public void updateNodeFromUser () {
|
||||||
|
// this only makes sense if this wrapper represents an active user
|
||||||
|
if (user == null)
|
||||||
|
return;
|
||||||
node = user.getNode ();
|
node = user.getNode ();
|
||||||
// set node handle to wrapped node
|
// set node handle to wrapped node
|
||||||
if (node instanceof helma.objectmodel.db.Node)
|
if (node instanceof Node)
|
||||||
handle = ((helma.objectmodel.db.Node) node).getHandle ();
|
handle = ((Node) node).getHandle ();
|
||||||
else
|
else
|
||||||
handle = null;
|
handle = null;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue