Addd hook capability
This commit is contained in:
@@ -41,7 +41,7 @@ import defusedxml.ElementTree as DefusedET
|
||||
import pkg_resources
|
||||
|
||||
from radicale import (auth, httputils, log, pathutils, rights, storage, web,
|
||||
xmlutils)
|
||||
xmlutils, hook)
|
||||
from radicale.app.delete import ApplicationDeleteMixin
|
||||
from radicale.app.get import ApplicationGetMixin
|
||||
from radicale.app.head import ApplicationHeadMixin
|
||||
@@ -82,6 +82,7 @@ class Application(
|
||||
self._rights = rights.load(configuration)
|
||||
self._web = web.load(configuration)
|
||||
self._encoding = configuration.get("encoding", "request")
|
||||
self._hook = hook.load(configuration)
|
||||
|
||||
def _headers_log(self, environ):
|
||||
"""Sanitize headers for logging."""
|
||||
|
||||
@@ -21,6 +21,7 @@ from http import client
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
from radicale import app, httputils, storage, xmlutils
|
||||
from radicale.hook.rabbitmq import QueueItem, QueueItemTypes
|
||||
|
||||
|
||||
def xml_delete(base_prefix, path, collection, href=None):
|
||||
@@ -64,8 +65,11 @@ class ApplicationDeleteMixin:
|
||||
return httputils.PRECONDITION_FAILED
|
||||
if isinstance(item, storage.BaseCollection):
|
||||
xml_answer = xml_delete(base_prefix, path, item)
|
||||
for item in item.get_all():
|
||||
self._hook.notify(QueueItem(QueueItemTypes.DELETE, item.uid))
|
||||
else:
|
||||
xml_answer = xml_delete(
|
||||
base_prefix, path, item.collection, item.href)
|
||||
self._hook.notify(QueueItem(QueueItemTypes.DELETE, item.uid))
|
||||
headers = {"Content-Type": "text/xml; charset=%s" % self._encoding}
|
||||
return client.OK, headers, self._write_xml_content(xml_answer)
|
||||
|
||||
@@ -29,6 +29,7 @@ from radicale import app, httputils
|
||||
from radicale import item as radicale_item
|
||||
from radicale import pathutils, rights, storage, xmlutils
|
||||
from radicale.log import logger
|
||||
from radicale.hook.rabbitmq import QueueItem, QueueItemTypes
|
||||
|
||||
MIMETYPE_TAGS = {value: key for key, value in xmlutils.MIMETYPES.items()}
|
||||
|
||||
@@ -193,6 +194,8 @@ class ApplicationPutMixin:
|
||||
try:
|
||||
etag = self._storage.create_collection(
|
||||
path, prepared_items, props).etag
|
||||
for item in prepared_items:
|
||||
self._hook.notify(QueueItem(QueueItemTypes.UPSERT, item.serialize()))
|
||||
except ValueError as e:
|
||||
logger.warning(
|
||||
"Bad PUT request on %r: %s", path, e, exc_info=True)
|
||||
@@ -208,6 +211,7 @@ class ApplicationPutMixin:
|
||||
href = posixpath.basename(pathutils.strip_path(path))
|
||||
try:
|
||||
etag = parent_item.upload(href, prepared_item).etag
|
||||
self._hook.notify(QueueItem(QueueItemTypes.UPSERT, prepared_item.serialize()))
|
||||
except ValueError as e:
|
||||
logger.warning(
|
||||
"Bad PUT request on %r: %s", path, e, exc_info=True)
|
||||
|
||||
Reference in New Issue
Block a user