annotate sat/plugins/plugin_misc_email_invitation.py @ 3335:83bc9d46a417

plugin email invitation: fixed create/simpleCreate + invitee_name: - fixed invitationSimpleCreate signature - fixed nicknames settings in create - use async coroutines - guest jid is now stored (as a string), avoiding the need to check profile to retrieve it - invitee_name is now needed in invitationSimpleCreate
author Goffi <goffi@goffi.org>
date Thu, 13 Aug 2020 23:46:18 +0200
parents 44a9438d6608
children e38ddaf477bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
3 # SàT plugin for sending invitations by email
3136
9d0df638c8b4 dates update
Goffi <goffi@goffi.org>
parents: 3120
diff changeset
4 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
19 import shortuuid
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
20 from twisted.internet import defer
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
21 from twisted.words.protocols.jabber import jid
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
22 from twisted.words.protocols.jabber import error
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.i18n import _, D_
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.core.constants import Const as C
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core import exceptions
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.core.log import getLogger
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from sat.tools import utils
2291
c05000d00dbb plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents: 2256
diff changeset
28 from sat.tools.common import data_format
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from sat.memory import persistent
3007
420897488080 plugins account, email invitation: fixed import of "email" module after it has been moved
Goffi <goffi@goffi.org>
parents: 2912
diff changeset
30 from sat.tools.common import email as sat_email
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
32 log = getLogger(__name__)
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
33
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 PLUGIN_INFO = {
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
36 C.PI_NAME: "Email Invitations",
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
37 C.PI_IMPORT_NAME: "EMAIL_INVITATION",
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_TYPE: C.PLUG_TYPE_MISC,
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 C.PI_DEPENDENCIES: ['XEP-0077'],
2256
61e836cc9512 plugin invitations: name is now registered as nickname on XMPP server thanks to plugin identity
Goffi <goffi@goffi.org>
parents: 2255
diff changeset
40 C.PI_RECOMMENDATIONS: ["IDENTITY"],
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_MAIN: "InvitationsPlugin",
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_HANDLER: "no",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
43 C.PI_DESCRIPTION: _("""invitation of people without XMPP account""")
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 }
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 SUFFIX_MAX = 5
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
48 INVITEE_PROFILE_TPL = "guest@@{uuid}"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
49 KEY_ID = 'id'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
50 KEY_JID = 'jid'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
51 KEY_CREATED = 'created'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
52 KEY_LAST_CONNECTION = 'last_connection'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
53 KEY_GUEST_PROFILE = 'guest_profile'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
54 KEY_PASSWORD = 'password'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
55 KEY_EMAILS_EXTRA = 'emails_extra'
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
56 EXTRA_RESERVED = {KEY_ID, KEY_JID, KEY_CREATED, 'jid_', 'jid', KEY_LAST_CONNECTION,
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
57 KEY_GUEST_PROFILE, KEY_PASSWORD, KEY_EMAILS_EXTRA}
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
58 DEFAULT_SUBJECT = D_("You have been invited by {host_name} to {app_name}")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
59 DEFAULT_BODY = D_("""Hello {name}!
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 You have received an invitation from {host_name} to participate to "{app_name}".
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 To join, you just have to click on the following URL:
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 {url}
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 Please note that this URL should not be shared with anybody!
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 If you want more details on {app_name}, you can check {app_url}.
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 Welcome!
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 """)
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 class InvitationsPlugin(object):
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
75 log.info(_("plugin Invitations initialization"))
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.host = host
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
77 self.invitations = persistent.LazyPersistentBinaryDict('invitations')
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
78 host.bridge.addMethod("invitationCreate", ".plugin", in_sign='sasssssssssa{ss}s',
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
79 out_sign='a{ss}',
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
80 method=self._create,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
81 async_=True)
2212
eaf2467d19ce plugin invitations: added getInvitation method, it return invitation data and raise an error if it is not found
Goffi <goffi@goffi.org>
parents: 2211
diff changeset
82 host.bridge.addMethod("invitationGet", ".plugin", in_sign='s', out_sign='a{ss}',
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
83 method=self.get,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
84 async_=True)
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
85 host.bridge.addMethod("invitationModify", ".plugin", in_sign='sa{ss}b',
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
86 out_sign='',
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
87 method=self._modify,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
88 async_=True)
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
89 host.bridge.addMethod("invitationList", ".plugin", in_sign='s',
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
90 out_sign='a{sa{ss}}',
2230
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
91 method=self._list,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
92 async_=True)
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
93 host.bridge.addMethod("invitationSimpleCreate", ".plugin", in_sign='sssss',
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
94 out_sign='a{ss}',
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
95 method=self._simpleCreate,
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
96 async_=True)
2212
eaf2467d19ce plugin invitations: added getInvitation method, it return invitation data and raise an error if it is not found
Goffi <goffi@goffi.org>
parents: 2211
diff changeset
97
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
98 def checkExtra(self, extra):
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
99 if EXTRA_RESERVED.intersection(extra):
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
100 raise ValueError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
101 _("You can't use following key(s) in extra, they are reserved: {}")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
102 .format(', '.join(EXTRA_RESERVED.intersection(extra))))
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
103
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
104 def _create(self, email='', emails_extra=None, jid_='', password='', name='',
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
105 host_name='', language='', url_template='', message_subject='',
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
106 message_body='', extra=None, profile=''):
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
107 # XXX: we don't use **kwargs here to keep arguments name for introspection with
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
108 # D-Bus bridge
2291
c05000d00dbb plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents: 2256
diff changeset
109 if emails_extra is None:
c05000d00dbb plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents: 2256
diff changeset
110 emails_extra = []
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 if extra is None:
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 extra = {}
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
115 extra = {str(k): str(v) for k,v in extra.items()}
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
2291
c05000d00dbb plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents: 2256
diff changeset
117 kwargs = {"extra": extra,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
118 KEY_EMAILS_EXTRA: [str(e) for e in emails_extra]
2291
c05000d00dbb plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents: 2256
diff changeset
119 }
c05000d00dbb plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents: 2256
diff changeset
120
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
121 # we need to be sure that values are unicode, else they won't be pickled correctly
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
122 # with D-Bus
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
123 for key in ("jid_", "password", "name", "host_name", "email", "language",
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
124 "url_template", "message_subject", "message_body", "profile"):
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 value = locals()[key]
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 if value:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
127 kwargs[key] = str(value)
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
128 return defer.ensureDeferred(self.create(**kwargs))
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
130 async def create(self, **kwargs):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
131 r"""Create an invitation
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
133 This will create an XMPP account and a profile, and use a UUID to retrieve them.
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
134 The profile is automatically generated in the form guest@@[UUID], this way they
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
135 can be retrieved easily
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
136 **kwargs: keywords arguments which can have the following keys, unset values are
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
137 equivalent to None:
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
138 jid_(jid.JID, None): jid to use for invitation, the jid will be created using
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
139 XEP-0077
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
140 if the jid has no user part, an anonymous account will be used (no XMPP
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
141 account created in this case)
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
142 if None, automatically generate an account name (in the form
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
143 "invitation-[random UUID]@domain.tld") (note that this UUID is not the
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
144 same as the invitation one, as jid can be used publicly (leaking the
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
145 UUID), and invitation UUID give access to account.
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
146 in case of conflict, a suffix number is added to the account until a free
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
147 one if found (with a failure if SUFFIX_MAX is reached)
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
148 password(unicode, None): password to use (will be used for XMPP account and
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
149 profile)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 None to automatically generate one
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 name(unicode, None): name of the invitee
2256
61e836cc9512 plugin invitations: name is now registered as nickname on XMPP server thanks to plugin identity
Goffi <goffi@goffi.org>
parents: 2255
diff changeset
152 will be set as profile identity if present
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 host_name(unicode, None): name of the host
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 email(unicode, None): email to send the invitation to
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
155 if None, no invitation email is sent, you can still associate email using
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
156 extra
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 if email is used, extra can't have "email" key
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
158 language(unicode): language of the invitee (used notabily to translate the
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
159 invitation)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 TODO: not used yet
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 url_template(unicode, None): template to use to construct the invitation URL
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 use {uuid} as a placeholder for identifier
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
163 use None if you don't want to include URL (or if it is already specified
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
164 in custom message)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 /!\ you must put full URL, don't forget https://
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
166 /!\ the URL will give access to the invitee account, you should warn in
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
167 message to not publish it publicly
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
168 message_subject(unicode, None): customised message body for the invitation
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
169 email
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 None to use default subject
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 uses the same substitution as for message_body
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 message_body(unicode, None): customised message body for the invitation email
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 None to use default body
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 use {name} as a place holder for invitee name
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 use {url} as a placeholder for the invitation url
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 use {uuid} as a placeholder for the identifier
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 use {app_name} as a placeholder for this software name
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 use {app_url} as a placeholder for this software official website
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 use {profile} as a placeholder for host's profile
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 use {host_name} as a placeholder for host's name
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 extra(dict, None): extra data to associate with the invitee
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 some keys are reserved:
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 - created (creation date)
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 if email argument is used, "email" key can't be used
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 profile(unicode, None): profile of the host (person who is inviting)
2211
df115e4a36c7 plugin invitations: invitation id and invitee jid are now added to return dict in invitationCreate, bridge signature has changed too
Goffi <goffi@goffi.org>
parents: 2210
diff changeset
186 @return (dict[unicode, unicode]): dictionary with:
df115e4a36c7 plugin invitations: invitation id and invitee jid are now added to return dict in invitationCreate, bridge signature has changed too
Goffi <goffi@goffi.org>
parents: 2210
diff changeset
187 - UUID associated with the invitee (key: id)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 - filled extra dictionary, as saved in the databae
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 """
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 ## initial checks
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 extra = kwargs.pop('extra', {})
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 if set(kwargs).intersection(extra):
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
193 raise ValueError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
194 _("You can't use following key(s) in both args and extra: {}").format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
195 ', '.join(set(kwargs).intersection(extra))))
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
196
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
197 self.checkExtra(extra)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
198
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
199 email = kwargs.pop('email', None)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
200 emails_extra = kwargs.pop('emails_extra', [])
2291
c05000d00dbb plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents: 2256
diff changeset
201 if not email and emails_extra:
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
202 raise ValueError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
203 _('You need to provide a main email address before using emails_extra'))
2255
ba613d32ca60 plugin invitations: doesn't raise an exception anymore if url_template is not set while email is not requested
Goffi <goffi@goffi.org>
parents: 2241
diff changeset
204
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
205 if (email is not None
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
206 and not 'url_template' in kwargs
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
207 and not 'message_body' in kwargs):
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
208 raise ValueError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
209 _("You need to provide url_template if you use default message body"))
2210
f8d61592f1fc plugin invitations: raise ValueError if url_template and message_body are both not specified
Goffi <goffi@goffi.org>
parents: 2208
diff changeset
210
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 ## uuid
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
212 log.info(_("creating an invitation"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
213 id_ = str(shortuuid.uuid())
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
214
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 ## XMPP account creation
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
216 password = kwargs.pop('password', None)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 if password is None:
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 password = utils.generatePassword()
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 assert password
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 # XXX: password is here saved in clear in database
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 # it is needed for invitation as the same password is used for profile
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 # and SàT need to be able to automatically open the profile with the uuid
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 # FIXME: we could add an extra encryption key which would be used with the uuid
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
224 # when the invitee is connecting (e.g. with URL). This key would not be
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
225 # saved and could be used to encrypt profile password.
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
226 extra[KEY_PASSWORD] = password
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
227
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
228 jid_ = kwargs.pop('jid_', None)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 if not jid_:
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 domain = self.host.memory.getConfig(None, 'xmpp_domain')
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 if not domain:
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 # TODO: fallback to profile's domain
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
233 raise ValueError(_("You need to specify xmpp_domain in sat.conf"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
234 jid_ = "invitation-{uuid}@{domain}".format(uuid=shortuuid.uuid(),
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
235 domain=domain)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 jid_ = jid.JID(jid_)
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 if jid_.user:
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
238 # we don't register account if there is no user as anonymous login is then
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
239 # used
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 try:
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
241 await self.host.plugins['XEP-0077'].registerNewAccount(jid_, password)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 except error.StanzaError as e:
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 prefix = jid_.user
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 idx = 0
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
245 while e.condition == 'conflict':
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 if idx >= SUFFIX_MAX:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
247 raise exceptions.ConflictError(_("Can't create XMPP account"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
248 jid_.user = prefix + '_' + str(idx)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
249 log.info(_("requested jid already exists, trying with {}".format(
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
250 jid_.full())))
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 try:
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
252 await self.host.plugins['XEP-0077'].registerNewAccount(jid_,
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
253 password)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
254 except error.StanzaError:
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 idx += 1
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 else:
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 break
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
258 if e.condition != 'conflict':
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 raise e
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
260
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
261 log.info(_("account {jid_} created").format(jid_=jid_.full()))
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 ## profile creation
2256
61e836cc9512 plugin invitations: name is now registered as nickname on XMPP server thanks to plugin identity
Goffi <goffi@goffi.org>
parents: 2255
diff changeset
264
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
265 extra[KEY_GUEST_PROFILE] = guest_profile = INVITEE_PROFILE_TPL.format(uuid=id_)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 # profile creation should not fail as we generate unique name ourselves
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
267 await self.host.memory.createProfile(guest_profile, password)
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
268 await self.host.memory.startSession(password, guest_profile)
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
269 await self.host.memory.setParam("JabberID", jid_.full(), "Connection",
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
270 profile_key=guest_profile)
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
271 await self.host.memory.setParam("Password", password, "Connection",
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
272 profile_key=guest_profile)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
273 name = kwargs.pop('name', None)
2256
61e836cc9512 plugin invitations: name is now registered as nickname on XMPP server thanks to plugin identity
Goffi <goffi@goffi.org>
parents: 2255
diff changeset
274 if name is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
275 extra['name'] = name
2256
61e836cc9512 plugin invitations: name is now registered as nickname on XMPP server thanks to plugin identity
Goffi <goffi@goffi.org>
parents: 2255
diff changeset
276 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
277 id_plugin = self.host.plugins['IDENTITY']
2256
61e836cc9512 plugin invitations: name is now registered as nickname on XMPP server thanks to plugin identity
Goffi <goffi@goffi.org>
parents: 2255
diff changeset
278 except KeyError:
61e836cc9512 plugin invitations: name is now registered as nickname on XMPP server thanks to plugin identity
Goffi <goffi@goffi.org>
parents: 2255
diff changeset
279 pass
61e836cc9512 plugin invitations: name is now registered as nickname on XMPP server thanks to plugin identity
Goffi <goffi@goffi.org>
parents: 2255
diff changeset
280 else:
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
281 await self.host.connect(guest_profile, password)
2256
61e836cc9512 plugin invitations: name is now registered as nickname on XMPP server thanks to plugin identity
Goffi <goffi@goffi.org>
parents: 2255
diff changeset
282 guest_client = self.host.getClient(guest_profile)
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
283 await id_plugin.setIdentity(guest_client, {'nicknames': [name]})
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
284 await self.host.disconnect(guest_profile)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
285
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 ## email
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
287 language = kwargs.pop('language', None)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 if language is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
289 extra['language'] = language.strip()
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
290
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 if email is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
292 extra['email'] = email
2291
c05000d00dbb plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents: 2256
diff changeset
293 data_format.iter2dict(KEY_EMAILS_EXTRA, extra)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
294 url_template = kwargs.pop('url_template', '')
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 format_args = {
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
296 'uuid': id_,
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
297 'app_name': C.APP_NAME,
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
298 'app_url': C.APP_URL}
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
299
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 if name is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
301 format_args['name'] = email
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
303 format_args['name'] = name
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
304
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
305 profile = kwargs.pop('profile', None)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 if profile is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
307 format_args['profile'] = ''
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
309 format_args['profile'] = extra['profile'] = profile
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
310
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
311 host_name = kwargs.pop('host_name', None)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 if host_name is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
313 format_args['host_name'] = profile or _("somebody")
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
315 format_args['host_name'] = extra['host_name'] = host_name
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
316
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 invite_url = url_template.format(**format_args)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
318 format_args['url'] = invite_url
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
319
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
320 await sat_email.sendEmail(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
321 self.host.memory.config,
2291
c05000d00dbb plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents: 2256
diff changeset
322 [email] + emails_extra,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
323 (kwargs.pop('message_subject', None) or DEFAULT_SUBJECT).format(
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
324 **format_args),
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
325 (kwargs.pop('message_body', None) or DEFAULT_BODY).format(**format_args),
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 )
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
327
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
328
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
329 if kwargs:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
330 log.warning(_("Not all arguments have been consumed: {}").format(kwargs))
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
331
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
332 extra[KEY_JID] = jid_.full()
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
333
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
334 ## extra data saving
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
335 self.invitations[id_] = extra
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
336
2211
df115e4a36c7 plugin invitations: invitation id and invitee jid are now added to return dict in invitationCreate, bridge signature has changed too
Goffi <goffi@goffi.org>
parents: 2210
diff changeset
337 extra[KEY_ID] = id_
2212
eaf2467d19ce plugin invitations: added getInvitation method, it return invitation data and raise an error if it is not found
Goffi <goffi@goffi.org>
parents: 2211
diff changeset
338
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
339 return extra
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
340
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
341 def _simpleCreate(self, invitee_email, invitee_name, url_template, extra_s, profile):
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
342 client = self.host.getClient(profile)
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
343 # FIXME: needed because python-dbus use a specific string class
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
344 invitee_email = str(invitee_email)
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
345 invitee_name = str(invitee_name)
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
346 url_template = str(url_template)
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
347 extra = data_format.deserialise(extra_s)
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
348 d = defer.ensureDeferred(
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
349 self.simpleCreate(client, invitee_email, invitee_name, url_template, extra)
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
350 )
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
351 d.addCallback(lambda data: {k: str(v) for k,v in data.items()})
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
352 return d
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
353
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
354 async def simpleCreate(
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
355 self, client, invitee_email, invitee_name, url_template, extra):
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
356 """Simplified method to invite somebody by email"""
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
357 return await self.create(
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
358 name=invitee_name,
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
359 email=invitee_email,
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
360 url_template=url_template,
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
361 profile=client.profile,
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
362 )
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
363
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
364 def get(self, id_):
2212
eaf2467d19ce plugin invitations: added getInvitation method, it return invitation data and raise an error if it is not found
Goffi <goffi@goffi.org>
parents: 2211
diff changeset
365 """Retrieve invitation linked to uuid if it exists
eaf2467d19ce plugin invitations: added getInvitation method, it return invitation data and raise an error if it is not found
Goffi <goffi@goffi.org>
parents: 2211
diff changeset
366
eaf2467d19ce plugin invitations: added getInvitation method, it return invitation data and raise an error if it is not found
Goffi <goffi@goffi.org>
parents: 2211
diff changeset
367 @param id_(unicode): UUID linked to an invitation
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
368 @return (dict[unicode, unicode]): data associated to the invitation
2212
eaf2467d19ce plugin invitations: added getInvitation method, it return invitation data and raise an error if it is not found
Goffi <goffi@goffi.org>
parents: 2211
diff changeset
369 @raise KeyError: there is not invitation with this id_
eaf2467d19ce plugin invitations: added getInvitation method, it return invitation data and raise an error if it is not found
Goffi <goffi@goffi.org>
parents: 2211
diff changeset
370 """
eaf2467d19ce plugin invitations: added getInvitation method, it return invitation data and raise an error if it is not found
Goffi <goffi@goffi.org>
parents: 2211
diff changeset
371 return self.invitations[id_]
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
372
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
373 def _modify(self, id_, new_extra, replace):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
374 return self.modify(id_, {str(k): str(v) for k,v in new_extra.items()},
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
375 replace)
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
376
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
377 def modify(self, id_, new_extra, replace=False):
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
378 """Modify invitation data
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
379
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
380 @param id_(unicode): UUID linked to an invitation
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
381 @param new_extra(dict[unicode, unicode]): data to update
2241
f87b673c7d17 plugin invitations: on modify an empty value delete corresponding extra keys, and reserved keys are now ignored.
Goffi <goffi@goffi.org>
parents: 2230
diff changeset
382 empty values will be deleted if replace is True
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
383 @param replace(bool): if True replace the data
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
384 else update them
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
385 @raise KeyError: there is not invitation with this id_
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
386 """
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
387 self.checkExtra(new_extra)
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
388 def gotCurrentData(current_data):
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
389 if replace:
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
390 new_data = new_extra
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
391 for k in EXTRA_RESERVED:
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
392 try:
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
393 new_data[k] = current_data[k]
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
394 except KeyError:
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
395 continue
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
396 else:
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
397 new_data = current_data
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
398 for k,v in new_extra.items():
2241
f87b673c7d17 plugin invitations: on modify an empty value delete corresponding extra keys, and reserved keys are now ignored.
Goffi <goffi@goffi.org>
parents: 2230
diff changeset
399 if k in EXTRA_RESERVED:
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
400 log.warning(_("Skipping reserved key {key}").format(key=k))
2241
f87b673c7d17 plugin invitations: on modify an empty value delete corresponding extra keys, and reserved keys are now ignored.
Goffi <goffi@goffi.org>
parents: 2230
diff changeset
401 continue
f87b673c7d17 plugin invitations: on modify an empty value delete corresponding extra keys, and reserved keys are now ignored.
Goffi <goffi@goffi.org>
parents: 2230
diff changeset
402 if v:
f87b673c7d17 plugin invitations: on modify an empty value delete corresponding extra keys, and reserved keys are now ignored.
Goffi <goffi@goffi.org>
parents: 2230
diff changeset
403 new_data[k] = v
f87b673c7d17 plugin invitations: on modify an empty value delete corresponding extra keys, and reserved keys are now ignored.
Goffi <goffi@goffi.org>
parents: 2230
diff changeset
404 else:
f87b673c7d17 plugin invitations: on modify an empty value delete corresponding extra keys, and reserved keys are now ignored.
Goffi <goffi@goffi.org>
parents: 2230
diff changeset
405 try:
f87b673c7d17 plugin invitations: on modify an empty value delete corresponding extra keys, and reserved keys are now ignored.
Goffi <goffi@goffi.org>
parents: 2230
diff changeset
406 del new_data[k]
f87b673c7d17 plugin invitations: on modify an empty value delete corresponding extra keys, and reserved keys are now ignored.
Goffi <goffi@goffi.org>
parents: 2230
diff changeset
407 except KeyError:
f87b673c7d17 plugin invitations: on modify an empty value delete corresponding extra keys, and reserved keys are now ignored.
Goffi <goffi@goffi.org>
parents: 2230
diff changeset
408 pass
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
409
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
410 self.invitations[id_] = new_data
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
411
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
412 d = self.invitations[id_]
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
413 d.addCallback(gotCurrentData)
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
414 return d
2230
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
415
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
416 def _list(self, profile=C.PROF_KEY_NONE):
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
417 return defer.ensureDeferred(self.list(profile))
2230
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
418
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
419 async def list(self, profile=C.PROF_KEY_NONE):
2230
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
420 """List invitations
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
421
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
422 @param profile(unicode): return invitation linked to this profile only
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
423 C.PROF_KEY_NONE: don't filter invitations
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
424 @return list(unicode): invitations uids
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
425 """
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
426 invitations = await self.invitations.all()
2230
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
427 if profile != C.PROF_KEY_NONE:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
428 invitations = {id_:data for id_, data in invitations.items()
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
429 if data.get('profile') == profile}
2230
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
430
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
431 return invitations