Пример #1
0
def prop_dav_addressbook_home_set(dav, request, resource):
    current_user_principal = getattr(
        settings, 'DAVVY_ADDRESSBOOK_HOME_SET_BASE', None)
    if current_user_principal is not None:
        if isinstance(current_user_principal, list) or isinstance(current_user_principal, tuple):
            for base in current_user_principal:
                yield davvy.xml_node('{DAV:}href', base.rstrip('/') + '/' + request.user.username)
        else:
            yield davvy.xml_node('{DAV:}href', current_user_principal.rstrip('/') + '/' + request.user.username)
Пример #2
0
def prop_dav_calendar_home_set(dav, request, resource):
    current_user_principal = getattr(settings, 'DAVVY_CALENDAR_HOME_SET_BASE',
                                     None)
    if current_user_principal is not None:
        if isinstance(current_user_principal, list) or isinstance(
                current_user_principal, tuple):
            for base in current_user_principal:
                yield davvy.xml_node(
                    '{DAV:}href',
                    base.rstrip('/') + '/' + request.user.username + '/')
        else:
            yield davvy.xml_node(
                '{DAV:}href',
                current_user_principal.rstrip('/') + '/' +
                request.user.username + '/')
Пример #3
0
def prop_dav_current_user_principal(dav, request, resource):
    current_user_principal = getattr(settings,
                                     'DAVVY_CURRENT_USER_PRINCIPAL_BASE', None)
    if current_user_principal is not None:
        if isinstance(current_user_principal, list) or isinstance(
                current_user_principal, tuple):
            for base in current_user_principal:
                yield davvy.xml_node(
                    '{DAV:}href',
                    base.rstrip('/') + '/' + request.user.username + '/')
        else:
            yield davvy.xml_node(
                '{DAV:}href',
                current_user_principal.rstrip('/') + '/' +
                request.user.username + '/')
Пример #4
0
def prop_dav_resourcetype(dav, request, resource):
    if resource.collection:
        # is it a subcollection ?
        if resource.parent and dav.subcollection_type is not None:
            if isinstance(dav.subcollection_type, list):
                rtypes = []
                for rtype in dav.subcollection_type:
                    rtypes.append(davvy.xml_node(rtype))
                return rtypes
            return davvy.xml_node(dav.subcollection_type)
        if isinstance(dav.collection_type, list):
            rtypes = []
            for rtype in dav.collection_type:
                rtypes.append(davvy.xml_node(rtype))
            return rtypes
        return davvy.xml_node(dav.collection_type)
    return ''
Пример #5
0
def prop_dav_resourcetype(dav, request, resource):
    if resource.collection:
        # is it a subcollection ?
        if resource.parent and dav.subcollection_type is not None:
            if isinstance(dav.subcollection_type, list):
                rtypes = []
                for rtype in dav.subcollection_type:
                    rtypes.append(davvy.xml_node(rtype))
                return rtypes
            return davvy.xml_node(dav.subcollection_type)
        if isinstance(dav.collection_type, list):
            rtypes = []
            for rtype in dav.collection_type:
                rtypes.append(davvy.xml_node(rtype))
            return rtypes
        return davvy.xml_node(dav.collection_type)
    return ''
Пример #6
0
def prop_dav_current_user_principal(dav, request, resource):
    current_user_principal = getattr(
        settings, 'DAVVY_CURRENT_USER_PRINCIPAL_BASE', None
    )
    if current_user_principal is not None:
        if isinstance(current_user_principal, list) or isinstance(current_user_principal, tuple):
            for base in current_user_principal:
                yield davvy.xml_node(
                    '{DAV:}href',
                    base.rstrip('/') + '/' + request.user.username + '/'
                )
        else:
            yield davvy.xml_node(
                '{DAV:}href',
                current_user_principal.rstrip(
                    '/') + '/' + request.user.username + '/'
            )
