[CalendarServer-changes] [6257] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Sep 8 10:19:47 PDT 2010


Revision: 6257
          http://trac.macosforge.org/projects/calendarserver/changeset/6257
Author:   cdaboo at apple.com
Date:     2010-09-08 10:19:47 -0700 (Wed, 08 Sep 2010)
Log Message:
-----------
Send a push notification to the client when a share is added or removed.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/resource.py
    CalendarServer/trunk/twistedcaldav/sharing.py
    CalendarServer/trunk/txdav/common/datastore/file.py
    CalendarServer/trunk/txdav/common/datastore/sql.py
    CalendarServer/trunk/txdav/common/datastore/sql_legacy.py

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2010-09-08 16:03:55 UTC (rev 6256)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2010-09-08 17:19:47 UTC (rev 6257)
@@ -495,7 +495,7 @@
                 if dataObject:
                     label = "collection" if isvirt else "default"
                     notifierID = dataObject.notifierID(label=label)
-                    if notifierID is not None:
+                    if notifierID is not None and config.Notifications.Services.XMPPNotifier.Enabled:
                         pubSubConfiguration = getPubSubConfiguration(config)
                         nodeName = getPubSubPath(notifierID, pubSubConfiguration)
                         propVal = customxml.PubSubXMPPPushKeyProperty(nodeName)
@@ -2234,7 +2234,7 @@
 
         if qname == (customxml.calendarserver_namespace, "push-transports"):
             notifierID = self._newStoreHome.notifierID()
-            if notifierID is not None:
+            if notifierID is not None and config.Notifications.Services.XMPPNotifier.Enabled:
                 pubSubConfiguration = getPubSubConfiguration(config)
                 children = []
                 if pubSubConfiguration['aps-bundle-id']:
@@ -2272,7 +2272,7 @@
 
         if qname == (customxml.calendarserver_namespace, "pushkey"):
             notifierID = self._newStoreHome.notifierID()
-            if notifierID is not None:
+            if notifierID is not None and config.Notifications.Services.XMPPNotifier.Enabled:
                 pubSubConfiguration = getPubSubConfiguration(config)
                 nodeName = getPubSubPath(notifierID, pubSubConfiguration)
                 return succeed(customxml.PubSubXMPPPushKeyProperty(nodeName))
@@ -2282,7 +2282,7 @@
 
         if qname == (customxml.calendarserver_namespace, "xmpp-uri"):
             notifierID = self._newStoreHome.notifierID()
-            if notifierID is not None:
+            if notifierID is not None and config.Notifications.Services.XMPPNotifier.Enabled:
                 pubSubConfiguration = getPubSubConfiguration(config)
                 return succeed(customxml.PubSubXMPPURIProperty(
                     getPubSubXMPPURI(notifierID, pubSubConfiguration)))
@@ -2359,6 +2359,9 @@
     def principalForRecord(self):
         raise NotImplementedError("Subclass must implement principalForRecord()")
 
+    def notifyChanged(self):
+        self._newStoreHome.notifyChanged()
+
     # Methods not supported
     http_ACL = None
     http_COPY = None

Modified: CalendarServer/trunk/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/sharing.py	2010-09-08 16:03:55 UTC (rev 6256)
+++ CalendarServer/trunk/twistedcaldav/sharing.py	2010-09-08 17:19:47 UTC (rev 6257)
@@ -979,26 +979,31 @@
 
         # Add or update in DB
         oldShare = self.sharesDB().recordForShareUID(shareUID)
-        if not oldShare:
-            oldShare = share = SharedCollectionRecord(shareUID, sharetype, hostUrl, str(uuid4()), displayname)
+        if oldShare:
+            share = oldShare
+        else:
+            share = SharedCollectionRecord(shareUID, sharetype, hostUrl, str(uuid4()), displayname)
             self.sharesDB().addOrUpdateRecord(share)
         
         # Set per-user displayname to whatever was given
         sharedCollection = (yield request.locateResource(hostUrl))
         ownerPrincipal = (yield self.ownerPrincipal(request))
-        sharedCollection.setVirtualShare(ownerPrincipal, oldShare)
+        sharedCollection.setVirtualShare(ownerPrincipal, share)
         if displayname:
             yield sharedCollection.writeProperty(davxml.DisplayName.fromString(displayname), request)
-            
+        
         # Calendars always start out transparent
-        if sharedCollection.isCalendarCollection():
+        if oldShare and sharedCollection.isCalendarCollection():
             yield sharedCollection.writeProperty(caldavxml.ScheduleCalendarTransp(caldavxml.Transparent()), request)
  
+        # Notify client of changes
+        self.notifyChanged()
+
         # Return the URL of the shared collection
         returnValue(XMLResponse(
             code = responsecode.OK,
             element = customxml.SharedAs(
-                davxml.HRef.fromString(joinURL(self.url(), oldShare.localname))
+                davxml.HRef.fromString(joinURL(self.url(), share.localname))
             )
         ))
 
@@ -1036,6 +1041,9 @@
                 inbox.processFreeBusyCalendar(shareURL, False)
 
         self.sharesDB().removeRecordForShareUID(share.shareuid)
+ 
+        # Notify client of changes
+        self.notifyChanged()
 
     @inlineCallbacks
     def declineShare(self, request, hostUrl, inviteUID):

Modified: CalendarServer/trunk/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/file.py	2010-09-08 16:03:55 UTC (rev 6256)
+++ CalendarServer/trunk/txdav/common/datastore/file.py	2010-09-08 17:19:47 UTC (rev 6257)
@@ -448,13 +448,13 @@
             return lambda: self._path.child(childPath.basename()).remove()
 
         self._transaction.addOperation(do, "create child %r" % (name,))
