[CalendarServer-changes] [297] CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Tue Oct 24 13:00:28 PDT 2006


Revision: 297
          http://trac.macosforge.org/projects/calendarserver/changeset/297
Author:   cdaboo at apple.com
Date:     2006-10-24 13:00:28 -0700 (Tue, 24 Oct 2006)

Log Message:
-----------
Remove duplicate account provisioning code by using only the principal resource method. That has now been modified to
do drop box provisioning if required.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/directory.py
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/repository.py
    CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/static.py

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/directory.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/directory.py	2006-10-24 19:58:24 UTC (rev 296)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/directory.py	2006-10-24 20:00:28 UTC (rev 297)
@@ -543,8 +543,17 @@
             return
 
         if (new):
-            principal.provisionCalendarAccount(name, None, True, None, self.calendarhomeroot,
-                                               None, ["calendar"], self.type == DirectoryTypePrincipalProvisioningResource.typeResource)
+            principal.provisionCalendarAccount(
+                name,
+                None,
+                True,
+                None,
+                self.calendarhomeroot,
+                None,
+                None,
+                ["calendar"],
+                self.type == DirectoryTypePrincipalProvisioningResource.typeResource,
+                True)
         
         # Add directory specific attributes to principal
         principal.setPropertyValue(realname, davxml.DisplayName)

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/repository.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/repository.py	2006-10-24 19:58:24 UTC (rev 296)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/repository.py	2006-10-24 20:00:28 UTC (rev 297)
@@ -695,126 +695,27 @@
             principal.open("w").close()
             log.msg("Created principal: %s" % principalURL)
         principal = CalendarPrincipalFile(principal.path, principalURL)
-        if len(item.pswd):
-            principal.writeDeadProperty(auth.TwistedPasswordProperty.fromString(item.pswd))
-        else:
-            principal.removeDeadProperty(auth.TwistedPasswordProperty())
-        if len(item.name):
-            principal.writeDeadProperty(davxml.DisplayName.fromString(item.name))
-        else:
-            principal.removeDeadProperty(davxml.DisplayName())
-        if len(item.cuaddrs):
-            principal.writeDeadProperty(caldavxml.CalendarUserAddressSet(*[davxml.HRef(addr) for addr in item.cuaddrs]))
-        else:
-            principal.removeDeadProperty(caldavxml.CalendarUserAddressSet())
-
-        if resetACLs or not principal_exists:
-            principal.setAccessControlList(
-                davxml.ACL(
-                    davxml.ACE(
-                        davxml.Principal(davxml.HRef.fromString(principalURL)),
-                        davxml.Grant(
-                            davxml.Privilege(davxml.Read()),
-                        ),
-                    ),
-                )
-            )
-
-        # If the user does not have any calendar user addresses we do not create a calendar home for them
-        if not item.cuaddrs and not item.calendars:
-            return
-
+        
+        # Special case: if we have an explicit cuhome URL, we will use that,
+        # otherwise we fall back to the inferred home and resource
         if item.cuhome:
-            principal.writeDeadProperty(caldavxml.CalendarHomeSet(davxml.HRef.fromString(item.cuhome)))
+            cuhome = (item.cuhome, None)
         else:
-            # Create calendar home
-            homeURL = joinURL(self.calendarHome.uri, item.uid)
-            home = FilePath(os.path.join(self.calendarHome.resource.fp.path, item.uid))
-            home_exists = home.exists()
-            if not home_exists:
-                home.createDirectory()
-            home = CalendarHomeFile(home.path)
-    
-            # Handle ACLs on calendar home
-            if resetACLs or not home_exists:
-                if item.acl:
-                    home.setAccessControlList(item.acl.acl)
-                else:
-                    home.setAccessControlList(
-                        davxml.ACL(
-                            davxml.ACE(
-                                davxml.Principal(davxml.Authenticated()),
-                                davxml.Grant(
-                                    davxml.Privilege(davxml.Read()),
-                                ),
-                            ),
-                            davxml.ACE(
-                                davxml.Principal(davxml.HRef.fromString(principalURL)),
-                                davxml.Grant(
-                                    davxml.Privilege(davxml.All()),
-                                ),
-                                TwistedACLInheritable(),
-                            ),
-                        )
-                    )
+            cuhome = (self.calendarHome.uri, self.calendarHome.resource)
             