Пример #7
0
    def _multiget_response(self,
                           request,
                           resource,
                           href,
                           report_type='response'):
        try:
            scheme = request.scheme
        except:
            scheme = request.META['wsgi.url_scheme']
        multistatus_response = davvy.xml_node('{DAV:}' + report_type)
        # temp hack, we need to find a better solution
        if resource.collection:
            href = href.rstrip('/') + '/'
        multistatus_response_href = davvy.xml_node(
            '{DAV:}href', scheme + '://' + request.META['HTTP_HOST'] + href)
        multistatus_response.append(multistatus_response_href)
        # add properties
        multistatus_response_propstat = davvy.xml_node('{DAV:}propstat')
        multistatus_response_propstat_prop = davvy.xml_node('{DAV:}prop')
        multistatus_response_propstat.append(
            multistatus_response_propstat_prop)
        if not resource.collection:
            multistatus_response_propstat_prop_calendar_data = davvy.xml_node(
                '{urn:ietf:params:xml:ns:caldav}calendar-data',
                ''.join(self.storage.retrieve(self, request, resource)))
            multistatus_response_propstat_prop.append(
                multistatus_response_propstat_prop_calendar_data)
            multistatus_response_propstat_prop_get_contenttype = davvy.xml_node(
                '{DAV:}getcontenttype', resource.content_type)
            multistatus_response_propstat_prop.append(
                multistatus_response_propstat_prop_get_contenttype)
            # contenttype
            multistatus_response_propstat_prop_getetag = davvy.xml_node(
                '{DAV:}getetag', str(resource.updated_at.strftime('%s')))
            multistatus_response_propstat_prop.append(
                multistatus_response_propstat_prop_getetag)
        else:
            multistatus_response_propstat_prop_get_contenttype = davvy.xml_node(
                '{DAV:}getcontenttype', 'httpd/unix-directory')
            multistatus_response_propstat_prop.append(
                multistatus_response_propstat_prop_get_contenttype)

        # add status
        multistatus_response_propstat_status = davvy.xml_node(
            '{DAV:}status', request.META['SERVER_PROTOCOL'] + ' 200 OK')
        multistatus_response_propstat.append(
            multistatus_response_propstat_status)

        multistatus_response.append(multistatus_response_propstat)

        return multistatus_response
Пример #8
0
    def _multiget_response(self, request, resource, href, report_type='response'):
        try:
            scheme = request.scheme
        except:
            scheme = request.META['wsgi.url_scheme']
        multistatus_response = davvy.xml_node('{DAV:}' + report_type)
        # temp hack, we need to find a better solution
        if resource.collection:
            href = href.rstrip('/') + '/'
        multistatus_response_href = davvy.xml_node(
            '{DAV:}href', scheme + '://' + request.META['HTTP_HOST'] + href
        )
        multistatus_response.append(multistatus_response_href)
        # add properties
        multistatus_response_propstat = davvy.xml_node('{DAV:}propstat')
        multistatus_response_propstat_prop = davvy.xml_node('{DAV:}prop')
        multistatus_response_propstat.append(
            multistatus_response_propstat_prop)
        if not resource.collection:
            multistatus_response_propstat_prop_calendar_data = davvy.xml_node(
                '{urn:ietf:params:xml:ns:caldav}calendar-data', ''.join(self.storage.retrieve(self, request, resource)))
            multistatus_response_propstat_prop.append(
                multistatus_response_propstat_prop_calendar_data)
            multistatus_response_propstat_prop_get_contenttype = davvy.xml_node(
                '{DAV:}getcontenttype', resource.content_type)
            multistatus_response_propstat_prop.append(
                multistatus_response_propstat_prop_get_contenttype)
            # contenttype
            multistatus_response_propstat_prop_getetag = davvy.xml_node(
                '{DAV:}getetag', str(resource.updated_at.strftime('%s')))
            multistatus_response_propstat_prop.append(
                multistatus_response_propstat_prop_getetag)
        else:
            multistatus_response_propstat_prop_get_contenttype = davvy.xml_node(
                '{DAV:}getcontenttype', 'httpd/unix-directory')
            multistatus_response_propstat_prop.append(
                multistatus_response_propstat_prop_get_contenttype)

        # add status
        multistatus_response_propstat_status = davvy.xml_node(
            '{DAV:}status', request.META['SERVER_PROTOCOL'] + ' 200 OK')
        multistatus_response_propstat.append(
            multistatus_response_propstat_status)

        multistatus_response.append(multistatus_response_propstat)

        return multistatus_response
