comparison sat/plugins/plugin_comp_ap_gateway/http_server.py @ 3870:bd84d289fc94

component AP gateway: fix item ID for XMPP items on Announce: if an Announced item is from XMPP, the AP id must be parsed to retrieve the XMPP original ID. rel 370
author Goffi <goffi@goffi.org>
date Fri, 22 Jul 2022 15:42:59 +0200
parents c0bcbcf5b4b7
children 2e4a0f6050bd
comparison
equal deleted inserted replaced
3869:c0bcbcf5b4b7 3870:bd84d289fc94
286 if repeated: 286 if repeated:
287 # we don't check sender when item is repeated, as it should be different 287 # we don't check sender when item is repeated, as it should be different
288 # from post author in this case 288 # from post author in this case
289 sender_jid = await self.apg.getJIDFromId(sender) 289 sender_jid = await self.apg.getJIDFromId(sender)
290 repeater_jid = await self.apg.getJIDFromId(signing_actor) 290 repeater_jid = await self.apg.getJIDFromId(signing_actor)
291 repeated_item_id = obj["id"]
292 if self.apg.isLocalURL(repeated_item_id):
293 # the repeated object is from XMPP, we need to parse the URL to find
294 # the right ID
295 url_type, url_args = self.apg.parseAPURL(repeated_item_id)
296 if url_type != "item":
297 raise exceptions.DataError(
298 "local URI is not an item: {repeated_id}"
299 )
300 try:
301 url_account, url_item_id = url_args
302 if not url_account or not url_item_id:
303 raise ValueError
304 except (RuntimeError, ValueError):
305 raise exceptions.DataError(
306 "local URI is invalid: {repeated_id}"
307 )
308 else:
309 url_jid, url_node = await self.apg.getJIDAndNode(url_account)
310 if ((url_jid != sender_jid
311 or url_node and url_node != self.apg._m.namespace)):
312 raise exceptions.DataError(
313 "announced ID doesn't match sender ({sender}): "
314 f"[repeated_item_id]"
315 )
316
317 repeated_item_id = url_item_id
291 318
292 obj["_repeated"] = { 319 obj["_repeated"] = {
293 "by": repeater_jid.full(), 320 "by": repeater_jid.full(),
294 "at": data.get("published"), 321 "at": data.get("published"),
295 "uri": uri.buildXMPPUri( 322 "uri": uri.buildXMPPUri(
296 "pubsub", 323 "pubsub",
297 path=sender_jid.full(), 324 path=sender_jid.full(),
298 node=self.apg._m.namespace, 325 node=self.apg._m.namespace,
299 item=obj["id"] 326 item=repeated_item_id
300 ) 327 )
301 } 328 }
302 # we must use activity's id and targets, not the original item ones 329 # we must use activity's id and targets, not the original item ones
303 for field in ("id", "to", "bto", "cc", "bcc"): 330 for field in ("id", "to", "bto", "cc", "bcc"):
304 obj[field] = data.get(field) 331 obj[field] = data.get(field)