-            # Handle quota on calendar home
-            home.setQuotaRoot(None, item.quota)
-    
-            # Save the calendar-home-set, schedule-inbox and schedule-outbox properties
-            principal.writeDeadProperty(caldavxml.CalendarHomeSet(davxml.HRef.fromString(homeURL + "/")))
-            principal.writeDeadProperty(caldavxml.ScheduleInboxURL(davxml.HRef.fromString(joinURL(homeURL, "inbox/"))))
-            principal.writeDeadProperty(caldavxml.ScheduleOutboxURL(davxml.HRef.fromString(joinURL(homeURL, "outbox/"))))
-            
-            # Set ACLs on inbox and outbox
-            if resetACLs or not home_exists:
-                inbox = home.getChild("inbox")
-                inbox.setAccessControlList(
-                    davxml.ACL(
-                        davxml.ACE(
-                            davxml.Principal(davxml.Authenticated()),
-                            davxml.Grant(
-                                davxml.Privilege(caldavxml.Schedule()),
-                            ),
-                        ),
-                    )
-                )
-                if item.autorespond:
-                    inbox.writeDeadProperty(customxml.TwistedScheduleAutoRespond())
-    
-                outbox = home.getChild("outbox")
-                if outbox.hasDeadProperty(davxml.ACL()):
-                    outbox.removeDeadProperty(davxml.ACL())
-    
-            calendars = []
-            for calendar in item.calendars:
-                childURL = joinURL(homeURL, calendar)
-                child = CalDAVFile(os.path.join(home.fp.path, calendar))
-                child_exists = child.exists()
-                if not child_exists:
-                    c = child.createCalendarCollection()
-                    assert c.called
-                    c = c.result
-                    
-                calendars.append(childURL)
-                if (resetACLs or not child_exists):
-                    child.setAccessControlList(
-                        davxml.ACL(
-                            davxml.ACE(
-                                davxml.Principal(davxml.Authenticated()),
-                                davxml.Grant(
-                                    davxml.Privilege(caldavxml.ReadFreeBusy()),
-                                ),
-                                TwistedACLInheritable(),
-                            ),
-                        )
-                    )
-            
-            # Set calendar-free-busy-set on Inbox if not already present
-            inbox = home.getChild("inbox")
-            if not inbox.hasDeadProperty(caldavxml.CalendarFreeBusySet()):
-                fbset = caldavxml.CalendarFreeBusySet(*[davxml.HRef.fromString(uri) for uri in calendars])
-                inbox.writeDeadProperty(fbset)
+        # Principal knows how to provision itself in the appropriate manner
+        principal.provisionCalendarAccount(
+            item.name,
+            item.pswd,
+            resetACLs or not principal_exists,
+            item.cuaddrs,
+            cuhome,
+            item.acl,
+            item.quota,
+            item.calendars,
+            item.autorespond,
+            True
+            )
 
 class ProvisionPrincipal (object):
     """

Modified: CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/static.py	2006-10-24 19:58:24 UTC (rev 296)
+++ CalendarServer/branches/users/cdaboo/dropbox/twistedcaldav/static.py	2006-10-24 20:00:28 UTC (rev 297)
@@ -110,22 +110,29 @@
         #
         # Create the collection once we know it is safe to do so
         #
+        return self.createSpecialCollection(davxml.ResourceType.calendar)
+    
+    def createSpecialCollection(self, resourceType=None):
+        #
+        # Create the collection once we know it is safe to do so
+        #
         def onCollection(status):
             if status != responsecode.CREATED:
                 raise HTTPError(status)
     
-            self.writeDeadProperty(davxml.ResourceType.calendar)
+            self.writeDeadProperty(resourceType)
             return status
         
         def onError(f):
             try:
                 rmdir(self.fp)
             except Exception, e:
-                log.err("Unable to clean up after failed MKCALENDAR: %s" % e)
+                log.err("Unable to clean up after failed MKCOL (special resource type: %s): %s" % (e, resourceType,))
             return f
 
         d = mkcollection(self.fp)
-        d.addCallback(onCollection)
+        if resourceType is not None:
+            d.addCallback(onCollection)
         d.addErrback(onError)
         return d
  
@@ -721,7 +728,7 @@
         """
         return self.fp.basename()
 