Пример #9
0
    def report(self, request, user, resource_name):
        resource = self.get_resource(request, user, resource_name)

        try:
            dom = etree.fromstring(request.read())
        except:
            raise davvy.exceptions.BadRequest()

        # print etree.tostring(dom, pretty_print=True)

        doc = etree.Element('{DAV:}multistatus')

        if dom.tag == '{urn:ietf:params:xml:ns:caldav}calendar-query':
            doc.append(self._multiget_response(request, resource,
                                               request.path))
            for child in resource.resource_set.all():
                doc.append(
                    self._multiget_response(
                        request, child,
                        request.path.rstrip('/') + '/' + child.name))
        elif dom.tag == '{DAV:}sync-collection':
            doc.append(
                self._multiget_response(request, resource, request.path,
                                        'sync-response'))
            for child in resource.resource_set.all():
                doc.append(
                    self._multiget_response(
                        request, child,
                        request.path.rstrip('/') + '/' + child.name,
                        'sync-response'))

            doc.append(
                davvy.xml_node(
                    '{DAV:}sync-token',
                    prop_dav_calendar_getctag(self, request, resource)))
        elif dom.tag == '{urn:ietf:params:xml:ns:caldav}calendar-multiget':
            hrefs = dom.iterfind('{DAV:}href')
            for href in hrefs:
                child = self.get_resource(
                    request, user, self.get_href(href.text, resource_name))
                doc.append(self._multiget_response(request, child, href.text))
        else:
            raise davvy.exceptions.BadRequest()

        # print etree.tostring(doc, pretty_print=True)

        response = HttpResponse(etree.tostring(doc, pretty_print=True),
                                content_type='text/xml; charset=utf-8')
        response.status_code = 207
        response.reason_phrase = 'Multi-Status'
        return response
Пример #10
0
def prop_dav_current_user_privilege_set(dav, request, resource):
    write = davvy.xml_node('{DAV:}privilege')
    write.append(davvy.xml_node('{DAV:}all'))
    write.append(davvy.xml_node('{DAV:}read'))
    write.append(davvy.xml_node('{DAV:}write'))
    write.append(davvy.xml_node('{DAV:}write-properties'))
    write.append(davvy.xml_node('{DAV:}write-content'))
    return write
Пример #11
0
def prop_dav_current_user_privilege_set(dav, request, resource):
    write = davvy.xml_node('{DAV:}privilege')
    write.append(davvy.xml_node('{DAV:}all'))
    write.append(davvy.xml_node('{DAV:}read'))
    write.append(davvy.xml_node('{DAV:}write'))
    write.append(davvy.xml_node('{DAV:}write-properties'))
    write.append(davvy.xml_node('{DAV:}write-content'))
    return write
Пример #12
0
    def report(self, request, user, resource_name):
        resource = self.get_resource(request, user, resource_name)

        try:
            dom = etree.fromstring(request.read())
        except:
            raise davvy.exceptions.BadRequest()

        # print etree.tostring(dom, pretty_print=True)

        doc = etree.Element('{DAV:}multistatus')

        if dom.tag == '{urn:ietf:params:xml:ns:caldav}calendar-query':
            doc.append(
                self._multiget_response(request, resource, request.path))
            for child in resource.resource_set.all():
                doc.append(self._multiget_response(
                    request, child, request.path.rstrip('/') + '/' + child.name))
        elif dom.tag == '{DAV:}sync-collection':
            doc.append(self._multiget_response(
                request, resource, request.path, 'sync-response'))
            for child in resource.resource_set.all():
                doc.append(self._multiget_response(
                    request, child, request.path.rstrip('/') + '/' + child.name, 'sync-response')
                )

            doc.append(davvy.xml_node(
                '{DAV:}sync-token', prop_dav_calendar_getctag(self, request, resource))
            )
        elif dom.tag == '{urn:ietf:params:xml:ns:caldav}calendar-multiget':
            hrefs = dom.iterfind('{DAV:}href')
            for href in hrefs:
                child = self.get_resource(
                    request, user, self.get_href(href.text, resource_name))
                doc.append(self._multiget_response(request, child, href.text))
        else:
            raise davvy.exceptions.BadRequest()

        # print etree.tostring(doc, pretty_print=True)

        response = HttpResponse(
            etree.tostring(doc, pretty_print=True), content_type='text/xml; charset=utf-8')
        response.status_code = 207
        response.reason_phrase = 'Multi-Status'
        return response
