From 1dd8a46572baf54b8c4b6a4021e5d949d634a413 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 11 Dec 2023 00:46:34 +0100 Subject: [PATCH] plugin XEP-0277: fix comments node handling when parent node doesn't exist. --- libervia/backend/plugins/plugin_xep_0277.py | 23 ++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/libervia/backend/plugins/plugin_xep_0277.py b/libervia/backend/plugins/plugin_xep_0277.py index e861990d..5a308b60 100644 --- a/libervia/backend/plugins/plugin_xep_0277.py +++ b/libervia/backend/plugins/plugin_xep_0277.py @@ -828,9 +828,14 @@ class XEP_0277(object): for comments_data in mb_data.get('comments', []): link_elt = entry_elt.addElement("link") # XXX: "uri" is set in self._manage_comments if not already existing - link_elt["href"] = comments_data["uri"] - link_elt["rel"] = "replies" - link_elt["title"] = "comments" + try: + link_elt["href"] = comments_data["uri"] + except KeyError: + log.warning(f"missing URI in comments data: {comments_data}") + entry_elt.children.remove(link_elt) + else: + link_elt["rel"] = "replies" + link_elt["title"] = "comments" if "repeated" in extra: try: @@ -937,13 +942,17 @@ class XEP_0277(object): # handle this in a list if len(mb_data.setdefault('comments', [])) == 0: # we need at least one comment node - comments_data = {} mb_data['comments'].append({}) if access is None: # TODO: cache access models per service/node - parent_node_config = await self._p.getConfiguration(client, service, node) - access = parent_node_config.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN) + try: + parent_node_config = await self._p.getConfiguration(client, service, node) + except error.StanzaError as e: + log.debug(f"Can't get parent node configuration: {e}") + access = self._p.ACCESS_OPEN + else: + access = parent_node_config.get(self._p.OPT_ACCESS_MODEL, self._p.ACCESS_OPEN) options = { self._p.OPT_ACCESS_MODEL: access, @@ -1012,7 +1021,7 @@ class XEP_0277(object): # because we wants members to be able to write to comments for jid_, affiliation in list(comments_affiliations.items()): if affiliation == "member": - comments_affiliations[jid_] == "publisher" + comments_affiliations[jid_] = "publisher" await self._p.set_node_affiliations( client, comments_service, comments_node, comments_affiliations