# HG changeset patch # User Goffi # Date 1702251994 -3600 # Node ID c86a22009c1f2cdcaeb59afad2bbd97402c3f127 # Parent c6d85c31a59f9252661d2ced717dd6cb2aa38711 plugin XEP-0277: fix comments node handling when parent node doesn't exist. diff -r c6d85c31a59f -r c86a22009c1f libervia/backend/plugins/plugin_xep_0277.py --- a/libervia/backend/plugins/plugin_xep_0277.py Sun Dec 10 18:32:04 2023 +0100 +++ b/libervia/backend/plugins/plugin_xep_0277.py Mon Dec 11 00:46:34 2023 +0100 @@ -828,9 +828,14 @@ 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 @@ # 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 @@ # 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