[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/homefolder/ Add option to the homefolder utility to have assignment and folder automatically created upon call of getHomeFolder.

Florian Lindner Florian.Lindner at xgm.de
Mon Apr 11 15:04:54 EDT 2005


Log message for revision 29944:
  Add option to the homefolder utility to have assignment and folder
 automatically created upon call of getHomeFolder.


Changed:
  U   Zope3/trunk/src/zope/app/homefolder/README.txt
  U   Zope3/trunk/src/zope/app/homefolder/homefolder.py
  U   Zope3/trunk/src/zope/app/homefolder/interfaces.py

-=-
Modified: Zope3/trunk/src/zope/app/homefolder/README.txt
===================================================================
--- Zope3/trunk/src/zope/app/homefolder/README.txt	2005-04-11 13:29:33 UTC
 (rev 29943) +++ Zope3/trunk/src/zope/app/homefolder/README.txt	2005-04-11
 18:41:07 UTC (rev 29944) @@ -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
 -------------------------

Modified: Zope3/trunk/src/zope/app/homefolder/homefolder.py
===================================================================
--- Zope3/trunk/src/zope/app/homefolder/homefolder.py	2005-04-11 13:29:33 UTC
 (rev 29943) +++ Zope3/trunk/src/zope/app/homefolder/homefolder.py	2005-04-11
 18:41:07 UTC (rev 29944) @@ -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)


Modified: Zope3/trunk/src/zope/app/homefolder/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/homefolder/interfaces.py	2005-04-11 13:29:33 UTC
 (rev 29943) +++ Zope3/trunk/src/zope/app/homefolder/interfaces.py	2005-04-11
 18:41:07 UTC (rev 29944) @@ -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`.
         """


More information about the Zope3-Checkins mailing list