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).
This commit is contained in:
parent
2fa4681929
commit
0fa0b3a5f6
1 changed files with 24 additions and 4 deletions
|
|
@ -125,6 +125,10 @@ RE_PERCENT_ENC = re.compile(f"%{HEXA_ENC}")
|
|||
RE_ALLOWED_UNQUOTED = re.compile(r"^[a-zA-Z0-9_-]+$")
|
||||
|
||||
|
||||
class MissingLocalPartError(Exception):
|
||||
"""JID local part is missing"""
|
||||
|
||||
|
||||
class APGateway:
|
||||
IMPORT_NAME = IMPORT_NAME
|
||||
# show data send or received through HTTP, used for debugging
|
||||
|
|
@ -668,7 +672,7 @@ class APGateway:
|
|||
user = self.period_encode(user)
|
||||
|
||||
if not user:
|
||||
raise exceptions.InternalError("there should be a user part")
|
||||
raise MissingLocalPartError("there should be a local part")
|
||||
|
||||
if node:
|
||||
account_elts.extend((node, "---"))
|
||||
|
|
@ -2094,9 +2098,25 @@ class APGateway:
|
|||
raise exceptions.InternalError(
|
||||
"node or service is missing in mb_data"
|
||||
)
|
||||
target_ap_account = await self.get_ap_account_from_jid_and_node(
|
||||
service, node
|
||||
)
|
||||
try:
|
||||
target_ap_account = await self.get_ap_account_from_jid_and_node(
|
||||
service, node
|
||||
)
|
||||
except MissingLocalPartError:
|
||||
# we have no local part, this is probably a comment
|
||||
try:
|
||||
service = jid.JID(mb_data["author_jid"])
|
||||
if not mb_data["author_jid_verified"]:
|
||||
raise KeyError
|
||||
except KeyError:
|
||||
raise exceptions.DataError(
|
||||
"Can't identify post author. Be sure to use a pubsub service "
|
||||
"setting the 'publisher' attribute."
|
||||
)
|
||||
else:
|
||||
target_ap_account = await self.get_ap_account_from_jid_and_node(
|
||||
service, node
|
||||
)
|
||||
if self.is_virtual_jid(service):
|
||||
# service is a proxy JID for AP account
|
||||
actor_data = await self.get_ap_actor_data_from_account(target_ap_account)
|
||||
|
|
|
|||
Loading…
Reference in a new issue