Am Mittwoch, 6. April 2005 20:21 schrieb Stephan Richter:
> On Wednesday 06 April 2005 16:22, Florian Lindner wrote:
> > I you think that is a good idea, I would like (to try) to make the
> > modifications at the HomeFolderManager. (as a junior job, practice and as
> > well as a little bit giving back for all your help).
>
> Sure. Go ahead.

Ok, I've made the changes and it works for me.

The diff I've created with:

[EMAIL PROTECTED] ~ $ svn diff Zope3/src/zope/app/homefolder/ > homefolder.diff

is attached.

I've also changed the readme to provide a example of the new feature.

However the changes are not formally tested. The homefolder module has not 
contained any tests I could have used as a template and since I've never 
written tests of zope components I've skipped that for now.

But I can't really imagine that you (Stephan) as the original auther wrote no 
tests (while propagating tests so strongly in his book), so I somehow suspect 
the README.txt to act as test module and that the code samples are 
executable. But I got no idea how to run these tests (if they are tests). 
tests.py just reports that are no functional oder unit tests to run.

Regards,

Florian
Index: Zope3/src/zope/app/homefolder/interfaces.py
===================================================================
--- Zope3/src/zope/app/homefolder/interfaces.py	(revision 29876)
+++ Zope3/src/zope/app/homefolder/interfaces.py	(working copy)
@@ -44,10 +44,17 @@
 
     createHomeFolder = Bool(
         title=_("Create Home Folder"),
-        description=_("Whether home folders should be created, if missing."),
+        description=_("Whether home folders should be created upon adding a assignment, if missing."),
         required=True,
         default=True)
-
+        
+    autoCreateAssignment = Bool(
+        title=_("Auto create assignment"),
+        description=_("Whether assignment and folder should be created when "
+                      "calling getHomeFolder, if not existing."),
+        required=True,
+        default=False)
+            
     homeFolderRole = Choice(
         title=_("Local Home Folder Role"),
         description=_("The local role that the user will have in "
@@ -80,10 +87,14 @@
     def getHomeFolder(principalId):
         """Get the home folder instance of the specified principal.
 
-        If the home folder does not exist and `autoCreateFolder` is set to
-        `True`, then create the home folder. During creation, the principal
-        should get manager rights inside the folder.
+        If a assignment does not exist and `autoCreateAssignment` is set to
+        `True`, then create the assignment and the homefolder. The homefolder 
+        will always be created regardless of the value of createHomeFolder.
+        The folder will be given the same name like the principalId.
+        
+        During creation, the principal should get the rights specified in 
+        homeFolderRole inside the folder.
 
-        If the home folder does not exist and `autoCreateFolder` is set to
+        If the home folder does not exist and `autoCreateAssignment` is set to
         `False`, then return `None`.
         """
Index: Zope3/src/zope/app/homefolder/homefolder.py
===================================================================
--- Zope3/src/zope/app/homefolder/homefolder.py	(revision 29876)
+++ Zope3/src/zope/app/homefolder/homefolder.py	(working copy)
@@ -35,6 +35,7 @@
     # See IHomeFolderManager
     homeFolderBase = None
     createHomeFolder = True
+    autoCreateAssignment = False
     homeFolderRole = u'zope.Manager'
 
     def __init__(self):
@@ -68,7 +69,10 @@
     def getHomeFolder(self, principalId):
         """See IHomeFolderManager"""
         if principalId not in self.assignments:
-            return None
+            if self.autoCreateAssignment:
+                self.assignHomeFolder(principalId, create=True)
+            else:
+                return None
         
         return self.homeFolderBase.get(self.assignments[principalId], None)
 
Index: Zope3/src/zope/app/homefolder/README.txt
===================================================================
--- Zope3/src/zope/app/homefolder/README.txt	(revision 29876)
+++ Zope3/src/zope/app/homefolder/README.txt	(working copy)
@@ -129,14 +129,27 @@
 
 
 If you try to get a folder and it does not yet exist, `None` will be
-returned. Remember 'dreamcatcher', which has an assignment, but not a folder?
+returned if autoCreateAssignment is False. Remember 'dreamcatcher', which 
+has an assignment, but not a folder:
 
   >>> 'dreamcatcher' in baseFolder
   False
   >>> homeFolder = manager.getHomeFolder('dreamcatcher')
   >>> homeFolder is None
   True
+  
+However, if autoCreateAssignment is True and you try to get a home folder
+of a principal which has no assignment, the assignment and the folder
+will be automatically created. The folder will always be created, regardless
+of the value of createHomeFolder. The name of the folder will be identically
+to the principalId:
 
+  >>> manager.autoCreateAssignment = True
+  >>> homeFolder = manager.getHomeFolder('florian')
+  >>> 'florian' in manager.assignments
+  True
+  >>> 'florian' in baseFolder
+  True
 
 Accessing the Home Folder
 -------------------------
_______________________________________________
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to