Exemplo n.º 1
0
    def http_POST(self, request):
        """
        The CalDAV POST method.

        This uses a generator function yielding either L{waitForDeferred} objects or L{Response} objects.
        This allows for code that follows a 'linear' execution pattern rather than having to use nested
        L{Deferred} callbacks. The logic is easier to follow this way plus we don't run into deep nesting
        issues which the other approach would have with large numbers of recipients.
        """
        # Check authentication and access controls
        yield self.authorize(request, (caldavxml.ScheduleSend(),))

        calendar = (yield self.loadCalendarFromRequest(request))
        originator = (yield self.loadOriginatorFromRequestDetails(request))
        recipients = self.loadRecipientsFromCalendarData(calendar)

        # storeComponent needs to know who the auth'd user is for access control
        # TODO: this needs to be done in a better way - ideally when the txn is created for the request,
        # we should set a txn.authzid attribute.
        authz = None
        authz_principal = self.parent.currentPrincipal(request).children[0]
        if isinstance(authz_principal, davxml.HRef):
            principalURL = str(authz_principal)
            if principalURL:
                authz = (yield request.locateResource(principalURL))
                self._associatedTransaction._authz_uid = authz.record.guid

        # This is a local CALDAV scheduling operation.
        scheduler = CalDAVScheduler(self._associatedTransaction, self.parent._newStoreHome.uid())

        # Do the POST processing treating
        result = (yield scheduler.doSchedulingViaPOST(originator, recipients, calendar))
        returnValue(result.response())
Exemplo n.º 2
0
    def http_POST(self, request):
        """
        The CalDAV POST method.

        This uses a generator function yielding either L{waitForDeferred} objects or L{Response} objects.
        This allows for code that follows a 'linear' execution pattern rather than having to use nested
        L{Deferred} callbacks. The logic is easier to follow this way plus we don't run into deep nesting
        issues which the other approach would have with large numbers of recipients.
        """
        # Check authentication and access controls
        yield self.authorize(request, (caldavxml.ScheduleSend(), ))

        calendar, format = (yield self.loadCalendarFromRequest(request))
        originator = (yield self.loadOriginatorFromRequestDetails(request))
        recipients = self.loadRecipientsFromCalendarData(calendar)

        # Log extended item
        if not hasattr(request, "extendedLogItems"):
            request.extendedLogItems = {}

        # This is a local CALDAV scheduling operation.
        scheduler = CalDAVScheduler(self._associatedTransaction,
                                    self.parent._newStoreHome.uid(),
                                    logItems=request.extendedLogItems)

        # Do the POST processing treating
        result = (yield scheduler.doSchedulingViaPOST(originator, recipients,
                                                      calendar))
        returnValue(result.response(format=format))
Exemplo n.º 3
0
    def http_POST(self, request):
        """
        The CalDAV POST method.

        This uses a generator function yielding either L{waitForDeferred} objects or L{Response} objects.
        This allows for code that follows a 'linear' execution pattern rather than having to use nested
        L{Deferred} callbacks. The logic is easier to follow this way plus we don't run into deep nesting
        issues which the other approach would have with large numbers of recipients.
        """
        # Check authentication and access controls
        yield self.authorize(request, (caldavxml.ScheduleSend(),))

        calendar, format = (yield self.loadCalendarFromRequest(request))
        originator = (yield self.loadOriginatorFromRequestDetails(request))
        recipients = self.loadRecipientsFromCalendarData(calendar)

        # Log extended item
        if not hasattr(request, "extendedLogItems"):
            request.extendedLogItems = {}

        # This is a local CALDAV scheduling operation.
        scheduler = CalDAVScheduler(self._associatedTransaction, self.parent._newStoreHome.uid(), logItems=request.extendedLogItems)

        # Do the POST processing treating
        result = (yield scheduler.doSchedulingViaPOST(originator, recipients, calendar))
        returnValue(result.response(format=format))
Exemplo n.º 4
0
    def test_one_event_event_details(self):
        """
        Test when the calendar is empty.
        """

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:1234-5678
DTSTAMP:20080601T000000Z
DTSTART:%s
DTEND:%s
END:VEVENT
END:VCALENDAR
""" % (self.now_12H.getText(), self.now_13H.getText(),)

        yield self._createCalendarObject(data, "user01", "test.ics")

        data_request = """BEGIN:VCALENDAR
