Ejemplo n.º 1
0
    def doImplicitAttendeeEventFix(self, ex):

        # Only certain types of exception should be handled - ones related to calendar data errors.
        # All others should result in the scheduling response coming back as a 5.x code

        if type(ex) not in (InvalidOverriddenInstanceError, HTTPError):
            raise ImplicitProcessorException("5.1;Service unavailable")

        # Check to see whether the originator is hosted on this server
        if not self.originator.record:
            raise ImplicitProcessorException("5.1;Service unavailable")

        # Locate the originator's copy of the event
        calendar_resource = (yield getCalendarObjectForRecord(self.txn, self.originator.record, self.uid))
        if calendar_resource is None:
            raise ImplicitProcessorException("5.1;Service unavailable")
        originator_calendar = (yield calendar_resource.componentForUser(self.originator.record.uid))

        # Get attendee's view of that
        originator_calendar.attendeesView((self.recipient.cuaddr,))

        # Locate the attendee's copy of the event if it exists.
        recipient_resource = (yield getCalendarObjectForRecord(self.txn, self.recipient.record, self.uid))

        # We only need to fix data that already exists
        if recipient_resource is not None:
            if originator_calendar.mainType() is not None:
                yield self.writeCalendarResource(None, recipient_resource, originator_calendar)
            else:
                yield self.deleteCalendarResource(recipient_resource)

        returnValue(True)
Ejemplo n.º 2
0
    def test_getCalendarObjectForRecord(self):
        """
        Test that L{txdav.caldav.datastore.scheduling.utils.getCalendarObjectForRecord} detects and removes
        resources with duplicate UIDs in the same calendar home.
        """

        # Check that expected resources are present
        txn = self.transactionUnderTest()
        for home_uid, calendar_name, resource_name in (
            ("user01", "calendar1", "1.ics",),
            ("user02", "calendar2", "2.ics",),
            ("user02", "calendar3", "3.ics",),
        ):
            resource = (yield self.calendarObjectUnderTest(txn, name=resource_name, calendar_name=calendar_name, home=home_uid))
            self.assertNotEqual(resource, None)
        yield self.commit()

        # Look up resource by UID in home where only one exists
        principal = buildDirectoryRecord("user01")
        txn = self.transactionUnderTest()
        resource = (yield getCalendarObjectForRecord(txn, principal, "685BC3A1-195A-49B3-926D-388DDACA78A6"))
        self.assertEqual(resource.name(), "1.ics")
        self.assertEqual(resource._parentCollection.name(), "calendar1")
        self.assertEqual(resource._parentCollection.viewerHome().uid(), "user01")
        yield self.commit()

        # Check that expected resources are still present
        txn = self.transactionUnderTest()
        for home_uid, calendar_name, resource_name in (
            ("user01", "calendar1", "1.ics",),
            ("user02", "calendar2", "2.ics",),
            ("user02", "calendar3", "3.ics",),
        ):
            resource = (yield self.calendarObjectUnderTest(txn, name=resource_name, calendar_name=calendar_name, home=home_uid))
            self.assertNotEqual(resource, None)
        yield self.commit()

        # Look up resource by UID in home where two exists
        principal = buildDirectoryRecord("user02")
        txn = self.transactionUnderTest()
        resource = (yield getCalendarObjectForRecord(txn, principal, "685BC3A1-195A-49B3-926D-388DDACA78A6"))
        self.assertTrue(resource.name() in ("2.ics", "3.ics",))
        self.assertTrue(resource._parentCollection.name() in ("calendar2", "calendar3",))
        self.assertEqual(resource._parentCollection.viewerHome().uid(), "user02")
        yield self.commit()

        # Check that expected resources are still present, but the duplicate missing
        txn = self.transactionUnderTest()
        resource = (yield self.calendarObjectUnderTest(txn, name="1.ics", calendar_name="calendar1", home="user01"))
        self.assertNotEqual(resource, None)
        resource2 = (yield self.calendarObjectUnderTest(txn, name="2.ics", calendar_name="calendar2", home="user02"))
        resource3 = (yield self.calendarObjectUnderTest(txn, name="3.ics", calendar_name="calendar3", home="user02"))
        self.assertTrue((resource2 is not None) ^ (resource3 is not None))
        yield self.commit()
