[Zope-PTK] Some methods for the PortalMembership kit

Tres Seaver tseaver@digicool.com
Thu, 21 Dec 2000 23:03:19 -0500


"Morten W. Petersen" wrote:
> 
> Hi guys,
> 
> just thought I'd share some functions I've made for the PortalMembership kit.
> These methods lets us use a tree structure like so:
> 
> /a/a/a/a/Members
> /a/c/d/a/Members

First, let me note that I am delighted to see this kind of
experimentation / innovation against the framework that the
tools provide.

Second, a question:  is the intent to "hash" the member folders
(like the classic Unixism, '/home/t/ts/tseaver' bit) to deal more
sanely with large numbers of them?  If so, then I think what you
want is to have a *single* user folder[1] and override the standard
'getHomeFolder()' and 'getHomeUrl()' methods of the membership tool.
E.g.:

 class HashedFolderMembershipTool(
      PTKDemo.DemoMembershipTool.DemoMembershipTool ):
     """
         Hash member IDs across a hierarchy.
     """
     def getHomeUrl( self, id=None, verifyPermission=0 ):
         """
             Returns URL of member's home folder.  Note that we
             hash the ID across a 4-layer directory tree, which
             is probably extreme.  Note as well that this method
             makes no guarantee that the path can be resolved.
         """
         if id is None:
             member = self.getAuthenticatedMember()
             if not hasattr( member, 'getMemberId' ):
                 return None
             id = member.getMemberId()
         hashpath = string.join( map( None, ( id + 'xxxxxx' )[:4] ), '/'
)
         return '%s/Members/%s/%s' % ( self.portal_url(), hashpath, id )

     def getHomeFolder( self, id=None, verifyPermission=0 ):
         """
             Returns a member's home folder object, if we can find it,
             or None.
         """
         url = self.getHomeUrl( id, verifyPermission )
         try:
             if verifyPermission:
                 return self.restrictedTraverse( url )
             else:
                 return self.unrestrictedTraverse( url )
         except KeyError: pass
         except AttributeError: pass
         except 'Unauthorized': pass  # swallow this one
         return None

Obviously, this code presumes that some other methods have actually
created the member folder in the appropriate location (which should
be computed by calling 'getHomeUrl()', of course!)


[1] Have you successfully integrated the current LoginManager with
    the PTK?  If so, could you write up the steps you took to make
    it work?  Bill Anderson is particularly interested in such an
    integration for his "Membership" product.


Tres.
-- 
===============================================================
Tres Seaver                                tseaver@digicool.com
Digital Creations     "Zope Dealers"       http://www.zope.org