# HG changeset patch # User Goffi # Date 1596291590 -7200 # Node ID 44a9438d66089f11b976aac24d46fbfb10c6e4d8 # Parent 56ee491c0df6c003fff02fb8713f909d3da7d600 plugin email invitation: simple invitation creation The new `invitationSimpleCreate` is a simplified way to create an email invitation. diff -r 56ee491c0df6 -r 44a9438d6608 sat/plugins/plugin_misc_email_invitation.py --- a/sat/plugins/plugin_misc_email_invitation.py Sat Aug 01 16:17:19 2020 +0200 +++ b/sat/plugins/plugin_misc_email_invitation.py Sat Aug 01 16:19:50 2020 +0200 @@ -1,7 +1,6 @@ #!/usr/bin/env python3 - -# SAT plugin for file tansfer +# SàT plugin for sending invitations by email # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) # This program is free software: you can redistribute it and/or modify @@ -91,6 +90,10 @@ out_sign='a{sa{ss}}', method=self._list, async_=True) + host.bridge.addMethod("invitationSimpleCreate", ".plugin", in_sign='', + out_sign='a{ss}', + method=self._simpleCreate, + async_=True) def checkExtra(self, extra): if EXTRA_RESERVED.intersection(extra): @@ -338,6 +341,26 @@ extra[KEY_JID] = jid_ defer.returnValue(extra) + def _simpleCreate(self, invitee_email, url_template, extra_s, profile): + client = self.host.getClient(profile) + # FIXME: needed because python-dbus use a specific string class + invitee_email = str(invitee_email) + url_template = str(url_template) + extra = data_format.deserialise(extra_s) + d = defer.ensureDeferred( + self.simpleCreate(client, invitee_email, url_template, extra) + ) + d.addCallback(lambda data: {k: str(v) for k,v in data.items()}) + return d + + async def simpleCreate(self, client, invitee_email, url_template, extra): + """Simplified method to invite somebody by email""" + return await self.create( + email=invitee_email, + url_template=url_template, + profile=client.profile, + ) + def get(self, id_): """Retrieve invitation linked to uuid if it exists @@ -374,7 +397,7 @@ new_data = current_data for k,v in new_extra.items(): if k in EXTRA_RESERVED: - log.warning(_("Skipping reserved key {key}".format(k))) + log.warning(_("Skipping reserved key {key}").format(key=k)) continue if v: new_data[k] = v