VERSION:2.0
METHOD:REQUEST
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VFREEBUSY
UID:1234-5678
DTSTAMP:20080601T000000Z
DTSTART:%s
DTEND:%s
ORGANIZER:mailto:[email protected]
ATTENDEE:mailto:[email protected]
X-CALENDARSERVER-EXTENDED-FREEBUSY:T
END:VFREEBUSY
END:VCALENDAR
""" % (self.now.getText(), self.now_1D.getText(),)

        data_reply = """BEGIN:VCALENDAR
VERSION:2.0
METHOD:REPLY
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
DTSTART:%(now_12H)s
DTEND:%(now_13H)s
END:VEVENT
BEGIN:VFREEBUSY
DTSTART:%(now)s
DTEND:%(now_1D)s
ATTENDEE:mailto:[email protected]
FREEBUSY;FBTYPE=BUSY:%(now_12H)s/PT1H
ORGANIZER:mailto:[email protected]
END:VFREEBUSY
END:VCALENDAR
""" % {"now": self.now.getText(), "now_1D": self.now_1D.getText(), "now_12H": self.now_12H.getText(), "now_13H": self.now_13H.getText(), }

        scheduler = CalDAVScheduler(self.transactionUnderTest(), "user01")
        result = (yield scheduler.doSchedulingViaPOST("mailto:[email protected]", ["mailto:[email protected]", ], Component.fromString(data_request)))
        self.assertEqual(len(result.responses), 1)
        self.assertEqual(str(result.responses[0].recipient.children[0]), "mailto:[email protected]")
        self.assertTrue(str(result.responses[0].reqstatus).startswith("2"))
        self.assertEqual(normalizeiCalendarText(str(result.responses[0].calendar)), data_reply.replace("\n", "\r\n"))
Exemplo n.º 5
0
    def test_one_event_event_details(self):
        """
        Test when the calendar is empty.
        """

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:1234-5678
DTSTAMP:20080601T000000Z
DTSTART:%s
DTEND:%s
END:VEVENT
END:VCALENDAR
""" % (self.now_12H.getText(), self.now_13H.getText(),)

        yield self._createCalendarObject(data, "user01", "test.ics")

        data_request = """BEGIN:VCALENDAR
VERSION:2.0
METHOD:REQUEST
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VFREEBUSY
UID:1234-5678
DTSTAMP:20080601T000000Z
DTSTART:%s
DTEND:%s
ORGANIZER:mailto:[email protected]
ATTENDEE:mailto:[email protected]
X-CALENDARSERVER-EXTENDED-FREEBUSY:T
END:VFREEBUSY
END:VCALENDAR
""" % (self.now.getText(), self.now_1D.getText(),)

        data_reply = """BEGIN:VCALENDAR
VERSION:2.0
METHOD:REPLY
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
DTSTART:%(now_12H)s
DTEND:%(now_13H)s
END:VEVENT
BEGIN:VFREEBUSY
DTSTART:%(now)s
DTEND:%(now_1D)s
ATTENDEE:mailto:[email protected]
FREEBUSY;FBTYPE=BUSY:%(now_12H)s/PT1H
ORGANIZER:mailto:[email protected]
END:VFREEBUSY
END:VCALENDAR
""" % {"now": self.now.getText(), "now_1D": self.now_1D.getText(), "now_12H": self.now_12H.getText(), "now_13H": self.now_13H.getText(), }

        scheduler = CalDAVScheduler(self.transactionUnderTest(), "user01")
        result = (yield scheduler.doSchedulingViaPOST("mailto:[email protected]", ["mailto:[email protected]", ], Component.fromString(data_request)))
        self.assertEqual(len(result.responses), 1)
        self.assertEqual(str(result.responses[0].recipient.children[0]), "mailto:[email protected]")
        self.assertTrue(str(result.responses[0].reqstatus).startswith("2"))
        self.assertEqual(normalizeiCalendarText(str(result.responses[0].calendar)), data_reply.replace("\n", "\r\n"))
Exemplo n.º 6
0
    def sendToOrganizer(self, home, itipmsg, originator, recipient):

        # Send scheduling message

        # This is a local CALDAV scheduling operation.
        from txdav.caldav.datastore.scheduling.caldav.scheduler import CalDAVScheduler
        scheduler = CalDAVScheduler(self.transaction, home.uid())

        # Do the PUT processing
        log.info("Implicit REPLY - attendee: '{att}' to organizer: '{org}', UID: '{uid}'", att=originator, org=recipient, uid=itipmsg.resourceUID())
        response = (yield scheduler.doSchedulingViaPUT(originator, (recipient,), itipmsg, internal_request=True))
        returnValue(response)
