[Helma-user] Collection items dependent of logged-in user?
Julian Tree
julian.tree at gmail.com
Fri Aug 18 18:05:19 CEST 2006
Andy, I asked that question a while back. It took me a while to get
use to this, but helma handles user related data restriction a little
differently.
Instead of restrict the user in type.properties
you access all the data through session.user object instead
for example. On a job tracking system in allow user to only access
jobs belong to the logged in user,
User/type.properties
-------------------------------
_id = USER_ID
_name = USERNAME
username = USERNAME
password = PASSWORD
jobs = collection(Job)
jobs.local = USER_ID
jobs.foreign = JOB_USER_ID
jobs.order = JOB_NAME ASC
Jobs/type.properties
-------------------------------
_id = JOB_ID
job_name = JOB_NAME
job_description = JOB_DESCRIPTION
user = object(User)
user.local = JOB_USER_ID
user.foreign = USER_ID
After the user login, using session.login() function, session.user is
the currently logged in user object
To access only jobs for the currently logged in user,
var currentUserJobs = session.user.jobs;
var str = "";
for (var i=0; i< currentUserJobs.size(); i++) {
var job = currentUserJobs.get(i);
str += job.renderSkinAsString("link");
}
Hope that make sense. So instead of trying to construct SQL
statement with filters, in helma it is recommended that you use
relationship to map every thing as child or grand child of the
Logged in User object.
Julian
On Aug 18, 2006, at 11:23 AM, Andy Hessling wrote:
> Hi,
>
> I have a question regarding the MySQL filter functionality/best
> practice in types.properties. These filters work just fine, I have
> collections of objects attached to my HopObject and can narrow down
> the selection of these objects by having a filter specify column
> constraints in the local/foreign table, or have static constraints
> like "not null". Now, is there any way I can access JS variable
> contents inside this type.properties file? I want to make the
> collection dependent on the current user that is logged in my system.
> If I could reference the session object for example, that could work.
> Comparing the columns "userID" in the collection's DB table with the
> user ID of the user whos currently logged in.
>
> Any thoughts?
>
>
> Thanks,
> Andy
> _______________________________________________
> Helma-user mailing list
> Helma-user at helma.org
> http://helma.org/mailman/listinfo/helma-user
More information about the Helma-user
mailing list