jp (file/receive): display or answer to C.META_TYPE_NOT_IN_ROSTER_LEAK dialog:

when a file is proposed by an entity not in roster, the dialog asking for confirmation
is displayed. If the bare jid of the sender is explicitely waited (i.e. it's in
arguments), then the dialog is automatically confirmed.
This commit is contained in:
Goffi 2020-11-12 14:53:16 +01:00
commit cc61784c2e

View file

@ -296,6 +296,7 @@ class Receive(base.CommandAnswering):
self.action_callbacks = {
C.META_TYPE_FILE: self.onFileAction,
C.META_TYPE_OVERWRITE: self.onOverwriteAction,
C.META_TYPE_NOT_IN_ROSTER_LEAK: self.onNotInRosterAction,
}
def add_parser_options(self):
@ -404,6 +405,35 @@ class Receive(base.CommandAnswering):
xmlui_data = {"answer": C.boolConst(self.args.force)}
await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile)
async def onNotInRosterAction(self, action_data, action_id, security_limit, profile):
xmlui_id = self.getXmluiId(action_data)
if xmlui_id is None:
return self.host.quitFromSignal(1)
try:
from_jid = jid.JID(action_data["meta_from_jid"])
except ValueError:
self.disp(_('invalid "from_jid" value received, ignoring: {value}').format(
value=from_jid), error=True)
return
except KeyError:
self.disp(_('ignoring action without "from_jid" value'), error=True)
return
self.disp(_("Confirmation needed for request from an entity not in roster"), 1)
if from_jid.bare in self.bare_jids:
# if the sender is expected, we can confirm the session
confirmed = True
self.disp(_("Sender confirmed because she or he is explicitly expected"), 1)
else:
xmlui = xmlui_manager.create(self.host, action_data["xmlui"])
confirmed = await self.host.confirm(xmlui.dlg.message)
xmlui_data = {"answer": C.boolConst(confirmed)}
await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile)
if not confirmed and not self.args.multiple:
self.disp(_("Session refused for {from_jid}").format(from_jid=from_jid))
self.host.quitFromSignal(0)
async def start(self):
self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids]
self.path = os.path.abspath(self.args.path)