Exemplo n.º 7
0
    def sendToOrganizer(self, home, itipmsg, originator, recipient):

        # Send scheduling message

        # This is a local CALDAV scheduling operation.
        from txdav.caldav.datastore.scheduling.caldav.scheduler import CalDAVScheduler
        scheduler = CalDAVScheduler(self.transaction, home.uid())

        # Do the PUT processing
        log.info("Implicit REPLY - attendee: '%s' to organizer: '%s', UID: '%s'" % (originator, recipient, itipmsg.resourceUID(),))
        response = (yield scheduler.doSchedulingViaPUT(originator, (recipient,), itipmsg, internal_request=True))
        returnValue(response)
Exemplo n.º 8
0
    def test_no_events(self):
        """
        Test when the calendar is empty.
        """

        data_request = """BEGIN:VCALENDAR
VERSION:2.0
METHOD:REQUEST
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VFREEBUSY
UID:1234-5678
DTSTAMP:20080601T000000Z
DTSTART:%s
DTEND:%s
ORGANIZER:mailto:[email protected]
ATTENDEE:mailto:[email protected]
END:VFREEBUSY
END:VCALENDAR
""" % (
            self.now.getText(),
            self.now_1D.getText(),
        )

        data_reply = """BEGIN:VCALENDAR
VERSION:2.0
METHOD:REPLY
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VFREEBUSY
DTSTART:%s
DTEND:%s
ATTENDEE:mailto:[email protected]
ORGANIZER:mailto:[email protected]
END:VFREEBUSY
END:VCALENDAR
""" % (
            self.now.getText(),
            self.now_1D.getText(),
        )

        scheduler = CalDAVScheduler(self.transactionUnderTest(), "user01")
        result = (yield scheduler.doSchedulingViaPOST(
            "mailto:[email protected]", [
                "mailto:[email protected]",
            ], Component.fromString(data_request)))
        self.assertEqual(len(result.responses), 1)
        self.assertEqual(str(result.responses[0].recipient.children[0]),
                         "mailto:[email protected]")
        self.assertTrue(str(result.responses[0].reqstatus).startswith("2"))
        self.assertEqual(
            normalizeiCalendarText(str(result.responses[0].calendar)),
            data_reply.replace("\n", "\r\n"))
Exemplo n.º 9
0
    def test_no_events(self):
        """
        Test when the calendar is empty.
        """

        data_request = """BEGIN:VCALENDAR
VERSION:2.0
METHOD:REQUEST
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VFREEBUSY
UID:1234-5678
DTSTAMP:20080601T000000Z
DTSTART:%s
DTEND:%s
ORGANIZER:mailto:[email protected]
ATTENDEE:mailto:[email protected]
END:VFREEBUSY
END:VCALENDAR
""" % (self.now.getText(), self.now_1D.getText(),)

        data_reply = """BEGIN:VCALENDAR
VERSION:2.0
METHOD:REPLY
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VFREEBUSY
DTSTART:%s
DTEND:%s
ATTENDEE:mailto:[email protected]
ORGANIZER:mailto:[email protected]
END:VFREEBUSY
END:VCALENDAR
""" % (self.now.getText(), self.now_1D.getText(),)

        scheduler = CalDAVScheduler(self.transactionUnderTest(), "user01")
        result = (yield scheduler.doSchedulingViaPOST("mailto:[email protected]", ["mailto:[email protected]", ], Component.fromString(data_request)))
        self.assertEqual(len(result.responses), 1)
        self.assertEqual(str(result.responses[0].children[0].children[0]), "mailto:[email protected]")
        self.assertTrue(str(result.responses[0].children[1]).startswith("2"))
        self.assertEqual(normalizeiCalendarText(str(result.responses[0].children[2].children[0])), data_reply.replace("\n", "\r\n"))
Exemplo n.º 10
0
 def makeScheduler(self, home):
     """
     Convenience method which we can override in unit tests to make testing easier.
     """
     from txdav.caldav.datastore.scheduling.caldav.scheduler import CalDAVScheduler
     return CalDAVScheduler(self.transaction, home.uid())