From bf5272e83d2d6ccb656a3f2546cfa57bda21a246 Mon Sep 17 00:00:00 2001 From: Tuna Celik Date: Mon, 17 Aug 2020 14:43:52 +0200 Subject: [PATCH] Improved notification message with user/calendar point as field --- radicale/app/delete.py | 2 ++ radicale/app/put.py | 2 ++ radicale/hook/__init__.py | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/radicale/app/delete.py b/radicale/app/delete.py index 5a989d28..a6fea029 100644 --- a/radicale/app/delete.py +++ b/radicale/app/delete.py @@ -69,6 +69,7 @@ class ApplicationDeleteMixin: hook_notification_item_list.append( HookNotificationItem( HookNotificationItemTypes.DELETE, + access.path, i.uid ) ) @@ -77,6 +78,7 @@ class ApplicationDeleteMixin: hook_notification_item_list.append( HookNotificationItem( HookNotificationItemTypes.DELETE, + access.path, item.uid ) ) diff --git a/radicale/app/put.py b/radicale/app/put.py index 650ce42e..c08387ce 100644 --- a/radicale/app/put.py +++ b/radicale/app/put.py @@ -197,6 +197,7 @@ class ApplicationPutMixin: for item in prepared_items: hook_notification_item = HookNotificationItem( HookNotificationItemTypes.UPSERT, + access.path, item.serialize() ) self._hook.notify(hook_notification_item) @@ -217,6 +218,7 @@ class ApplicationPutMixin: etag = parent_item.upload(href, prepared_item).etag hook_notification_item = HookNotificationItem( HookNotificationItemTypes.UPSERT, + access.path, prepared_item.serialize() ) self._hook.notify(hook_notification_item) diff --git a/radicale/hook/__init__.py b/radicale/hook/__init__.py index 98562bcb..0fc09b42 100644 --- a/radicale/hook/__init__.py +++ b/radicale/hook/__init__.py @@ -1,7 +1,7 @@ import json from enum import Enum -from radicale import utils +from radicale import pathutils, utils INTERNAL_TYPES = ("none", "rabbitmq") @@ -33,10 +33,20 @@ class HookNotificationItemTypes(Enum): DELETE = "delete" +def _cleanup(path): + sane_path = pathutils.strip_path(path) + attributes = sane_path.split("/") if sane_path else [] + + if len(attributes) < 2: + return "" + return attributes[0] + "/" + attributes[1] + + class HookNotificationItem: - def __init__(self, notification_item_type, content): + def __init__(self, notification_item_type, path, content): self.type = notification_item_type.value + self.point = _cleanup(path) self.content = content def to_json(self):