Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py @ 4094:c3b68fdc2de7
component AP gateway: fix handling of XMPP comments authors:
the gateway was supposing that comments where emitted from PEP of author. While this is
the case for most blog posts, it's not for comments. Instead the component is now using
`author_jid` which is retrieved by XEP-0277 plugin, and reject the item if the auhor is
not verified (i.e. if `publisher` attribute is not set by XMPP service).
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 12 Jun 2023 14:50:43 +0200 |
parents | 4b842c1fb686 |
children | 7067b0d73183 |
comparison
equal
deleted
inserted
replaced
4093:13b1079c27ec | 4094:c3b68fdc2de7 |
---|---|
123 RE_PERIOD_ENC = re.compile(f"\\.{HEXA_ENC}") | 123 RE_PERIOD_ENC = re.compile(f"\\.{HEXA_ENC}") |
124 RE_PERCENT_ENC = re.compile(f"%{HEXA_ENC}") | 124 RE_PERCENT_ENC = re.compile(f"%{HEXA_ENC}") |
125 RE_ALLOWED_UNQUOTED = re.compile(r"^[a-zA-Z0-9_-]+$") | 125 RE_ALLOWED_UNQUOTED = re.compile(r"^[a-zA-Z0-9_-]+$") |
126 | 126 |
127 | 127 |
128 class MissingLocalPartError(Exception): | |
129 """JID local part is missing""" | |
130 | |
131 | |
128 class APGateway: | 132 class APGateway: |
129 IMPORT_NAME = IMPORT_NAME | 133 IMPORT_NAME = IMPORT_NAME |
130 # show data send or received through HTTP, used for debugging | 134 # show data send or received through HTTP, used for debugging |
131 # 1: log POST objects | 135 # 1: log POST objects |
132 # 2: log POST and GET objects | 136 # 2: log POST and GET objects |
666 if node: | 670 if node: |
667 node = self.period_encode(node) | 671 node = self.period_encode(node) |
668 user = self.period_encode(user) | 672 user = self.period_encode(user) |
669 | 673 |
670 if not user: | 674 if not user: |
671 raise exceptions.InternalError("there should be a user part") | 675 raise MissingLocalPartError("there should be a local part") |
672 | 676 |
673 if node: | 677 if node: |
674 account_elts.extend((node, "---")) | 678 account_elts.extend((node, "---")) |
675 | 679 |
676 account_elts.extend(( | 680 account_elts.extend(( |
2092 except KeyError: | 2096 except KeyError: |
2093 # node and service must always be specified when this method is used | 2097 # node and service must always be specified when this method is used |
2094 raise exceptions.InternalError( | 2098 raise exceptions.InternalError( |
2095 "node or service is missing in mb_data" | 2099 "node or service is missing in mb_data" |
2096 ) | 2100 ) |
2097 target_ap_account = await self.get_ap_account_from_jid_and_node( | 2101 try: |
2098 service, node | 2102 target_ap_account = await self.get_ap_account_from_jid_and_node( |
2099 ) | 2103 service, node |
2104 ) | |
2105 except MissingLocalPartError: | |
2106 # we have no local part, this is probably a comment | |
2107 try: | |
2108 service = jid.JID(mb_data["author_jid"]) | |
2109 if not mb_data["author_jid_verified"]: | |
2110 raise KeyError | |
2111 except KeyError: | |
2112 raise exceptions.DataError( | |
2113 "Can't identify post author. Be sure to use a pubsub service " | |
2114 "setting the 'publisher' attribute." | |
2115 ) | |
2116 else: | |
2117 target_ap_account = await self.get_ap_account_from_jid_and_node( | |
2118 service, node | |
2119 ) | |
2100 if self.is_virtual_jid(service): | 2120 if self.is_virtual_jid(service): |
2101 # service is a proxy JID for AP account | 2121 # service is a proxy JID for AP account |
2102 actor_data = await self.get_ap_actor_data_from_account(target_ap_account) | 2122 actor_data = await self.get_ap_actor_data_from_account(target_ap_account) |
2103 followers = actor_data.get("followers") | 2123 followers = actor_data.get("followers") |
2104 else: | 2124 else: |