Пример #13
0
    def _multiget_response(self, request, resource, href):
        try:
            scheme = request.scheme
        except:
            scheme = request.META['wsgi.url_scheme']
        # temp hack, we need to find a better solution
        multistatus_response = davvy.xml_node('{DAV:}response')
        multistatus_response_href = davvy.xml_node(
            '{DAV:}href', scheme + '://' + request.META['HTTP_HOST'] + href)
        multistatus_response.append(multistatus_response_href)
        # add properties
        multistatus_response_propstat = davvy.xml_node('{DAV:}propstat')
        multistatus_response_propstat_prop = davvy.xml_node('{DAV:}prop')
        multistatus_response_propstat.append(
            multistatus_response_propstat_prop)

        multistatus_response_propstat_prop_address_data = davvy.xml_node(
            '{urn:ietf:params:xml:ns:carddav}address-data',
            ''.join(self.storage.retrieve(self, request, resource)))
        multistatus_response_propstat_prop.append(
            multistatus_response_propstat_prop_address_data)
        # contenttype
        multistatus_response_propstat_prop_get_contenttype = davvy.xml_node(
            '{DAV:}getcontenttype', resource.content_type)
        multistatus_response_propstat_prop.append(
            multistatus_response_propstat_prop_get_contenttype)

        # contenttype
        multistatus_response_propstat_prop_getetag = davvy.xml_node(
            '{DAV:}getetag', str(resource.updated_at.strftime('%s')))
        multistatus_response_propstat_prop.append(
            multistatus_response_propstat_prop_getetag)

        # add status
        multistatus_response_propstat_status = davvy.xml_node(
            '{DAV:}status', request.META['SERVER_PROTOCOL'] + ' 200 OK')
        multistatus_response_propstat.append(
            multistatus_response_propstat_status)

        multistatus_response.append(multistatus_response_propstat)

        return multistatus_response
Пример #14
0
    def _multiget_response(self, request, resource, href):
        try:
            scheme = request.scheme
        except:
            scheme = request.META['wsgi.url_scheme']
        # temp hack, we need to find a better solution
        multistatus_response = davvy.xml_node('{DAV:}response')
        multistatus_response_href = davvy.xml_node(
            '{DAV:}href', scheme + '://' + request.META['HTTP_HOST'] + href)
        multistatus_response.append(multistatus_response_href)
        # add properties
        multistatus_response_propstat = davvy.xml_node('{DAV:}propstat')
        multistatus_response_propstat_prop = davvy.xml_node('{DAV:}prop')
        multistatus_response_propstat.append(
            multistatus_response_propstat_prop)

        multistatus_response_propstat_prop_address_data = davvy.xml_node(
            '{urn:ietf:params:xml:ns:carddav}address-data', ''.join(self.storage.retrieve(self, request, resource)))
        multistatus_response_propstat_prop.append(
            multistatus_response_propstat_prop_address_data)
        # contenttype
        multistatus_response_propstat_prop_get_contenttype = davvy.xml_node(
            '{DAV:}getcontenttype', resource.content_type)
        multistatus_response_propstat_prop.append(
            multistatus_response_propstat_prop_get_contenttype)

        # contenttype
        multistatus_response_propstat_prop_getetag = davvy.xml_node(
            '{DAV:}getetag', str(resource.updated_at.strftime('%s')))
        multistatus_response_propstat_prop.append(
            multistatus_response_propstat_prop_getetag)

        # add status
        multistatus_response_propstat_status = davvy.xml_node(
            '{DAV:}status', request.META['SERVER_PROTOCOL'] + ' 200 OK')
        multistatus_response_propstat.append(
            multistatus_response_propstat_status)

        multistatus_response.append(multistatus_response_propstat)

        return multistatus_response
Пример #15
0
def prop_dav_acl(dav, request, resource):
    ace = davvy.xml_node('{DAV:}ace')
    ace_principal = davvy.xml_node('{DAV:}principal')
    ace_principal.append(davvy.xml_node('{DAV:}all'))
    #principals = prop_dav_current_user_principal(dav, request, resource)
    # for principal in principals:
    #    ace_principal.append(principal)
    ace.append(ace_principal)
    grant = davvy.xml_node('{DAV:}grant')
    privilege = davvy.xml_node('{DAV:}privilege')
    privilege.append(davvy.xml_node('{DAV:}write'))
    grant.append(privilege)
    ace.append(grant)
    return ace
