- Check if hook is enabled before constructing hook notification items
- Skip/early exit email hook if notification item is not a VCALENDAR
This commit is contained in:
@@ -89,34 +89,38 @@ class ApplicationPartDelete(ApplicationBase):
|
||||
if not access.check("D", item):
|
||||
logger.info("delete of collection is prevented by config/option [rights] permit_delete_collection and not explicit allowed by permission 'D': %s", path)
|
||||
return httputils.NOT_ALLOWED
|
||||
for i in item.get_all():
|
||||
hook_notification_item_list.append(
|
||||
HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.DELETE,
|
||||
path=access.path,
|
||||
content=i.uid,
|
||||
uid=i.uid,
|
||||
old_content=i.serialize(), # type: ignore
|
||||
new_content=None
|
||||
if self._hook.enabled:
|
||||
for i in item.get_all():
|
||||
hook_notification_item_list.append(
|
||||
HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.DELETE,
|
||||
path=access.path,
|
||||
content=i.uid,
|
||||
content_type=i.name,
|
||||
uid=i.uid,
|
||||
old_content=i.serialize(), # type: ignore
|
||||
new_content=None
|
||||
)
|
||||
)
|
||||
)
|
||||
xml_answer = xml_delete(base_prefix, path, item)
|
||||
else:
|
||||
assert item.collection is not None
|
||||
assert item.href is not None
|
||||
hook_notification_item_list.append(
|
||||
HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.DELETE,
|
||||
path=access.path,
|
||||
content=item.uid,
|
||||
uid=item.uid,
|
||||
old_content=item.serialize(), # type: ignore
|
||||
new_content=None,
|
||||
if self._hook.enabled:
|
||||
hook_notification_item_list.append(
|
||||
HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.DELETE,
|
||||
path=access.path,
|
||||
content=item.uid,
|
||||
content_type=item.name,
|
||||
uid=item.uid,
|
||||
old_content=item.serialize(), # type: ignore
|
||||
new_content=None,
|
||||
)
|
||||
)
|
||||
)
|
||||
xml_answer = xml_delete(
|
||||
base_prefix, path, item.collection, item.href)
|
||||
for notification_item in hook_notification_item_list:
|
||||
for notification_item in hook_notification_item_list: # Will be empty if hook not enabled
|
||||
self._hook.notify(notification_item)
|
||||
headers = {"Content-Type": "text/xml; charset=%s" % self._encoding}
|
||||
return client.OK, headers, self._xml_response(xml_answer), None
|
||||
|
||||
@@ -205,15 +205,17 @@ class ApplicationPartProppatch(ApplicationBase):
|
||||
xml_content,
|
||||
encoding=self._encoding
|
||||
).decode(encoding=self._encoding)
|
||||
hook_notification_item = HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.CPATCH,
|
||||
path=access.path,
|
||||
content=content,
|
||||
uid=None,
|
||||
old_content=None,
|
||||
new_content=content
|
||||
)
|
||||
self._hook.notify(hook_notification_item)
|
||||
if self._hook.enabled:
|
||||
hook_notification_item = HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.CPATCH,
|
||||
path=access.path,
|
||||
content=content,
|
||||
content_type=None, # Can't easily determine content type, won't trigger email hook
|
||||
uid=None,
|
||||
old_content=None,
|
||||
new_content=content
|
||||
)
|
||||
self._hook.notify(hook_notification_item)
|
||||
except ValueError as e:
|
||||
# return better matching HTTP result in case errno is provided and catched
|
||||
errno_match = re.search("\\[Errno ([0-9]+)\\]", str(e))
|
||||
|
||||
@@ -306,28 +306,32 @@ class ApplicationPartPut(ApplicationBase):
|
||||
href=path,
|
||||
items=prepared_items,
|
||||
props=props)
|
||||
for item in prepared_items:
|
||||
# Try to grab the previously-existing item by href
|
||||
existing_item = replaced_items.get(item.href, None) # type: ignore
|
||||
if existing_item:
|
||||
hook_notification_item = HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.UPSERT,
|
||||
path=access.path,
|
||||
content=existing_item.serialize(),
|
||||
uid=None,
|
||||
old_content=existing_item.serialize(),
|
||||
new_content=item.serialize()
|
||||
)
|
||||
else: # We assume the item is new because it was not in the replaced_items
|
||||
hook_notification_item = HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.UPSERT,
|
||||
path=access.path,
|
||||
content=item.serialize(),
|
||||
uid=None,
|
||||
old_content=None,
|
||||
new_content=item.serialize()
|
||||
)
|
||||
self._hook.notify(hook_notification_item)
|
||||
# Only run the hook if the hook is enabled
|
||||
if self._hook.enabled:
|
||||
for item in prepared_items:
|
||||
# Try to grab the previously-existing item by href
|
||||
existing_item = replaced_items.get(item.href, None) # type: ignore
|
||||
if existing_item:
|
||||
hook_notification_item = HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.UPSERT,
|
||||
path=access.path,
|
||||
content=existing_item.serialize(),
|
||||
content_type=item.name,
|
||||
uid=None,
|
||||
old_content=existing_item.serialize(),
|
||||
new_content=item.serialize(),
|
||||
)
|
||||
else: # We assume the item is new because it was not in the replaced_items
|
||||
hook_notification_item = HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.UPSERT,
|
||||
path=access.path,
|
||||
content=item.serialize(),
|
||||
content_type=item.name,
|
||||
uid=None,
|
||||
old_content=None,
|
||||
new_content=item.serialize()
|
||||
)
|
||||
self._hook.notify(hook_notification_item)
|
||||
except ValueError as e:
|
||||
logger.warning(
|
||||
"Bad PUT request on %r (create_collection): %s", path, e, exc_info=True)
|
||||
@@ -345,15 +349,17 @@ class ApplicationPartPut(ApplicationBase):
|
||||
try:
|
||||
uploaded_item, replaced_item = parent_item.upload(href, prepared_item)
|
||||
etag = uploaded_item.etag
|
||||
hook_notification_item = HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.UPSERT,
|
||||
path=access.path,
|
||||
content=prepared_item.serialize(),
|
||||
uid=None,
|
||||
old_content=replaced_item.serialize() if replaced_item else None,
|
||||
new_content=prepared_item.serialize()
|
||||
)
|
||||
self._hook.notify(hook_notification_item)
|
||||
if self._hook.enabled:
|
||||
hook_notification_item = HookNotificationItem(
|
||||
notification_item_type=HookNotificationItemTypes.UPSERT,
|
||||
path=access.path,
|
||||
content=prepared_item.serialize(),
|
||||
content_type=prepared_item.name,
|
||||
uid=None,
|
||||
old_content=replaced_item.serialize() if replaced_item else None,
|
||||
new_content=prepared_item.serialize(),
|
||||
)
|
||||
self._hook.notify(hook_notification_item)
|
||||
except ValueError as e:
|
||||
# return better matching HTTP result in case errno is provided and catched
|
||||
errno_match = re.search("\\[Errno ([0-9]+)\\]", str(e))
|
||||
|
||||
Reference in New Issue
Block a user