Menu

#80 getPath in compiled templates?

open
nobody
5
2004-07-22
2004-07-22
Anonymous
No

Hi All,

I've been writing various decorators which would be much more
efficiently implemented by overriding the getPath() method.

An example: an auth decorator

Background: it would be nice to display content in the template
depending on the rights that the user has. It would also be nice to
only check these rights as they are required.
Solution: make a decorator that intercepts the right template vars
and checks them only when requested.

using get():
'auth.right.app.shop.view' will result in many dereferences, and
building associated classes to actaully be dereferenced, such that
only the specified right is checked (another solution would be to
check all the rights and lump the data into an ordinary dataspace -
but that's not what I'm after for performance reasons)

using getPath():
I can write the decorator such that the template var
'auth.right.app.shop.view' results in just one call to getPath.

So, I checked out the Template compiler code, hoping that the
code could be tweaked so that if a 'getPath' method exists for the
dataspace in question it writes getPath(path.to.var). But it seems
that info about the orig datasource is not availbale to the compiler.
Is this right?

I then plunged in and just changed the code in databinding.inc.php
so that all get()s become getPath()s when a path is found, instead
of dereferencing.

I also changed template.inc.php so that it passes on the getPath
calls to the orig datasource.

I've tested it a bit and it seems to work...

Many thanks,
Ian White
--
ian@ardes.com

ps. I will post details of my journey into an auth system for wact
when it's tested a little more.

Summary of features and implementation:

* wrapper class to LiveUser, using wact style config

* Authorisation is performed by action classes which check the
rights of the user and return various views depending on the result
(simple action can be configured to return a login page on auth
failure, but also can return a different page for say, a user who
has idled, or a user who has intentionally logged out.
To put page level auth, simply register an action that runs every
time.
To use auth for particular actions, simply descend form the action
class and override 'onAuthSuccess' and 'onAuthFailure'

* DataSource Decorator (described above) for easily displaying
auth content in Templates (eg 'auth.handle', 'auth.isLoggedIn')

Discussion

  • Harry Fuecks

    Harry Fuecks - 2004-07-22

    Logged In: YES
    user_id=569780

    Think Jeff's input is really needed here. Great that you're
    working on LiveUser integration.

    "So, I checked out the Template compiler code, hoping that the
    code could be tweaked so that if a 'getPath' method exists
    for the dataspace in question it writes
    getPath(path.to.var). But it seems that info about the orig
    datasource is not availbale to the compiler. Is this right?"

    If I've understood you right: unless you're using one of the
    tags that subclasses ServerDataComponentTag, that's right:
    the compiler won't know about DataSources you assign at runtime.

    It sounds a bit like we may need additional syntax for
    calling getPath directly e.g.

    <core:optional for="*auth.right.app.shop.view">
    Secret message for valid users
    </core:optional>

    Or

    {$*auth.right.app.shop.view}

     
  • Norbert Mocsnik

    Norbert Mocsnik - 2005-01-17

    Logged In: YES
    user_id=1114223

    Hi there,

    I need an auth/permission system for two of my WACT apps,
    either LiveUser [1] or phpgacl [2]. Did you succeed with the
    LiveUser integration?

    [1] http://pear.php.net/LiveUser
    [2] http://phpgacl.sf.net

    Regards,
    Norbert Mocsnik

     

Log in to post a comment.