plugin XEP-0277: fix comments node handling when parent node doesn't exist.

This commit is contained in:
Goffi 2023-12-11 00:46:34 +01:00
commit 1dd8a46572

View file

@ -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