-        if self._notifier:
-            self._transaction.postCommit(self._notifier.notify)
         props = c.properties()
         props[PropertyName(*ResourceType.qname())] = c.resourceType()
         self.createdChild(c)
 
+        self.notifyChanged()
 
+
     def createdChild(self, child):
         pass
 
@@ -501,8 +501,7 @@
             do, "prepare child remove %r" % (name,)
         )
 
-        if self._notifier:
-            self._transaction.postCommit(self._notifier.notify)
+        self.notifyChanged()
 
     # @cached
     def properties(self):
@@ -519,7 +518,14 @@
         else:
             return None
 
+    def notifyChanged(self):
+        """
+        Trigger a notification of a change
+        """
+        if self._notifier:
+            self._txn.postCommit(self._notifier.notify)
 
+
 class CommonHomeChild(FileMetaDataMixin, LoggingMixIn, FancyEqMixin):
     """
     Common ancestor class of AddressBooks and Calendars.
@@ -603,8 +609,7 @@
 
         self.retrieveOldIndex().bumpRevision()
 
-        if self._notifier:
-            self._transaction.postCommit(self._notifier.notify)
+        self.notifyChanged()
 
     def ownerHome(self):
         return self._home
@@ -708,8 +713,7 @@
                 return lambda: None
             self._transaction.addOperation(do, "remove object resource object %r" %
                                            (name,))
-            if self._notifier:
-                self._transaction.postCommit(self._notifier.notify)
+            self.notifyChanged()
         else:
             raise NoSuchObjectResourceError(name)
 
@@ -765,7 +769,14 @@
         else:
             return None
 
+    def notifyChanged(self):
+        """
+        Trigger a notification of a change
+        """
+        if self._notifier:
+            self._txn.postCommit(self._notifier.notify)
 
+
 class CommonObjectResource(FileMetaDataMixin, LoggingMixIn, FancyEqMixin):
     """
     @ivar _path: The path of the file on disk

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2010-09-08 16:03:55 UTC (rev 6256)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2010-09-08 17:19:47 UTC (rev 6257)
@@ -411,8 +411,7 @@
         newChild._initSyncToken()
         self.createdChild(newChild)
 
-        if self._notifier:
-            self._txn.postCommit(self._notifier.notify)
+        self.notifyChanged()
 
 
     def createdChild(self, child):
@@ -436,8 +435,7 @@
         self._children.pop(name, None)
         if self._txn._cursor.rowcount == 0:
             raise NoSuchHomeChildError()
-        if self._notifier:
-            self._txn.postCommit(self._notifier.notify)
+        self.notifyChanged()
 
 
     @cached
@@ -448,7 +446,7 @@
             self._resourceID
         )
 
-
+    
     # IDataStoreResource
     def contentType(self):
         """
@@ -479,6 +477,14 @@
         else:
             return None
 
+    def notifyChanged(self):
+        """
+        Trigger a notification of a change
+        """
+        if self._notifier:
+            self._txn.postCommit(self._notifier.notify)
+        
+
 class CommonHomeChild(LoggingMixIn, FancyEqMixin):
     """
     Common ancestor class of AddressBooks and Calendars.
@@ -540,8 +546,7 @@
         self._home._children[name] = self
         self._updateSyncToken()
 
-        if self._notifier:
-            self._txn.postCommit(self._notifier.notify)
+        self.notifyChanged()
 
 
     def ownerHome(self):
@@ -624,8 +629,7 @@
         self._objects.pop(uid, None)
         self._deleteRevision(name)
 
-        if self._notifier:
-            self._txn.postCommit(self._notifier.notify)
+        self.notifyChanged()
 
 
     def removeObjectResourceWithUID(self, uid):
@@ -641,8 +645,7 @@
         self._objects.pop(uid, None)
         self._deleteRevision(name)
 
-        if self._notifier:
-            self._txn.postCommit(self._notifier.notify)
+        self.notifyChanged()
 
 
     def _initSyncToken(self):
@@ -781,14 +784,6 @@
     def _doValidate(self, component):
         raise NotImplementedError
 
-    def notifierID(self, label="default"):
-        if self._notifier:
-            return self._notifier.getID(label)
-        else:
-            return None
-
-
-
     # IDataStoreResource
     def contentType(self):
         raise NotImplementedError()
@@ -818,6 +813,20 @@
         )[0][0]
         return int(modified)
 
+    def notifierID(self, label="default"):
+        if self._notifier:
+            return self._notifier.getID(label)
+        else:
+            return None
+
+    def notifyChanged(self):
+        """
+        Trigger a notification of a change
+        """
+        if self._notifier:
+            self._txn.postCommit(self._notifier.notify)
+        
+
 class CommonObjectResource(LoggingMixIn, FancyEqMixin):
     """
     @ivar _path: The path of the file on disk

Modified: CalendarServer/trunk/txdav/common/datastore/sql_legacy.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql_legacy.py	2010-09-08 16:03:55 UTC (rev 6256)
+++ CalendarServer/trunk/txdav/common/datastore/sql_legacy.py	2010-09-08 17:19:47 UTC (rev 6257)
@@ -66,7 +66,7 @@
         return NotificationRecord(
             notificationObject.uid(),
             notificationObject.name(),
-            notificationObject._fieldQuery("XML_TYPE"))
+            notificationObject._fieldQuery("XML_TYPE")) if notificationObject else None
 
 
     def recordForName(self, name):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100908/efeca7de/attachment-0001.html>


More information about the calendarserver-changes mailing list