[CalendarServer-changes] [8639] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Feb 9 10:56:44 PST 2012


Revision: 8639
          http://trac.macosforge.org/projects/calendarserver/changeset/8639
Author:   sagen at apple.com
Date:     2012-02-09 10:56:44 -0800 (Thu, 09 Feb 2012)
Log Message:
-----------
If a client resubscribes to APNS with the same device token and key but as a different user, update the DB to reflect the change in user as well as updating the timestamp.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/push/test/test_applepush.py
    CalendarServer/trunk/txdav/common/datastore/sql.py

Modified: CalendarServer/trunk/calendarserver/push/test/test_applepush.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/test/test_applepush.py	2012-02-09 17:46:12 UTC (rev 8638)
+++ CalendarServer/trunk/calendarserver/push/test/test_applepush.py	2012-02-09 18:56:44 UTC (rev 8639)
@@ -89,6 +89,19 @@
         self.assertTrue([token, key1, timestamp1] in subscriptions)
         self.assertTrue([token, key2, timestamp2] in subscriptions)
 
+        # Verify an update to a subscription with a different uid takes on
+        # the new uid
+        timestamp3 = 5000
+        uid2 = "D8FFB335-9D36-4CE8-A3B9-D1859E38C0DA"
+        yield txn.addAPNSubscription(token, key2, timestamp3, uid2)
+        subscriptions = (yield txn.apnSubscriptionsBySubscriber(uid))
+        self.assertTrue([token, key1, timestamp1] in subscriptions)
+        self.assertFalse([token, key2, timestamp3] in subscriptions)
+        subscriptions = (yield txn.apnSubscriptionsBySubscriber(uid2))
+        self.assertTrue([token, key2, timestamp3] in subscriptions)
+        # Change it back
+        yield txn.addAPNSubscription(token, key2, timestamp2, uid)
+
         yield txn.commit()
 
         # Set up the service

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2012-02-09 17:46:12 UTC (rev 8638)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2012-02-09 18:56:44 UTC (rev 8639)
@@ -356,7 +356,8 @@
     @classproperty
     def _updateAPNSubscriptionQuery(cls): #@NoSelf
         apn = schema.APN_SUBSCRIPTIONS
-        return Update({apn.MODIFIED: Parameter("modified")},
+        return Update({apn.MODIFIED: Parameter("modified"),
+                       apn.SUBSCRIBER_GUID: Parameter("subscriber")},
                       Where=(apn.TOKEN == Parameter("token")).And(
                              apn.RESOURCE_KEY == Parameter("resourceKey")))
 
@@ -388,10 +389,11 @@
                 # Subscription may have been added by someone else, which is fine
                 pass
 
-        else: # Subscription exists, so update with new timestamp
+        else: # Subscription exists, so update with new timestamp and subscriber
             try:
                 yield self._updateAPNSubscriptionQuery.on(self,
-                    token=token, resourceKey=key, modified=timestamp)
+                    token=token, resourceKey=key, modified=timestamp,
+                    subscriber=subscriber)
             except Exception:
                 # Subscription may have been added by someone else, which is fine
                 pass
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120209/ea0f9f46/attachment-0001.html>


More information about the calendarserver-changes mailing list