Implementing caldav report

merge-requests/30/head
Bob Mottram 2022-02-23 12:19:27 +00:00
parent 03e44e87d1
commit 93d05bbdce
19 changed files with 132 additions and 33 deletions

View File

@ -979,6 +979,15 @@ class PubServer(BaseHTTPRequestHandler):
'This is nothing less ' +
'than an utter triumph')
def _201(self) -> None:
if self.server.translate:
ok_str = self.server.translate['Done']
self._http_return_code(201,
self.server.translate['Created'], ok_str)
else:
self._http_return_code(201, 'Created',
'Done')
def _207(self) -> None:
if self.server.translate:
multi_str = self.server.translate['Lots of things']
@ -16879,19 +16888,31 @@ class PubServer(BaseHTTPRequestHandler):
propfind_xml = propfind_bytes.decode('utf-8')
response_str = None
if endpoint_type == 'propfind':
response_str = dav_propfind_response(self.server.base_dir,
nickname, self.server.domain,
depth, propfind_xml)
response_str = \
dav_propfind_response(self.server.base_dir,
nickname, self.server.domain,
depth, propfind_xml)
elif endpoint_type == 'put':
response_str = dav_put_response(self.server.base_dir,
nickname, self.server.domain,
depth, propfind_xml,
self.server.http_prefix,
self.server.system_language)
response_str = \
dav_put_response(self.server.base_dir,
nickname, self.server.domain,
depth, propfind_xml,
self.server.http_prefix,
self.server.system_language)
elif endpoint_type == 'report':
response_str = dav_report_response(self.server.base_dir,
nickname, self.server.domain,
depth, propfind_xml)
curr_etag = None
if self.headers.get('ETag'):
curr_etag = self.headers['ETag']
elif self.headers.get('Etag'):
curr_etag = self.headers['Etag']
response_str = \
dav_report_response(self.server.base_dir,
nickname, self.server.domain,
depth, propfind_xml,
self.server.person_cache,
self.server.http_prefix,
curr_etag,
self.server.domain_full)
elif endpoint_type == 'delete':
response_str = \
dav_delete_response(self.server.base_dir,
@ -16903,7 +16924,9 @@ class PubServer(BaseHTTPRequestHandler):
if not response_str:
self._404()
return
if response_str != 'Ok':
if response_str == 'Not modified':
return self._304()
elif response_str != 'Ok':
message_xml = response_str.encode('utf-8')
message_xml_len = len(message_xml)
self._set_headers('application/xml; charset=utf-8',
@ -16912,7 +16935,10 @@ class PubServer(BaseHTTPRequestHandler):
self._write(message_xml)
if 'multistatus' in response_str:
return self._207()
self._200()
if endpoint_type == 'put':
self._201()
else:
self._200()
def do_PROPFIND(self):
self._dav_handler('propfind')

View File

@ -9,6 +9,7 @@ __module_group__ = "Core"
import os
from uuid import UUID
from hashlib import md5
from datetime import datetime
from datetime import timedelta
@ -971,7 +972,10 @@ def dav_put_response(base_dir: str, nickname: str, domain: str,
def dav_report_response(base_dir: str, nickname: str, domain: str,
depth: int, xml_str: str) -> str:
depth: int, xml_str: str,
person_cache: {}, http_prefix: str,
curr_etag: str,
domain_full: str) -> str:
"""Returns the response to caldav REPORT
"""
if '<c:calendar-query' not in xml_str or \
@ -979,8 +983,43 @@ def dav_report_response(base_dir: str, nickname: str, domain: str,
if '<c:calendar-multiget' not in xml_str or \
'</c:calendar-multiget>' not in xml_str:
return None
# TODO
return None
# today's calendar events
now = datetime.now()
ical_events = \
get_todays_events_icalendar(base_dir, nickname, domain,
now.year, now.month,
now.day, person_cache,
http_prefix)
if not ical_events:
return None
if 'VEVENT' not in ical_events:
return None
etag = md5(ical_events).hexdigest()
if etag == curr_etag:
return "Not modified"
events_href = \
http_prefix + '://' + domain_full + '/users/' + \
nickname + '/calendar?year=' + \
str(now.year) + '?month=' + str(now.month) + '?day=' + str(now.day)
response_str = \
'<d:multistatus xmlns:d="DAV:" ' + \
'xmlns:cs="http://calendarserver.org/ns/">\n' + \
' <d:response>\n' + \
' <d:href>' + events_href + '</d:href>\n' + \
' <d:propstat>\n' + \
' <d:prop>\n' + \
' <d:getetag>"' + etag + '"</d:getetag>\n' + \
' <c:calendar-data>' + ical_events + \
' </c:calendar-data>\n' + \
' </d:prop>\n' + \
' <d:status>HTTP/1.1 200 OK</d:status>\n' + \
' </d:propstat>\n' + \
' </d:response>\n' + \
' <d:response>\n' + \
'</d:multistatus>'
return response_str
def dav_delete_response(base_dir: str, nickname: str, domain: str,

View File

@ -508,5 +508,7 @@
"Leave a comment": "اترك تعليقا",
"View comments": "تعليقات عرض",
"Multi Status": "متعدد الحالات",
"Lots of things": "أشياء كثيرة"
"Lots of things": "أشياء كثيرة",
"Created": "مخلوق",
"It is done": "تم"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Deixa un comentari",
"View comments": "Veure comentaris",
"Multi Status": "Estat múltiple",
"Lots of things": "Moltes coses"
"Lots of things": "Moltes coses",
"Created": "Creat",
"It is done": "Esta fet"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Gadael sylw",
"View comments": "Gweld sylwadau",
"Multi Status": "Statws Aml",
"Lots of things": "Llawer o pethau"
"Lots of things": "Llawer o pethau",
"Created": "Wedi creu",
"It is done": "Mae'n cael ei wneud"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Hinterlasse einen Kommentar",
"View comments": "Kommentare ansehen",
"Multi Status": "Multi-Status",
"Lots of things": "Viele Dinge"
"Lots of things": "Viele Dinge",
"Created": "Erstellt",
"It is done": "Es ist vollbracht"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Leave a comment",
"View comments": "View comments",
"Multi Status": "Multi Status",
"Lots of things": "Lots of things"
"Lots of things": "Lots of things",
"Created": "Created",
"It is done": "It is done"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Deja un comentario",
"View comments": "Ver comentarios",
"Multi Status": "Estado múltiple",
"Lots of things": "Muchas cosas"
"Lots of things": "Muchas cosas",
"Created": "Creada",
"It is done": "Se hace"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Laissez un commentaire",
"View comments": "Voir les commentaires",
"Multi Status": "Statut multiple",
"Lots of things": "Beaucoup de choses"
"Lots of things": "Beaucoup de choses",
"Created": "Créé",
"It is done": "C'est fait"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Fág trácht",
"View comments": "Féach ar thuairimí",
"Multi Status": "Stádas Il",
"Lots of things": "A lán rudaí"
"Lots of things": "A lán rudaí",
"Created": "Cruthaithe",
"It is done": "Déantar é"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "एक टिप्पणी छोड़ें",
"View comments": "टिप्पणियाँ देखें",
"Multi Status": "बहु स्थिति",
"Lots of things": "बहुत सी बातें"
"Lots of things": "बहुत सी बातें",
"Created": "बनाया था",
"It is done": "हो गया है"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Lascia un commento",
"View comments": "Visualizza commenti",
"Multi Status": "Stato multiplo",
"Lots of things": "Un sacco di cose"
"Lots of things": "Un sacco di cose",
"Created": "Creata",
"It is done": "È fatta"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "コメントを残す",
"View comments": "コメントを見る",
"Multi Status": "マルチステータス",
"Lots of things": "多くの物"
"Lots of things": "多くの物",
"Created": "作成した",
"It is done": "されております"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Bihêle şîroveyek",
"View comments": "Binêre şîroveyan",
"Multi Status": "Multi Status",
"Lots of things": "Gelek tişt"
"Lots of things": "Gelek tişt",
"Created": "Afirandin",
"It is done": "Tê kirin"
}

View File

@ -504,5 +504,7 @@
"Leave a comment": "Leave a comment",
"View comments": "View comments",
"Multi Status": "Multi Status",
"Lots of things": "Lots of things"
"Lots of things": "Lots of things",
"Created": "Created",
"It is done": "It is done"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Deixe um comentário",
"View comments": "Ver comentários",
"Multi Status": "Vários status",
"Lots of things": "Muitas coisas"
"Lots of things": "Muitas coisas",
"Created": "Criada",
"It is done": "Está feito"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Оставить комментарий",
"View comments": "Посмотреть комментарии",
"Multi Status": "Мульти статус",
"Lots of things": "Много всего"
"Lots of things": "Много всего",
"Created": "Созданный",
"It is done": "Сделано"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "Acha maoni",
"View comments": "Tazama maoni",
"Multi Status": "Hali nyingi",
"Lots of things": "Mambo mengi"
"Lots of things": "Mambo mengi",
"Created": "Imeundwa",
"It is done": "Imefanyika"
}

View File

@ -508,5 +508,7 @@
"Leave a comment": "发表评论",
"View comments": "查看评论",
"Multi Status": "多状态",
"Lots of things": "很多事情"
"Lots of things": "很多事情",
"Created": "已创建",
"It is done": "完成了"
}