예제 #1
0
    def test_vevent_some_props(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Test
TRIGGER;RELATED=START:-PT10M
END:VALARM
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        result = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:Test
TRIGGER;RELATED=START:-PT10M
END:VALARM
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        empty = CalendarData(
            CalendarComponent(CalendarComponent(AllComponents(),
                                                Property(name="UID", ),
                                                Property(name="DTSTART", ),
                                                Property(name="DTEND", ),
                                                name="VEVENT"),
                              AllProperties(),
                              name="VCALENDAR"))

        for item in (
                data,
                Component.fromString(data),
        ):
            self.assertEqual(str(CalendarDataFilter(empty).filter(item)),
                             result)
예제 #2
0
    def test_vcalendar_no_comp(self):

        data = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
X-WR-CALNAME:Help
BEGIN:VEVENT
UID:12345-67890
DTSTART:20080601T120000Z
DTEND:20080601T130000Z
ATTENDEE:mailto:[email protected]
ATTENDEE:mailto:[email protected]
ORGANIZER;CN=User 01:mailto:[email protected]
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n")

        result = """BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
X-WR-CALNAME:Help
END:VCALENDAR
""".replace("\n", "\r\n")

        empty = CalendarData(
            CalendarComponent(AllProperties(), name="VCALENDAR"))
        for item in (
                data,
                Component.fromString(data),
        ):
            self.assertEqual(str(CalendarDataFilter(empty).filter(item)),
                             result)
예제 #3
0
    def filter(self, ical):
        """
        Filter the supplied iCalendar object using the request information.

        @param ical: iCalendar object
        @type ical: L{Component} or C{str}

        @return: L{Component} for the filtered calendar data
        """

        if self.isowner or self.accessRestriction == Component.ACCESS_PUBLIC or not self.accessRestriction:
            # No need to filter for the owner or public event
            return ical

        elif self.accessRestriction == Component.ACCESS_PRIVATE:
            # We should never get here because ACCESS_PRIVATE is protected via an ACL
            raise HTTPError(
                StatusResponse(responsecode.FORBIDDEN, "Access Denied"))

        elif self.accessRestriction == Component.ACCESS_PUBLIC:
            return ical
        elif self.accessRestriction in (Component.ACCESS_CONFIDENTIAL,
                                        Component.ACCESS_RESTRICTED):
            # Create a CALDAV:calendar-data element with the appropriate iCalendar Component/Property
            # filter in place for the access restriction in use

            extra_access = ()
            if self.accessRestriction == Component.ACCESS_RESTRICTED:
                extra_access = (
                    Property(name="SUMMARY"),
                    Property(name="LOCATION"),
                )

            calendardata = CalendarData(
                CalendarComponent(

                    # VCALENDAR properties
                    Property(name="PRODID"),
                    Property(name="VERSION"),
                    Property(name="CALSCALE"),
                    Property(name=Component.ACCESS_PROPERTY),

                    # VEVENT
                    CalendarComponent(Property(name="UID"),
                                      Property(name="RECURRENCE-ID"),
                                      Property(name="SEQUENCE"),
                                      Property(name="DTSTAMP"),
                                      Property(name="STATUS"),
                                      Property(name="TRANSP"),
                                      Property(name="DTSTART"),
                                      Property(name="DTEND"),
                                      Property(name="DURATION"),
                                      Property(name="RRULE"),
                                      Property(name="RDATE"),
                                      Property(name="EXRULE"),
                                      Property(name="EXDATE"), *extra_access,
                                      **{"name": "VEVENT"}),

                    # VTODO
                    CalendarComponent(Property(name="UID"),
                                      Property(name="RECURRENCE-ID"),
                                      Property(name="SEQUENCE"),
                                      Property(name="DTSTAMP"),
                                      Property(name="STATUS"),
                                      Property(name="DTSTART"),
                                      Property(name="COMPLETED"),
                                      Property(name="DUE"),
                                      Property(name="DURATION"),
                                      Property(name="RRULE"),
                                      Property(name="RDATE"),
                                      Property(name="EXRULE"),
                                      Property(name="EXDATE"), *extra_access,
                                      **{"name": "VTODO"}),

                    # VJOURNAL
                    CalendarComponent(Property(name="UID"),
                                      Property(name="RECURRENCE-ID"),
                                      Property(name="SEQUENCE"),
                                      Property(name="DTSTAMP"),
                                      Property(name="STATUS"),
                                      Property(name="TRANSP"),
                                      Property(name="DTSTART"),
                                      Property(name="RRULE"),
                                      Property(name="RDATE"),
                                      Property(name="EXRULE"),
                                      Property(name="EXDATE"), *extra_access,
                                      **{"name": "VJOURNAL"}),

                    # VFREEBUSY
                    CalendarComponent(Property(name="UID"),
                                      Property(name="DTSTAMP"),
                                      Property(name="DTSTART"),
                                      Property(name="DTEND"),
                                      Property(name="DURATION"),
                                      Property(name="FREEBUSY"), *extra_access,
                                      **{"name": "VFREEBUSY"}),

                    # VTIMEZONE
                    CalendarComponent(
                        AllProperties(),
                        AllComponents(),
                        name="VTIMEZONE",
                    ),
                    name="VCALENDAR",
                ), )

            # Now "filter" the resource calendar data through the CALDAV:calendar-data element
            return CalendarDataFilter(calendardata).filter(ical)
        else:
            # Unknown access restriction
            raise HTTPError(
                StatusResponse(responsecode.FORBIDDEN, "Access Denied"))