[CalendarServer-changes] [8539] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Mon Jan 16 08:52:00 PST 2012


Revision: 8539
          http://trac.macosforge.org/projects/calendarserver/changeset/8539
Author:   cdaboo at apple.com
Date:     2012-01-16 08:52:00 -0800 (Mon, 16 Jan 2012)
Log Message:
-----------
Fix copy/move behavior to/from shared calendars.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/method/put_common.py

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2012-01-16 16:51:06 UTC (rev 8538)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2012-01-16 16:52:00 UTC (rev 8539)
@@ -1,6 +1,6 @@
 # -*- test-case-name: twistedcaldav.directory.test.test_principal -*-
 ##
-# Copyright (c) 2006-2011 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2012 Apple Inc. All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -716,6 +716,15 @@
     def __str__(self):
         return "(%s)%s" % (self.record.recordType, self.record.shortNames[0])
 
+    def __eq__(self, other):
+        """
+        Principals are the same if their principalURLs are the same.
+        """
+        return (self.principalURL() == other.principalURL()) if isinstance(other, DirectoryPrincipalResource) else False
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
     @inlineCallbacks
     def readProperty(self, property, request):
         if type(property) is tuple:

Modified: CalendarServer/trunk/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/put_common.py	2012-01-16 16:51:06 UTC (rev 8538)
+++ CalendarServer/trunk/twistedcaldav/method/put_common.py	2012-01-16 16:52:00 UTC (rev 8539)
@@ -1,6 +1,6 @@
 # -*- test-case-name: twistedcaldav.test.test_validation -*-
 ##
-# Copyright (c) 2005-2011 Apple Inc. All rights reserved.
+# Copyright (c) 2005-2012 Apple Inc. All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -205,7 +205,6 @@
         """
 
         # Basic validation
-        yield self.validCopyMoveOperation()
         self.validIfScheduleMatch()
 
         if self.destinationcal:
@@ -351,6 +350,9 @@
                 # would be better to copy the index entries from the source and add to the destination.
                 self.calendar = (yield self.source.iCalendarForUser(self.request))
 
+            # Check that moves to shared calendars are OK
+            yield self.validCopyMoveOperation()
+
             # Check access
             if self.destinationcal and config.EnablePrivateEvents:
                 result = (yield self.validAccess())
@@ -361,7 +363,11 @@
         elif self.sourcecal:
             self.source_index = self.sourceparent.index()
             self.calendar = (yield self.source.iCalendarForUser(self.request))
-    
+
+        # Check that moves to shared calendars are OK
+        yield self.validCopyMoveOperation()
+
+
     @inlineCallbacks
     def validCopyMoveOperation(self):
         """
@@ -377,14 +383,35 @@
                 # Moving into a calendar requires regular checks
                 pass
             else:
-                # Calendar to calendar moves are OK if the owner is the same
-                sourceowner = (yield self.sourceparent.owner(self.request))
-                destowner = (yield self.destinationparent.owner(self.request))
+                # Calendar to calendar moves are OK if the resource owner is the same.
+                # Use resourceOwnerPrincipal for this as that takes into account sharing such that the
+                # returned principal relates to the URI path used to access the resource rather than the
+                # underlying resource owner (sharee).
+                sourceowner = (yield self.sourceparent.resourceOwnerPrincipal(self.request))
+                destowner = (yield self.destinationparent.resourceOwnerPrincipal(self.request))
+
                 if sourceowner != destowner:
-                    msg = "Calendar-to-calendar %s with different owners are not supported" % ("moves" if self.deletesource else "copies",)
+                    msg = "Calendar-to-calendar %s with different homes are not supported" % ("moves" if self.deletesource else "copies",)
                     log.debug(msg)
                     raise HTTPError(StatusResponse(responsecode.FORBIDDEN, msg))
+                    
+                # Calendar to calendar moves where Organizer is present are not OK if the owners are different.
+                sourceowner = (yield self.sourceparent.ownerPrincipal(self.request))
+                destowner = (yield self.destinationparent.ownerPrincipal(self.request))
 
+                if sourceowner != destowner:
+                    # Now check whether an ORGANIZER property is present in either sourcecal or destcal
+                    organizer = self.calendar.getOrganizer()
+                    if organizer is None and self.destination.exists() and self.destinationcal:
+                        oldCal = yield self.destination.iCalendar()
+                        organizer = oldCal.getOrganizer()
+                    
+                    if organizer is not None:
+                        msg = "Calendar-to-calendar %s with an organizer property present and different owners are not supported" % ("moves" if self.deletesource else "copies",)
+                        log.debug(msg)
+                        raise HTTPError(StatusResponse(responsecode.FORBIDDEN, msg))
+
+
     def validIfScheduleMatch(self):
         """
         Check for If-ScheduleTag-Match header behavior.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120116/589c4a98/attachment.html>


More information about the calendarserver-changes mailing list