Parcourir la source

- Include legacy "content" parameter in HookNotificationItem usage

Nate Harris il y a 7 mois
Parent
commit
16b7311229
3 fichiers modifiés avec 22 ajouts et 19 suppressions
  1. 2 0
      radicale/app/delete.py
  2. 8 4
      radicale/app/proppatch.py
  3. 12 15
      radicale/app/put.py

+ 2 - 0
radicale/app/delete.py

@@ -85,6 +85,7 @@ class ApplicationPartDelete(ApplicationBase):
                         HookNotificationItem(
                             notification_item_type=HookNotificationItemTypes.DELETE,
                             path=access.path,
+                            content=i.uid,
                             uid=i.uid,
                             old_content=item.serialize(),  # type: ignore
                             new_content=None
@@ -98,6 +99,7 @@ class ApplicationPartDelete(ApplicationBase):
                     HookNotificationItem(
                         notification_item_type=HookNotificationItemTypes.DELETE,
                         path=access.path,
+                        content=item.uid,
                         uid=item.uid,
                         old_content=item.serialize(),  # type: ignore
                         new_content=None,

+ 8 - 4
radicale/app/proppatch.py

@@ -101,13 +101,17 @@ class ApplicationPartProppatch(ApplicationBase):
                 xml_answer = xml_proppatch(base_prefix, path, xml_content,
                                            item)
                 if xml_content is not None:
+                    content = DefusedET.tostring(
+                        xml_content,
+                        encoding=self._encoding
+                    ).decode(encoding=self._encoding)
                     hook_notification_item = HookNotificationItem(
                         notification_item_type=HookNotificationItemTypes.CPATCH,
                         path=access.path,
-                        new_content=DefusedET.tostring(
-                            xml_content,
-                            encoding=self._encoding
-                        ).decode(encoding=self._encoding)
+                        content=content,
+                        uid=None,
+                        old_content=None,
+                        new_content=content
                     )
                     self._hook.notify(hook_notification_item)
             except ValueError as e:

+ 12 - 15
radicale/app/put.py

@@ -254,6 +254,8 @@ class ApplicationPartPut(ApplicationBase):
                             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()
                             )
@@ -261,6 +263,8 @@ class ApplicationPartPut(ApplicationBase):
                             hook_notification_item = HookNotificationItem(
                                 notification_item_type=HookNotificationItemTypes.UPSERT,
                                 path=access.path,
+                                content=item.serialize(),
+                                uid=None,
                                 old_content=None,
                                 new_content=item.serialize()
                             )
@@ -282,21 +286,14 @@ class ApplicationPartPut(ApplicationBase):
                 try:
                     uploaded_item, replaced_item = parent_item.upload(href, prepared_item)
                     etag = uploaded_item.etag
-                    if replaced_item:
-                        # If the item was replaced, we notify with the old content
-                        hook_notification_item = HookNotificationItem(
-                            notification_item_type=HookNotificationItemTypes.UPSERT,
-                            path=access.path,
-                            old_content=replaced_item.serialize(),
-                            new_content=prepared_item.serialize()
-                        )
-                    else:  # If it was a new item, we notify with no old content
-                        hook_notification_item = HookNotificationItem(
-                            notification_item_type=HookNotificationItemTypes.UPSERT,
-                            path=access.path,
-                            old_content=None,
-                            new_content=prepared_item.serialize()
-                        )
+                    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)
                 except ValueError as e:
                     # return better matching HTTP result in case errno is provided and catched