Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_email_invitation.py @ 3337:932cf08dfdc3
plugin email invitation: new `invitationDelete` method
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 13 Aug 2020 23:46:18 +0200 |
parents | e38ddaf477bd |
children | be6d91572633 |
comparison
equal
deleted
inserted
replaced
3336:e38ddaf477bd | 3337:932cf08dfdc3 |
---|---|
18 | 18 |
19 import shortuuid | 19 import shortuuid |
20 from twisted.internet import defer | 20 from twisted.internet import defer |
21 from twisted.words.protocols.jabber import jid | 21 from twisted.words.protocols.jabber import jid |
22 from twisted.words.protocols.jabber import error | 22 from twisted.words.protocols.jabber import error |
23 from twisted.words.protocols.jabber import sasl | |
23 from sat.core.i18n import _, D_ | 24 from sat.core.i18n import _, D_ |
24 from sat.core.constants import Const as C | 25 from sat.core.constants import Const as C |
25 from sat.core import exceptions | 26 from sat.core import exceptions |
26 from sat.core.log import getLogger | 27 from sat.core.log import getLogger |
27 from sat.tools import utils | 28 from sat.tools import utils |
79 out_sign='a{ss}', | 80 out_sign='a{ss}', |
80 method=self._create, | 81 method=self._create, |
81 async_=True) | 82 async_=True) |
82 host.bridge.addMethod("invitationGet", ".plugin", in_sign='s', out_sign='a{ss}', | 83 host.bridge.addMethod("invitationGet", ".plugin", in_sign='s', out_sign='a{ss}', |
83 method=self.get, | 84 method=self.get, |
85 async_=True) | |
86 host.bridge.addMethod("invitationDelete", ".plugin", in_sign='s', out_sign='', | |
87 method=self._delete, | |
84 async_=True) | 88 async_=True) |
85 host.bridge.addMethod("invitationModify", ".plugin", in_sign='sa{ss}b', | 89 host.bridge.addMethod("invitationModify", ".plugin", in_sign='sa{ss}b', |
86 out_sign='', | 90 out_sign='', |
87 method=self._modify, | 91 method=self._modify, |
88 async_=True) | 92 async_=True) |
379 @return (dict[unicode, unicode]): data associated to the invitation | 383 @return (dict[unicode, unicode]): data associated to the invitation |
380 @raise KeyError: there is not invitation with this id_ | 384 @raise KeyError: there is not invitation with this id_ |
381 """ | 385 """ |
382 return self.invitations[id_] | 386 return self.invitations[id_] |
383 | 387 |
388 def _delete(self, id_): | |
389 return defer.ensureDeferred(self.delete(id_)) | |
390 | |
391 async def delete(self, id_): | |
392 """Delete an invitation data and associated XMPP account""" | |
393 log.info(f"deleting invitation {id_}") | |
394 data = await self.get(id_) | |
395 guest_profile = data['guest_profile'] | |
396 password = data['password'] | |
397 try: | |
398 await self.host.connect(guest_profile, password) | |
399 guest_client = self.host.getClient(guest_profile) | |
400 # XXX: be extra careful to use guest_client and not client below, as this will | |
401 # delete the associated XMPP account | |
402 log.debug("deleting XMPP account") | |
403 await self.host.plugins['XEP-0077'].unregister(guest_client, None) | |
404 except (error.StanzaError, sasl.SASLAuthError) as e: | |
405 log.warning( | |
406 f"Can't delete {guest_profile}'s XMPP account, maybe it as already been " | |
407 f"deleted: {e}") | |
408 try: | |
409 await self.host.memory.asyncDeleteProfile(guest_profile, True) | |
410 except Exception as e: | |
411 log.warning(f"Can't delete guest profile {guest_profile}: {e}") | |
412 log.debug("removing guest data") | |
413 await self.invitations.adel(id_) | |
414 log.info(f"{id_} invitation has been deleted") | |
415 | |
384 def _modify(self, id_, new_extra, replace): | 416 def _modify(self, id_, new_extra, replace): |
385 return self.modify(id_, {str(k): str(v) for k,v in new_extra.items()}, | 417 return self.modify(id_, {str(k): str(v) for k,v in new_extra.items()}, |
386 replace) | 418 replace) |
387 | 419 |
388 def modify(self, id_, new_extra, replace=False): | 420 def modify(self, id_, new_extra, replace=False): |