Mercurial > libervia-backend
changeset 4186:c86a22009c1f
plugin XEP-0277: fix comments node handling when parent node doesn't exist.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 11 Dec 2023 00:46:34 +0100 |
parents | c6d85c31a59f |
children | 3b64b503f250 |
files | libervia/backend/plugins/plugin_xep_0277.py |
diffstat | 1 files changed, 16 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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