Ejemplo n.º 3
0
    def getRecipientsCopy(self):
        """
        Get the Recipient's copy of the event being processed.
        """

        self.recipient_calendar = None
        self.recipient_calendar_resource = None
        calendar_resource = (yield getCalendarObjectForRecord(self.txn, self.recipient.record, self.uid))
        if calendar_resource:
            self.recipient_calendar = (yield calendar_resource.componentForUser(self.recipient.record.uid))
            self.recipient_calendar_resource = calendar_resource
Ejemplo n.º 4
0
    def test_getCalendarObjectForRecord(self):
        """
        Test that L{txdav.caldav.datastore.scheduling.utils.getCalendarObjectForRecord} detects and removes
        resources with duplicate UIDs in the same calendar home.
        """

        # Check that expected resources are present
        txn = self.transactionUnderTest()
        for home_uid, calendar_name, resource_name in (
            (
                "user01",
                "calendar1",
                "1.ics",
            ),
            (
                "user02",
                "calendar2",
                "2.ics",
            ),
            (
                "user02",
                "calendar3",
                "3.ics",
            ),
        ):
            resource = (yield self.calendarObjectUnderTest(
                txn,
                name=resource_name,
                calendar_name=calendar_name,
                home=home_uid))
            self.assertNotEqual(resource, None)
        yield self.commit()

        # Look up resource by UID in home where only one exists
        principal = yield self.directory.recordWithUID(u"user01")
        txn = self.transactionUnderTest()
        resource = (yield getCalendarObjectForRecord(
            txn, principal, "685BC3A1-195A-49B3-926D-388DDACA78A6"))
        self.assertEqual(resource.name(), "1.ics")
        self.assertEqual(resource._parentCollection.name(), "calendar1")
        self.assertEqual(resource._parentCollection.viewerHome().uid(),
                         "user01")
        yield self.commit()

        # Check that expected resources are still present
        txn = self.transactionUnderTest()
        for home_uid, calendar_name, resource_name in (
            (
                "user01",
                "calendar1",
                "1.ics",
            ),
            (
                "user02",
                "calendar2",
                "2.ics",
            ),
            (
                "user02",
                "calendar3",
                "3.ics",
            ),
        ):
            resource = (yield self.calendarObjectUnderTest(
                txn,
                name=resource_name,
                calendar_name=calendar_name,
                home=home_uid))
            self.assertNotEqual(resource, None)
        yield self.commit()

        # Look up resource by UID in home where two exists
        principal = yield self.directory.recordWithUID("user02")
        txn = self.transactionUnderTest()
        resource = (yield getCalendarObjectForRecord(
            txn, principal, "685BC3A1-195A-49B3-926D-388DDACA78A6"))
        self.assertTrue(resource.name() in (
            "2.ics",
            "3.ics",
        ))
        self.assertTrue(resource._parentCollection.name() in (
            "calendar2",
            "calendar3",
        ))
        self.assertEqual(resource._parentCollection.viewerHome().uid(),
                         "user02")
        yield self.commit()

        # Check that expected resources are still present, but the duplicate missing
        txn = self.transactionUnderTest()
        resource = (yield
                    self.calendarObjectUnderTest(txn,
                                                 name="1.ics",
                                                 calendar_name="calendar1",
                                                 home="user01"))
        self.assertNotEqual(resource, None)
        resource2 = (yield
                     self.calendarObjectUnderTest(txn,
                                                  name="2.ics",
                                                  calendar_name="calendar2",
                                                  home="user02"))
        resource3 = (yield
                     self.calendarObjectUnderTest(txn,
                                                  name="3.ics",
                                                  calendar_name="calendar3",
                                                  home="user02"))
        self.assertTrue((resource2 is not None) ^ (resource3 is not None))
        yield self.commit()

        # Look up resource where principal exists but home does not
        principal = yield self.directory.recordWithUID(
            "user102")  # ASKCYRUS: but user102 doesn't exist
        txn = self.transactionUnderTest()
        resource = (yield getCalendarObjectForRecord(
            txn, principal, "685BC3A1-195A-49B3-926D-388DDACA78A6"))
        self.assertTrue(resource is None)
        yield self.commit()