From 93d05bbdcef932f053fa94c5f0e15b84f76c6698 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 23 Feb 2022 12:19:27 +0000 Subject: [PATCH] Implementing caldav report --- daemon.py | 52 +++++++++++++++++++++++++++++++++----------- happening.py | 45 +++++++++++++++++++++++++++++++++++--- translations/ar.json | 4 +++- translations/ca.json | 4 +++- translations/cy.json | 4 +++- translations/de.json | 4 +++- translations/en.json | 4 +++- translations/es.json | 4 +++- translations/fr.json | 4 +++- translations/ga.json | 4 +++- translations/hi.json | 4 +++- translations/it.json | 4 +++- translations/ja.json | 4 +++- translations/ku.json | 4 +++- translations/oc.json | 4 +++- translations/pt.json | 4 +++- translations/ru.json | 4 +++- translations/sw.json | 4 +++- translations/zh.json | 4 +++- 19 files changed, 132 insertions(+), 33 deletions(-) diff --git a/daemon.py b/daemon.py index a80393251..ee114533b 100644 --- a/daemon.py +++ b/daemon.py @@ -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') diff --git a/happening.py b/happening.py index 28a2b0ab6..72e38c9c1 100644 --- a/happening.py +++ b/happening.py @@ -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 '' 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 = \ + '\n' + \ + ' \n' + \ + ' ' + events_href + '\n' + \ + ' \n' + \ + ' \n' + \ + ' "' + etag + '"\n' + \ + ' ' + ical_events + \ + ' \n' + \ + ' \n' + \ + ' HTTP/1.1 200 OK\n' + \ + ' \n' + \ + ' \n' + \ + ' \n' + \ + '' + + return response_str def dav_delete_response(base_dir: str, nickname: str, domain: str, diff --git a/translations/ar.json b/translations/ar.json index 5ab1eb100..bcdf3a467 100644 --- a/translations/ar.json +++ b/translations/ar.json @@ -508,5 +508,7 @@ "Leave a comment": "اترك تعليقا", "View comments": "تعليقات عرض", "Multi Status": "متعدد الحالات", - "Lots of things": "أشياء كثيرة" + "Lots of things": "أشياء كثيرة", + "Created": "مخلوق", + "It is done": "تم" } diff --git a/translations/ca.json b/translations/ca.json index af52432a4..e3964b71c 100644 --- a/translations/ca.json +++ b/translations/ca.json @@ -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" } diff --git a/translations/cy.json b/translations/cy.json index 9319a457a..8ff0a936f 100644 --- a/translations/cy.json +++ b/translations/cy.json @@ -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" } diff --git a/translations/de.json b/translations/de.json index cc777a8f0..0b0c61432 100644 --- a/translations/de.json +++ b/translations/de.json @@ -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" } diff --git a/translations/en.json b/translations/en.json index 4572a3c3c..85a17198b 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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" } diff --git a/translations/es.json b/translations/es.json index 2635360ff..741520778 100644 --- a/translations/es.json +++ b/translations/es.json @@ -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" } diff --git a/translations/fr.json b/translations/fr.json index c0a03dde5..69aba39dd 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -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" } diff --git a/translations/ga.json b/translations/ga.json index 27a56bad3..2798af038 100644 --- a/translations/ga.json +++ b/translations/ga.json @@ -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 é" } diff --git a/translations/hi.json b/translations/hi.json index 9f143ccfe..8313a7c4e 100644 --- a/translations/hi.json +++ b/translations/hi.json @@ -508,5 +508,7 @@ "Leave a comment": "एक टिप्पणी छोड़ें", "View comments": "टिप्पणियाँ देखें", "Multi Status": "बहु स्थिति", - "Lots of things": "बहुत सी बातें" + "Lots of things": "बहुत सी बातें", + "Created": "बनाया था", + "It is done": "हो गया है" } diff --git a/translations/it.json b/translations/it.json index 336b7ae31..eca3f2e6f 100644 --- a/translations/it.json +++ b/translations/it.json @@ -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" } diff --git a/translations/ja.json b/translations/ja.json index 8427d5014..f54f1cb2e 100644 --- a/translations/ja.json +++ b/translations/ja.json @@ -508,5 +508,7 @@ "Leave a comment": "コメントを残す", "View comments": "コメントを見る", "Multi Status": "マルチステータス", - "Lots of things": "多くの物" + "Lots of things": "多くの物", + "Created": "作成した", + "It is done": "されております" } diff --git a/translations/ku.json b/translations/ku.json index 2c63fd059..7fe1c233b 100644 --- a/translations/ku.json +++ b/translations/ku.json @@ -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" } diff --git a/translations/oc.json b/translations/oc.json index e53a095a6..85fac4385 100644 --- a/translations/oc.json +++ b/translations/oc.json @@ -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" } diff --git a/translations/pt.json b/translations/pt.json index 34f504d55..461bd87e5 100644 --- a/translations/pt.json +++ b/translations/pt.json @@ -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" } diff --git a/translations/ru.json b/translations/ru.json index d79c2701f..3f07d564f 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -508,5 +508,7 @@ "Leave a comment": "Оставить комментарий", "View comments": "Посмотреть комментарии", "Multi Status": "Мульти статус", - "Lots of things": "Много всего" + "Lots of things": "Много всего", + "Created": "Созданный", + "It is done": "Сделано" } diff --git a/translations/sw.json b/translations/sw.json index f76346f65..882a8b721 100644 --- a/translations/sw.json +++ b/translations/sw.json @@ -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" } diff --git a/translations/zh.json b/translations/zh.json index 39725c4ca..07947e30a 100644 --- a/translations/zh.json +++ b/translations/zh.json @@ -508,5 +508,7 @@ "Leave a comment": "发表评论", "View comments": "查看评论", "Multi Status": "多状态", - "Lots of things": "很多事情" + "Lots of things": "很多事情", + "Created": "已创建", + "It is done": "完成了" }