Пример #16
0
def prop_dav_acl(dav, request, resource):
    ace = davvy.xml_node('{DAV:}ace')
    ace_principal = davvy.xml_node('{DAV:}principal')
    ace_principal.append(davvy.xml_node('{DAV:}all'))
    #principals = prop_dav_current_user_principal(dav, request, resource)
    # for principal in principals:
    #    ace_principal.append(principal)
    ace.append(ace_principal)
    grant = davvy.xml_node('{DAV:}grant')
    privilege = davvy.xml_node('{DAV:}privilege')
    privilege.append(davvy.xml_node('{DAV:}write'))
    grant.append(privilege)
    ace.append(grant)
    return ace
Пример #17
0
def prop_dav_supported_report_set(dav, request, resource):
    supported_reports = []

    supported_report = davvy.xml_node('{DAV:}supported-report')
    report = davvy.xml_node('{DAV:}report')
    supported_report.append(report)
    addressbook_multiget = davvy.xml_node(
        '{urn:ietf:params:xml:ns:carddav}addressbook-multiget')
    report.append(addressbook_multiget)
    supported_reports.append(supported_report)

    supported_report = davvy.xml_node('{DAV:}supported-report')
    report = davvy.xml_node('{DAV:}report')
    supported_report.append(report)
    addressbook_query = davvy.xml_node(
        '{urn:ietf:params:xml:ns:carddav}addressbook-query')
    report.append(addressbook_query)
    supported_reports.append(supported_report)

    supported_report = davvy.xml_node('{DAV:}supported-report')
    report = davvy.xml_node('{DAV:}report')
    supported_report.append(report)
    calendar_query = davvy.xml_node(
        '{urn:ietf:params:xml:ns:caldav}calendar-query')
    report.append(calendar_query)
    supported_reports.append(supported_report)

    supported_report = davvy.xml_node('{DAV:}supported-report')
    report = davvy.xml_node('{DAV:}report')
    supported_report.append(report)
    calendar_multiget = davvy.xml_node(
        '{urn:ietf:params:xml:ns:caldav}calendar-multiget')
    report.append(calendar_multiget)
    supported_reports.append(supported_report)

    supported_report = davvy.xml_node('{DAV:}supported-report')
    report = davvy.xml_node('{DAV:}report')
    supported_report.append(report)
    sync_collection = davvy.xml_node('{DAV:}sync-collection')
    report.append(sync_collection)
    supported_reports.append(supported_report)

    return supported_reports
Пример #18
0
def prop_dav_calendar_user_address_set(dav, request, resource):
    yield davvy.xml_node('{DAV:}href', 'mailto:' + request.user.email)
Пример #19
0
def prop_dav_supported_report_set(dav, request, resource):
    supported_reports = []

    supported_report = davvy.xml_node('{DAV:}supported-report')
    report = davvy.xml_node('{DAV:}report')
    supported_report.append(report)
    addressbook_multiget = davvy.xml_node(
        '{urn:ietf:params:xml:ns:carddav}addressbook-multiget')
    report.append(addressbook_multiget)
    supported_reports.append(supported_report)

    supported_report = davvy.xml_node('{DAV:}supported-report')
    report = davvy.xml_node('{DAV:}report')
    supported_report.append(report)
    addressbook_query = davvy.xml_node(
        '{urn:ietf:params:xml:ns:carddav}addressbook-query')
    report.append(addressbook_query)
    supported_reports.append(supported_report)

    supported_report = davvy.xml_node('{DAV:}supported-report')
    report = davvy.xml_node('{DAV:}report')
    supported_report.append(report)
    calendar_query = davvy.xml_node(
        '{urn:ietf:params:xml:ns:caldav}calendar-query')
    report.append(calendar_query)
    supported_reports.append(supported_report)

    supported_report = davvy.xml_node('{DAV:}supported-report')
    report = davvy.xml_node('{DAV:}report')
    supported_report.append(report)
    calendar_multiget = davvy.xml_node(
        '{urn:ietf:params:xml:ns:caldav}calendar-multiget')
    report.append(calendar_multiget)
    supported_reports.append(supported_report)

    supported_report = davvy.xml_node('{DAV:}supported-report')
    report = davvy.xml_node('{DAV:}report')
    supported_report.append(report)
    sync_collection = davvy.xml_node('{DAV:}sync-collection')
    report.append(sync_collection)
    supported_reports.append(supported_report)

    return supported_reports
Пример #20
0
def prop_dav_calendar_user_address_set(dav, request, resource):
    yield davvy.xml_node('{DAV:}href', 'mailto:' + request.user.email)