comparison sat/plugins/plugin_xep_0346.py @ 3457:6791103de47d

plugin XEP-0346: use submitted namespace for node: the node was not always adapted to the submitted namespace now used with XEP-0346, this patch fixes it by adding the prefix when it's missing.
author Goffi <goffi@goffi.org>
date Thu, 04 Feb 2021 21:05:21 +0100
parents bb0225aaf4e6
children d4a71a1dac88
comparison
equal deleted inserted replaced
3456:6deea0d8d0e7 3457:6791103de47d
110 namespace = namespace[len(SUBMITTED_PREFIX):] 110 namespace = namespace[len(SUBMITTED_PREFIX):]
111 elif namespace.startswith(TEMPLATE_PREFIX): 111 elif namespace.startswith(TEMPLATE_PREFIX):
112 namespace = namespace[len(TEMPLATE_PREFIX):] 112 namespace = namespace[len(TEMPLATE_PREFIX):]
113 return namespace 113 return namespace
114 114
115 def getSubmittedNS(self, app_ns: str) -> str: 115 def getSubmittedNS(self, namespace: str) -> str:
116 """Returns node to use to submit forms""" 116 """Returns node to use to submit forms"""
117 return f"{SUBMITTED_PREFIX}{app_ns}" 117 return f"{SUBMITTED_PREFIX}{self.getApplicationNS(namespace)}"
118 118
119 def _getSchemaBridgeCb(self, schema_elt): 119 def _getSchemaBridgeCb(self, schema_elt):
120 if schema_elt is None: 120 if schema_elt is None:
121 return "" 121 return ""
122 return schema_elt.toXml() 122 return schema_elt.toXml()
298 if not default_node: 298 if not default_node:
299 raise ValueError( 299 raise ValueError(
300 _("default_node must be set if nodeIdentifier is not set") 300 _("default_node must be set if nodeIdentifier is not set")
301 ) 301 )
302 nodeIdentifier = default_node 302 nodeIdentifier = default_node
303 submitted_ns = self.getSubmittedNS(nodeIdentifier)
303 # we need the initial form to get options of fields when suitable 304 # we need the initial form to get options of fields when suitable
304 schema_form = await self.getSchemaForm( 305 schema_form = await self.getSchemaForm(
305 client, service, nodeIdentifier, schema, form_type="result", copy_form=False 306 client, service, nodeIdentifier, schema, form_type="result", copy_form=False
306 ) 307 )
307 items_data = await self._p.getItems( 308 items_data = await self._p.getItems(
308 client, 309 client,
309 service, 310 service,
310 nodeIdentifier, 311 submitted_ns,
311 max_items, 312 max_items,
312 item_ids, 313 item_ids,
313 sub_id, 314 sub_id,
314 rsm_request, 315 rsm_request,
315 extra, 316 extra,
657 extra = {} 658 extra = {}
658 if not node: 659 if not node:
659 if default_node is None: 660 if default_node is None:
660 raise ValueError(_("default_node must be set if node is not set")) 661 raise ValueError(_("default_node must be set if node is not set"))
661 node = default_node 662 node = default_node
663 node = self.getSubmittedNS(node)
662 now = utils.xmpp_date() 664 now = utils.xmpp_date()
663 if not item_id: 665 if not item_id:
664 values["created"] = now 666 values["created"] = now
665 elif extra.get("update", False): 667 elif extra.get("update", False):
666 if item_id is None: 668 if item_id is None: