Mercurial > libervia-backend
comparison sat_frontends/jp/cmd_file.py @ 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 | 19bc03743aeb |
children | f30b238d9c45 |
comparison
equal
deleted
inserted
replaced
3409:4ca5bc6b44b6 | 3410:55f9a38864af |
---|---|
294 ) | 294 ) |
295 self._overwrite_refused = False # True when one overwrite as already been refused | 295 self._overwrite_refused = False # True when one overwrite as already been refused |
296 self.action_callbacks = { | 296 self.action_callbacks = { |
297 C.META_TYPE_FILE: self.onFileAction, | 297 C.META_TYPE_FILE: self.onFileAction, |
298 C.META_TYPE_OVERWRITE: self.onOverwriteAction, | 298 C.META_TYPE_OVERWRITE: self.onOverwriteAction, |
299 C.META_TYPE_NOT_IN_ROSTER_LEAK: self.onNotInRosterAction, | |
299 } | 300 } |
300 | 301 |
301 def add_parser_options(self): | 302 def add_parser_options(self): |
302 self.parser.add_argument( | 303 self.parser.add_argument( |
303 "jids", | 304 "jids", |
401 self.disp(_("Refused to overwrite"), 2) | 402 self.disp(_("Refused to overwrite"), 2) |
402 self._overwrite_refused = True | 403 self._overwrite_refused = True |
403 | 404 |
404 xmlui_data = {"answer": C.boolConst(self.args.force)} | 405 xmlui_data = {"answer": C.boolConst(self.args.force)} |
405 await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) | 406 await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) |
407 | |
408 async def onNotInRosterAction(self, action_data, action_id, security_limit, profile): | |
409 xmlui_id = self.getXmluiId(action_data) | |
410 if xmlui_id is None: | |
411 return self.host.quitFromSignal(1) | |
412 try: | |
413 from_jid = jid.JID(action_data["meta_from_jid"]) | |
414 except ValueError: | |
415 self.disp(_('invalid "from_jid" value received, ignoring: {value}').format( | |
416 value=from_jid), error=True) | |
417 return | |
418 except KeyError: | |
419 self.disp(_('ignoring action without "from_jid" value'), error=True) | |
420 return | |
421 self.disp(_("Confirmation needed for request from an entity not in roster"), 1) | |
422 | |
423 if from_jid.bare in self.bare_jids: | |
424 # if the sender is expected, we can confirm the session | |
425 confirmed = True | |
426 self.disp(_("Sender confirmed because she or he is explicitly expected"), 1) | |
427 else: | |
428 xmlui = xmlui_manager.create(self.host, action_data["xmlui"]) | |
429 confirmed = await self.host.confirm(xmlui.dlg.message) | |
430 | |
431 xmlui_data = {"answer": C.boolConst(confirmed)} | |
432 await self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile) | |
433 if not confirmed and not self.args.multiple: | |
434 self.disp(_("Session refused for {from_jid}").format(from_jid=from_jid)) | |
435 self.host.quitFromSignal(0) | |
406 | 436 |
407 async def start(self): | 437 async def start(self): |
408 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids] | 438 self.bare_jids = [jid.JID(jid_).bare for jid_ in self.args.jids] |
409 self.path = os.path.abspath(self.args.path) | 439 self.path = os.path.abspath(self.args.path) |
410 if not os.path.isdir(self.path): | 440 if not os.path.isdir(self.path): |