changeset 3410:55f9a38864af

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.
author Goffi <goffi@goffi.org>
date Thu, 12 Nov 2020 14:53:16 +0100
parents 4ca5bc6b44b6
children f30b238d9c45
files sat_frontends/jp/cmd_file.py
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_file.py	Thu Nov 12 14:53:16 2020 +0100
+++ b/sat_frontends/jp/cmd_file.py	Thu Nov 12 14:53:16 2020 +0100
@@ -296,6 +296,7 @@
         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 @@
             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)