Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_email_invitation.py @ 3323:44a9438d6608
plugin email invitation: simple invitation creation
The new `invitationSimpleCreate` is a simplified way to create an email invitation.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 Aug 2020 16:19:50 +0200 |
parents | 1af840e84af7 |
children | 83bc9d46a417 |
comparison
equal
deleted
inserted
replaced
3322:56ee491c0df6 | 3323:44a9438d6608 |
---|---|
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 | 2 |
3 | 3 # SàT plugin for sending invitations by email |
4 # SAT plugin for file tansfer | |
5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) | 4 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
6 | 5 |
7 # This program is free software: you can redistribute it and/or modify | 6 # This program is free software: you can redistribute it and/or modify |
8 # it under the terms of the GNU Affero General Public License as published by | 7 # it under the terms of the GNU Affero General Public License as published by |
9 # the Free Software Foundation, either version 3 of the License, or | 8 # the Free Software Foundation, either version 3 of the License, or |
88 method=self._modify, | 87 method=self._modify, |
89 async_=True) | 88 async_=True) |
90 host.bridge.addMethod("invitationList", ".plugin", in_sign='s', | 89 host.bridge.addMethod("invitationList", ".plugin", in_sign='s', |
91 out_sign='a{sa{ss}}', | 90 out_sign='a{sa{ss}}', |
92 method=self._list, | 91 method=self._list, |
92 async_=True) | |
93 host.bridge.addMethod("invitationSimpleCreate", ".plugin", in_sign='', | |
94 out_sign='a{ss}', | |
95 method=self._simpleCreate, | |
93 async_=True) | 96 async_=True) |
94 | 97 |
95 def checkExtra(self, extra): | 98 def checkExtra(self, extra): |
96 if EXTRA_RESERVED.intersection(extra): | 99 if EXTRA_RESERVED.intersection(extra): |
97 raise ValueError( | 100 raise ValueError( |
336 | 339 |
337 extra[KEY_ID] = id_ | 340 extra[KEY_ID] = id_ |
338 extra[KEY_JID] = jid_ | 341 extra[KEY_JID] = jid_ |
339 defer.returnValue(extra) | 342 defer.returnValue(extra) |
340 | 343 |
344 def _simpleCreate(self, invitee_email, url_template, extra_s, profile): | |
345 client = self.host.getClient(profile) | |
346 # FIXME: needed because python-dbus use a specific string class | |
347 invitee_email = str(invitee_email) | |
348 url_template = str(url_template) | |
349 extra = data_format.deserialise(extra_s) | |
350 d = defer.ensureDeferred( | |
351 self.simpleCreate(client, invitee_email, url_template, extra) | |
352 ) | |
353 d.addCallback(lambda data: {k: str(v) for k,v in data.items()}) | |
354 return d | |
355 | |
356 async def simpleCreate(self, client, invitee_email, url_template, extra): | |
357 """Simplified method to invite somebody by email""" | |
358 return await self.create( | |
359 email=invitee_email, | |
360 url_template=url_template, | |
361 profile=client.profile, | |
362 ) | |
363 | |
341 def get(self, id_): | 364 def get(self, id_): |
342 """Retrieve invitation linked to uuid if it exists | 365 """Retrieve invitation linked to uuid if it exists |
343 | 366 |
344 @param id_(unicode): UUID linked to an invitation | 367 @param id_(unicode): UUID linked to an invitation |
345 @return (dict[unicode, unicode]): data associated to the invitation | 368 @return (dict[unicode, unicode]): data associated to the invitation |
372 continue | 395 continue |
373 else: | 396 else: |
374 new_data = current_data | 397 new_data = current_data |
375 for k,v in new_extra.items(): | 398 for k,v in new_extra.items(): |
376 if k in EXTRA_RESERVED: | 399 if k in EXTRA_RESERVED: |
377 log.warning(_("Skipping reserved key {key}".format(k))) | 400 log.warning(_("Skipping reserved key {key}").format(key=k)) |
378 continue | 401 continue |
379 if v: | 402 if v: |
380 new_data[k] = v | 403 new_data[k] = v |
381 else: | 404 else: |
382 try: | 405 try: |