-    def provisionCalendarAccount(self, name, pswd, resetacl, cuaddrs, cuhome, cuhomeacls, cals, autorespond):
+    def provisionCalendarAccount(self, name, pswd, resetacl, cuaddrs, cuhome, cuhomeacls, quota, cals, autorespond, allowdropbox):
         """
         Provision the principal and a calendar account for it.
         
@@ -733,6 +740,7 @@
         @param cuhomeacls: L{ACL} acls to use on calendar home when resetting ACLs, or C{None} to use default set.
         @param cals: C{list} list of calendar names to create in the calendar home for this prinicpal.
         @param autorespond: C{True} if iTIP auto-response is required, C{False} otherwise.
+        @param allowdropbox: C{True} if drop box should be enabled for this user is drop box is supproted, C{False} otherwise.
         """
         
         if pswd:
@@ -764,89 +772,101 @@
         if not cuaddrs and not cals:
             return
 
-        # Create calendar home
-        homeURL = joinURL(cuhome[0], self.principalUID())
-        home = FilePath(os.path.join(cuhome[1].fp.path, self.principalUID()))
-        home_exists = home.exists()
-        if not home_exists:
-            home.createDirectory()
-        home = CalendarHomeFile(home.path)
-
-        if resetacl or not home_exists:
-            if cuhomeacls:
-                home.setAccessControlList(cuhomeacls.acl)
-            else:
-                home.setAccessControlList(
-                    davxml.ACL(
-                        davxml.ACE(
-                            davxml.Principal(davxml.Authenticated()),
-                            davxml.Grant(
-                                davxml.Privilege(davxml.Read()),
+        # Create calendar home if we already have the resource, otherwise simply record
+        # the URL as the calendar-home-set
+        if cuhome[1] is None:
+            self.writeDeadProperty(caldavxml.CalendarHomeSet(davxml.HRef.fromString(cuhome[0])))
+        else:
+            homeURL = joinURL(cuhome[0], self.principalUID())
+            home = FilePath(os.path.join(cuhome[1].fp.path, self.principalUID()))
+            home_exists = home.exists()
+            if not home_exists:
+                home.createDirectory()
+            home = CalendarHomeFile(home.path)
+    
+            if resetacl or not home_exists:
+                if cuhomeacls:
+                    home.setAccessControlList(cuhomeacls.acl)
+                else:
+                    home.setAccessControlList(
+                        davxml.ACL(
+                            davxml.ACE(
+                                davxml.Principal(davxml.Authenticated()),
+                                davxml.Grant(
+                                    davxml.Privilege(davxml.Read()),
+                                ),
                             ),
-                        ),
-                        davxml.ACE(
-                            davxml.Principal(davxml.HRef.fromString(self._url)),
-                            davxml.Grant(
-                                davxml.Privilege(davxml.All()),
+                            davxml.ACE(
+                                davxml.Principal(davxml.HRef.fromString(self._url)),
+                                davxml.Grant(
+                                    davxml.Privilege(davxml.All()),
+                                ),
+                                TwistedACLInheritable(),
                             ),
-                            TwistedACLInheritable(),
-                        ),
+                        )
                     )
-                )
+            
+            # Handle quota on calendar home
+            home.setQuotaRoot(None, quota)
         
-        # Save the calendar-home-set, schedule-inbox and schedule-outbox properties
-        self.writeDeadProperty(caldavxml.CalendarHomeSet(davxml.HRef.fromString(homeURL + "/")))
-        self.writeDeadProperty(caldavxml.ScheduleInboxURL(davxml.HRef.fromString(joinURL(homeURL, "inbox/"))))
-        self.writeDeadProperty(caldavxml.ScheduleOutboxURL(davxml.HRef.fromString(joinURL(homeURL, "outbox/"))))
-        
-        # Set ACLs on inbox and outbox
-        if resetacl or not home_exists:
-            inbox = home.getChild("inbox")
-            inbox.setAccessControlList(
-                davxml.ACL(
-                    davxml.ACE(
-                        davxml.Principal(davxml.Authenticated()),
-                        davxml.Grant(
-                            davxml.Privilege(caldavxml.Schedule()),
-                        ),
-                    ),
-                )
-            )
-            if autorespond:
-                inbox.writeDeadProperty(customxml.TwistedScheduleAutoRespond())
-
-            outbox = home.getChild("outbox")
-            if outbox.hasDeadProperty(davxml.ACL()):
-                outbox.removeDeadProperty(davxml.ACL())
-
-        calendars = []
-        for calendar in cals:
-            childURL = joinURL(homeURL, calendar)
-            child = CalDAVFile(os.path.join(home.fp.path, calendar))
-            child_exists = child.exists()
-            if not child_exists:
-                c = child.createCalendarCollection()
-                assert c.called
-                c = c.result
-            calendars.append(childURL)
-            if (resetacl or not child_exists):
-                child.setAccessControlList(
+            # Save the calendar-home-set, schedule-inbox and schedule-outbox properties
+            self.writeDeadProperty(caldavxml.CalendarHomeSet(davxml.HRef.fromString(homeURL + "/")))
+            self.writeDeadProperty(caldavxml.ScheduleInboxURL(davxml.HRef.fromString(joinURL(homeURL, "inbox/"))))
+            self.writeDeadProperty(caldavxml.ScheduleOutboxURL(davxml.HRef.fromString(joinURL(homeURL, "outbox/"))))
+            
+            # Set ACLs on inbox and outbox
+            if resetacl or not home_exists:
+                inbox = home.getChild("inbox")
+                inbox.setAccessControlList(
                     davxml.ACL(
                         davxml.ACE(
                             davxml.Principal(davxml.Authenticated()),
                             davxml.Grant(
-                                davxml.Privilege(caldavxml.ReadFreeBusy()),
+                                davxml.Privilege(caldavxml.Schedule()),
                             ),
-                            TwistedACLInheritable(),
                         ),
                     )
                 )
-        
-        # Set calendar-free-busy-set on Inbox if not already present
-        inbox = home.getChild("inbox")
-        if not inbox.hasDeadProperty(caldavxml.CalendarFreeBusySet()):
-            fbset = caldavxml.CalendarFreeBusySet(*[davxml.HRef.fromString(uri) for uri in calendars])
-            inbox.writeDeadProperty(fbset)
+                if autorespond:
+                    inbox.writeDeadProperty(customxml.TwistedScheduleAutoRespond())
+    
+                outbox = home.getChild("outbox")
+                if outbox.hasDeadProperty(davxml.ACL()):
+                    outbox.removeDeadProperty(davxml.ACL())
+    
+            calendars = []
+            for calendar in cals:
+                childURL = joinURL(homeURL, calendar)
+                child = CalDAVFile(os.path.join(home.fp.path, calendar))
+                child_exists = child.exists()
+                if not child_exists:
+                    c = child.createCalendarCollection()
+                    assert c.called
+                    c = c.result
+                calendars.append(childURL)
+                if (resetacl or not child_exists):
+                    child.setAccessControlList(
+                        davxml.ACL(
+                            davxml.ACE(
+                                davxml.Principal(davxml.Authenticated()),
+                                davxml.Grant(
+                                    davxml.Privilege(caldavxml.ReadFreeBusy()),
+                                ),
+                                TwistedACLInheritable(),
+                            ),
+                        )
+                    )
+            
+            # Set calendar-free-busy-set on Inbox if not already present
+            inbox = home.getChild("inbox")
+            if not inbox.hasDeadProperty(caldavxml.CalendarFreeBusySet()):
+                fbset = caldavxml.CalendarFreeBusySet(*[davxml.HRef.fromString(uri) for uri in calendars])
+                inbox.writeDeadProperty(fbset)
+                
+            # Do drop box if requested
+            if allowdropbox:
+                from twistedcaldav.dropbox import DropBox
+                DropBox.provision(self, (homeURL, home))
 
 
 class CalendarUserPrincipalProvisioningResource (CalendarPrincipalCollectionResource, DAVFile):

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061024/951af943/attachment.html


More information about the calendarserver-changes mailing list