Esempio n. 1
0
def moveCalendarTranspProperties(home):
    """
    Need to move all the CalDAV:schedule-calendar-transp properties in the
    RESOURCE_PROPERTY table to the new CALENDAR_BIND table columns, extracting
    the new value from the XML property.
    """

    # Iterate over each calendar (both owned and shared)
    calendars = (yield home.loadChildren())
    for calendar in calendars:
        if calendar.isInbox():
            prop = calendar.properties().get(
                PropertyName.fromElement(caldavxml.CalendarFreeBusySet))
            if prop is not None:
                del calendar.properties()[PropertyName.fromElement(
                    caldavxml.CalendarFreeBusySet)]
        prop = calendar.properties().get(
            PropertyName.fromElement(caldavxml.ScheduleCalendarTransp))
        if prop is not None:
            yield calendar.setUsedForFreeBusy(
                prop == caldavxml.ScheduleCalendarTransp(caldavxml.Opaque()))
            del calendar.properties()[PropertyName.fromElement(
                caldavxml.ScheduleCalendarTransp)]
Esempio n. 2
0
    def test_CalendarTranspProperty(self):

        request = self.oneRequest("/calendars/users/wsanchez/calendar/")

        # Get calendar first
        calendar = (
            yield
            request.locateResource("/calendars/users/wsanchez/calendar/"))
        if calendar is None:
            self.fail("Incorrect response to GET on existent calendar.")

        inbox = (yield
                 request.locateResource("/calendars/users/wsanchez/inbox/"))
        if inbox is None:
            self.fail("Incorrect response to GET on existent inbox.")

        # Provisioned calendar has default opaque property
        transp = (yield calendar.hasProperty(caldavxml.ScheduleCalendarTransp,
                                             request))
        self.assertTrue(transp)

        transp = (yield calendar.readProperty(caldavxml.ScheduleCalendarTransp,
                                              request))
        self.assertEqual(transp,
                         caldavxml.ScheduleCalendarTransp(caldavxml.Opaque()))

        # Inbox property lists the default calendar
        fbset = (yield inbox.hasProperty(caldavxml.CalendarFreeBusySet,
                                         request))
        self.assertTrue(fbset)

        fbset = (yield inbox.readProperty(caldavxml.CalendarFreeBusySet,
                                          request))
        self.assertEqual(
            fbset,
            caldavxml.CalendarFreeBusySet(
                davxml.HRef.fromString(
                    "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/calendar/"
                ), ))

        # Now remove the property to simulate the old calendar server state with
        # a calendar listed in the fbset
        yield calendar._newStoreObject.setUsedForFreeBusy(False)
        fbset = (yield inbox.readProperty(caldavxml.CalendarFreeBusySet,
                                          request))
        self.assertEqual(fbset, caldavxml.CalendarFreeBusySet())

        # Calendar has opaque property derived from inbox
        transp = (yield calendar.hasProperty(caldavxml.ScheduleCalendarTransp,
                                             request))
        self.assertTrue(transp)

        transp = (yield calendar.readProperty(caldavxml.ScheduleCalendarTransp,
                                              request))
        self.assertEqual(
            transp, caldavxml.ScheduleCalendarTransp(caldavxml.Transparent()))

        # Force trailing slash on fbset
        yield inbox.writeProperty(
            caldavxml.CalendarFreeBusySet(
                davxml.HRef.fromString(
                    "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/calendar/"
                ), ), request)

        # Now remove the dead property to simulate the old calendar server state with
        # a calendar listed in the fbset
        fbset = (yield inbox.readProperty(caldavxml.CalendarFreeBusySet,
                                          request))
        self.assertEqual(
            fbset,
            caldavxml.CalendarFreeBusySet(
                davxml.HRef.fromString(
                    "/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/calendar/"
                ), ))

        # Calendar has opaque property derived from inbox
        transp = (yield calendar.hasProperty(caldavxml.ScheduleCalendarTransp,
                                             request))
        self.assertTrue(transp)

        transp = (yield calendar.readProperty(caldavxml.ScheduleCalendarTransp,
                                              request))
        self.assertEqual(transp,
                         caldavxml.ScheduleCalendarTransp(caldavxml.Opaque()))