cli (file/receive): handle CONFIRM dialog received in pre-flight.

This commit is contained in:
Goffi 2024-03-05 17:31:56 +01:00
commit dec2fa48bc

View file

@ -303,6 +303,7 @@ class Receive(base.CommandAnswering):
) )
self._overwrite_refused = False # True when one overwrite as already been refused self._overwrite_refused = False # True when one overwrite as already been refused
self.action_callbacks = { self.action_callbacks = {
C.META_TYPE_CONFIRM: self.on_confirm_action,
C.META_TYPE_FILE: self.on_file_action, C.META_TYPE_FILE: self.on_file_action,
C.META_TYPE_OVERWRITE: self.on_overwrite_action, C.META_TYPE_OVERWRITE: self.on_overwrite_action,
C.META_TYPE_NOT_IN_ROSTER_LEAK: self.on_not_in_roster_action, C.META_TYPE_NOT_IN_ROSTER_LEAK: self.on_not_in_roster_action,
@ -368,6 +369,23 @@ class Receive(base.CommandAnswering):
self.disp(_("Invalid XMLUI received"), error=True) self.disp(_("Invalid XMLUI received"), error=True)
return xmlui_id return xmlui_id
async def on_confirm_action(self, action_data, action_id, security_limit, profile):
xmlui_id = self.get_xmlui_id(action_data)
if xmlui_id is None:
return self.host.quit_from_signal(1)
if action_data.get("subtype") != C.META_TYPE_FILE:
self.disp(_("Ignoring confirm dialog unrelated to file."), 1)
return
# we always accept preflight confirmation dialog, as for now a second dialog is
# always sent
# FIXME: real confirmation should be done here, and second dialog should not be
# sent from backend
xmlui_data = {"answer": C.BOOL_TRUE}
await self.host.bridge.action_launch(
xmlui_id, data_format.serialise(xmlui_data), profile_key=profile
)
async def on_file_action(self, action_data, action_id, security_limit, profile): async def on_file_action(self, action_data, action_id, security_limit, profile):
xmlui_id = self.get_xmlui_id(action_data) xmlui_id = self.get_xmlui_id(action_data)
if xmlui_id is None: if xmlui_id is None:
@ -429,7 +447,7 @@ class Receive(base.CommandAnswering):
except ValueError: except ValueError:
self.disp( self.disp(
_('invalid "from_jid" value received, ignoring: {value}').format( _('invalid "from_jid" value received, ignoring: {value}').format(
value=from_jid value=action_data["from_jid"]
), ),
error=True, error=True,
) )
@ -459,7 +477,7 @@ class Receive(base.CommandAnswering):
self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids] self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids]
self.path = os.path.abspath(self.args.path) self.path = os.path.abspath(self.args.path)
if not os.path.isdir(self.path): if not os.path.isdir(self.path):
self.disp(_("Given path is not a directory !", error=True)) self.disp(_("Given path is not a directory !"), error=True)
self.host.quit(C.EXIT_BAD_ARG) self.host.quit(C.EXIT_BAD_ARG)
if self.args.multiple: if self.args.multiple:
self.host.quit_on_progress_end = False self.host.quit_on_progress_end = False