annotate libervia/backend/plugins/plugin_misc_email_invitation.py @ 4278:240d8b7ad906

component Conferences: implementation of SFU component to make multi-party A/V conferences: This component wrap `Galène` SFU and translate its signaling to XMPP Jingle in both direction. rel 445
author Goffi <goffi@goffi.org>
date Fri, 05 Jul 2024 17:18:37 +0200
parents 0d7bb4df2343
children
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
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3337
diff changeset
4 # Copyright (C) 2009-2021 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
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
20 from typing import Optional
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
21 from twisted.internet import defer
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 jid
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
23 from twisted.words.protocols.jabber import error
3337
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
24 from twisted.words.protocols.jabber import sasl
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
25 from libervia.backend.core.i18n import _, D_
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
26 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
27 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
28 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
29 from libervia.backend.tools import utils
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
30 from libervia.backend.tools.common import data_format
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
31 from libervia.backend.memory import persistent
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
32 from libervia.backend.tools.common import email as sat_email
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
34 log = getLogger(__name__)
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
35
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 PLUGIN_INFO = {
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
38 C.PI_NAME: "Email Invitations",
2912
a3faf1c86596 plugin events: refactored invitation and personal lists logic:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
39 C.PI_IMPORT_NAME: "EMAIL_INVITATION",
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_TYPE: C.PLUG_TYPE_MISC,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
41 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
42 C.PI_RECOMMENDATIONS: ["IDENTITY"],
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 C.PI_MAIN: "InvitationsPlugin",
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 C.PI_HANDLER: "no",
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
45 C.PI_DESCRIPTION: _("""invitation of people without XMPP account"""),
2184
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
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 SUFFIX_MAX = 5
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
50 INVITEE_PROFILE_TPL = "guest@@{uuid}"
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
51 KEY_ID = "id"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
52 KEY_JID = "jid"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
53 KEY_CREATED = "created"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
54 KEY_LAST_CONNECTION = "last_connection"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
55 KEY_GUEST_PROFILE = "guest_profile"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
56 KEY_PASSWORD = "password"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
57 KEY_EMAILS_EXTRA = "emails_extra"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
58 EXTRA_RESERVED = {
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
59 KEY_ID,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
60 KEY_JID,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
61 KEY_CREATED,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
62 "jid_",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
63 "jid",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
64 KEY_LAST_CONNECTION,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
65 KEY_GUEST_PROFILE,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
66 KEY_PASSWORD,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
67 KEY_EMAILS_EXTRA,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
68 }
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
69 DEFAULT_SUBJECT = D_("You have been invited by {host_name} to {app_name}")
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
70 DEFAULT_BODY = D_(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
71 """Hello {name}!
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
72
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 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
74 To join, you just have to click on the following URL:
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 {url}
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 Please note that this URL should not be shared with anybody!
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 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
79
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 Welcome!
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
81 """
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
82 )
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 class InvitationsPlugin(object):
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
88 log.info(_("plugin Invitations initialization"))
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.host = host
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
90 self.invitations = persistent.LazyPersistentBinaryDict("invitations")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
91 host.bridge.add_method(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
92 "invitation_create",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
93 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
94 in_sign="sasssssssssa{ss}s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
95 out_sign="a{ss}",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
96 method=self._create,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
97 async_=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
98 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
99 host.bridge.add_method(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
100 "invitation_get",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
101 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
102 in_sign="s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
103 out_sign="a{ss}",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
104 method=self.get,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
105 async_=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
106 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
107 host.bridge.add_method(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
108 "invitation_delete",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
109 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
110 in_sign="s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
111 out_sign="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
112 method=self._delete,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
113 async_=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
114 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
115 host.bridge.add_method(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
116 "invitation_modify",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
117 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
118 in_sign="sa{ss}b",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
119 out_sign="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
120 method=self._modify,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
121 async_=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
122 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
123 host.bridge.add_method(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
124 "invitation_list",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
125 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
126 in_sign="s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
127 out_sign="a{sa{ss}}",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
128 method=self._list,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
129 async_=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
130 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
131 host.bridge.add_method(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
132 "invitation_simple_create",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
133 ".plugin",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
134 in_sign="sssss",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
135 out_sign="a{ss}",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
136 method=self._simple_create,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
137 async_=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
138 )
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
139
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
140 def check_extra(self, extra):
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
141 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
142 raise ValueError(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
143 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
144 "You can't use following key(s) in extra, they are reserved: {}"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
145 ).format(", ".join(EXTRA_RESERVED.intersection(extra)))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
146 )
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
147
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
148 def _create(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
149 self,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
150 email="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
151 emails_extra=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
152 jid_="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
153 password="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
154 name="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
155 host_name="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
156 language="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
157 url_template="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
158 message_subject="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
159 message_body="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
160 extra=None,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
161 profile="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
162 ):
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
163 # 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
164 # 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
165 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
166 emails_extra = []
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
167
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 if extra is None:
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 extra = {}
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
171 extra = {str(k): str(v) for k, v in extra.items()}
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
172
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
173 kwargs = {"extra": extra, 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
174
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
175 # 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
176 # with D-Bus
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
177 for key in (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
178 "jid_",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
179 "password",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
180 "name",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
181 "host_name",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
182 "email",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
183 "language",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
184 "url_template",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
185 "message_subject",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
186 "message_body",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
187 "profile",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
188 ):
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 value = locals()[key]
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 if value:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
191 kwargs[key] = str(value)
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
192 return defer.ensureDeferred(self.create(**kwargs))
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
193
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
194 async def get_existing_invitation(self, email: Optional[str]) -> Optional[dict]:
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
195 """Retrieve existing invitation with given email
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
196
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
197 @param email: check if any invitation exist with this email
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
198 @return: first found invitation, or None if nothing found
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
199 """
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
200 # FIXME: This method is highly inefficient, it get all invitations and check them
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
201 # one by one, this is just a temporary way to avoid creating creating new accounts
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
202 # for an existing email. A better way will be available with Libervia 0.9.
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
203 # TODO: use a better way to check existing invitations
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
204
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
205 if email is None:
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
206 return None
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
207 all_invitations = await self.invitations.all()
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
208 for id_, invitation in all_invitations.items():
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
209 if invitation.get("email") == email:
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
210 invitation[KEY_ID] = id_
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
211 return invitation
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
212
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
213 async def _create_account_and_profile(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
214 self, id_: str, kwargs: dict, extra: dict
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
215 ) -> None:
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
216 """Create XMPP account and Libervia profile for guest"""
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
217 ## XMPP account creation
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
218 password = kwargs.pop("password", None)
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
219 if password is None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
220 password = utils.generate_password()
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
221 assert password
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
222 # XXX: password is here saved in clear in database
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
223 # it is needed for invitation as the same password is used for profile
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
224 # and SàT need to be able to automatically open the profile with the uuid
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
225 # FIXME: we could add an extra encryption key which would be used with the
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
226 # uuid when the invitee is connecting (e.g. with URL). This key would
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
227 # not be saved and could be used to encrypt profile password.
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
228 extra[KEY_PASSWORD] = password
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
229
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
230 jid_ = kwargs.pop("jid_", None)
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
231 if not jid_:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
232 domain = self.host.memory.config_get(None, "xmpp_domain")
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
233 if not domain:
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
234 # TODO: fallback to profile's domain
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
235 raise ValueError(_("You need to specify xmpp_domain in sat.conf"))
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
236 jid_ = "invitation-{uuid}@{domain}".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
237 uuid=shortuuid.uuid(), domain=domain
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
238 )
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
239 jid_ = jid.JID(jid_)
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
240 extra[KEY_JID] = jid_.full()
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
241
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
242 if jid_.user:
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
243 # we don't register account if there is no user as anonymous login is then
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
244 # used
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
245 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
246 await self.host.plugins["XEP-0077"].register_new_account(jid_, password)
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
247 except error.StanzaError as e:
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
248 prefix = jid_.user
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
249 idx = 0
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
250 while e.condition == "conflict":
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
251 if idx >= SUFFIX_MAX:
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
252 raise exceptions.ConflictError(_("Can't create XMPP account"))
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
253 jid_.user = prefix + "_" + str(idx)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
254 log.info(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
255 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
256 "requested jid already exists, trying with {}".format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
257 jid_.full()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
258 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
259 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
260 )
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
261 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
262 await self.host.plugins["XEP-0077"].register_new_account(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
263 jid_, password
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
264 )
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
265 except error.StanzaError:
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
266 idx += 1
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
267 else:
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
268 break
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
269 if e.condition != "conflict":
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
270 raise e
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
271
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
272 log.info(_("account {jid_} created").format(jid_=jid_.full()))
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
273
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
274 ## profile creation
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
275
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
276 extra[KEY_GUEST_PROFILE] = guest_profile = INVITEE_PROFILE_TPL.format(uuid=id_)
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
277 # profile creation should not fail as we generate unique name ourselves
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
278 await self.host.memory.create_profile(guest_profile, password)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
279 await self.host.memory.start_session(password, guest_profile)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
280 await self.host.memory.param_set(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
281 "JabberID", jid_.full(), "Connection", profile_key=guest_profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
282 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
283 await self.host.memory.param_set(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
284 "Password", password, "Connection", profile_key=guest_profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
285 )
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
286
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
287 async def create(self, **kwargs):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
288 r"""Create an invitation
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
289
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
290 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
291 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
292 can be retrieved easily
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
293 **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
294 equivalent to None:
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
295 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
296 XEP-0077
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
297 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
298 account created in this case)
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
299 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
300 "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
301 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
302 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
303 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
304 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
305 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
306 profile)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 None to automatically generate one
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 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
309 will be set as profile identity if present
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 host_name(unicode, None): name of the host
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 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
312 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
313 extra
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 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
315 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
316 invitation)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 TODO: not used yet
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 url_template(unicode, None): template to use to construct the invitation URL
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 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
320 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
321 in custom message)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 /!\ 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
323 /!\ 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
324 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
325 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
326 email
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 None to use default subject
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
328 uses the same substitution as for message_body
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
329 message_body(unicode, None): customised message body for the invitation email
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 None to use default body
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
331 use {name} as a place holder for invitee name
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
332 use {url} as a placeholder for the invitation url
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
333 use {uuid} as a placeholder for the identifier
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
334 use {app_name} as a placeholder for this software name
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
335 use {app_url} as a placeholder for this software official website
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 use {profile} as a placeholder for host's profile
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 use {host_name} as a placeholder for host's name
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 extra(dict, None): extra data to associate with the invitee
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 some keys are reserved:
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 - created (creation date)
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 if email argument is used, "email" key can't be used
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 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
343 @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
344 - UUID associated with the invitee (key: id)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 - filled extra dictionary, as saved in the databae
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 """
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 ## initial checks
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
348 extra = kwargs.pop("extra", {})
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 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
350 raise ValueError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
351 _("You can't use following key(s) in both args and extra: {}").format(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
352 ", ".join(set(kwargs).intersection(extra))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
353 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
354 )
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
355
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
356 self.check_extra(extra)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
357
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
358 email = kwargs.pop("email", None)
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
359
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
360 existing = await self.get_existing_invitation(email)
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
361 if existing is not None:
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
362 log.info(f"There is already an invitation for {email!r}")
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
363 extra.update(existing)
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
364 del extra[KEY_ID]
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
365
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
366 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
367 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
368 raise ValueError(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
369 _("You need to provide a main email address before using emails_extra")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
370 )
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
371
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
372 if (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
373 email is not None
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
374 and not "url_template" in kwargs
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
375 and not "message_body" in kwargs
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
376 ):
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
377 raise ValueError(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
378 _("You need to provide url_template if you use default message body")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
379 )
2210
f8d61592f1fc plugin invitations: raise ValueError if url_template and message_body are both not specified
Goffi <goffi@goffi.org>
parents: 2208
diff changeset
380
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
381 ## uuid
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
382 log.info(_("creating an invitation"))
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
383 id_ = existing[KEY_ID] if existing else str(shortuuid.uuid())
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
384
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
385 if existing is None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
386 await self._create_account_and_profile(id_, kwargs, extra)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
387
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
388 profile = kwargs.pop("profile", None)
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
389 guest_profile = extra[KEY_GUEST_PROFILE]
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
390 jid_ = jid.JID(extra[KEY_JID])
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
391
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
392 ## identity
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
393 name = kwargs.pop("name", None)
3700
cfc06915de15 plugin email invitations: re-use existing invitation for a given email:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
394 password = extra[KEY_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
395 if name is not None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
396 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
397 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
398 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
399 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
400 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
401 else:
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
402 await self.host.connect(guest_profile, password)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
403 guest_client = self.host.get_client(guest_profile)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
404 await id_plugin.set_identity(guest_client, {"nicknames": [name]})
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
405 await self.host.disconnect(guest_profile)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
406
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
407 ## email
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
408 language = kwargs.pop("language", None)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
409 if language is not None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
410 extra["language"] = language.strip()
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
411
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
412 if email is not None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
413 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
414 data_format.iter2dict(KEY_EMAILS_EXTRA, extra)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
415 url_template = kwargs.pop("url_template", "")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
416 format_args = {"uuid": id_, "app_name": C.APP_NAME, "app_url": C.APP_URL}
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
417
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
418 if name is None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
419 format_args["name"] = email
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
420 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
421 format_args["name"] = name
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
422
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
423 if profile is None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
424 format_args["profile"] = ""
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
425 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
426 format_args["profile"] = extra["profile"] = profile
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
427
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
428 host_name = kwargs.pop("host_name", None)
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
429 if host_name is None:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
430 format_args["host_name"] = profile or _("somebody")
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
431 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
432 format_args["host_name"] = extra["host_name"] = host_name
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
433
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
434 invite_url = url_template.format(**format_args)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
435 format_args["url"] = invite_url
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
436
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
437 await sat_email.send_email(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
438 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
439 [email] + emails_extra,
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
440 (kwargs.pop("message_subject", None) or DEFAULT_SUBJECT).format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
441 **format_args
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
442 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
443 (kwargs.pop("message_body", None) or DEFAULT_BODY).format(**format_args),
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
444 )
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
445
3336
e38ddaf477bd plugin email invitation: guests are now automatically added to host roster in `guests` group
Goffi <goffi@goffi.org>
parents: 3335
diff changeset
446 ## roster
e38ddaf477bd plugin email invitation: guests are now automatically added to host roster in `guests` group
Goffi <goffi@goffi.org>
parents: 3335
diff changeset
447
e38ddaf477bd plugin email invitation: guests are now automatically added to host roster in `guests` group
Goffi <goffi@goffi.org>
parents: 3335
diff changeset
448 # we automatically add guest to host roster (if host is specified)
e38ddaf477bd plugin email invitation: guests are now automatically added to host roster in `guests` group
Goffi <goffi@goffi.org>
parents: 3335
diff changeset
449 # FIXME: a parameter to disable auto roster adding would be nice
e38ddaf477bd plugin email invitation: guests are now automatically added to host roster in `guests` group
Goffi <goffi@goffi.org>
parents: 3335
diff changeset
450 if profile is not None:
e38ddaf477bd plugin email invitation: guests are now automatically added to host roster in `guests` group
Goffi <goffi@goffi.org>
parents: 3335
diff changeset
451 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
452 client = self.host.get_client(profile)
3336
e38ddaf477bd plugin email invitation: guests are now automatically added to host roster in `guests` group
Goffi <goffi@goffi.org>
parents: 3335
diff changeset
453 except Exception as e:
e38ddaf477bd plugin email invitation: guests are now automatically added to host roster in `guests` group
Goffi <goffi@goffi.org>
parents: 3335
diff changeset
454 log.error(f"Can't get host profile: {profile}: {e}")
e38ddaf477bd plugin email invitation: guests are now automatically added to host roster in `guests` group
Goffi <goffi@goffi.org>
parents: 3335
diff changeset
455 else:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
456 await self.host.contact_update(client, jid_, name, ["guests"])
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
457
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
458 if kwargs:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3007
diff changeset
459 log.warning(_("Not all arguments have been consumed: {}").format(kwargs))
2184
e0f91efa404a plugin invitations: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
460
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
461 ## extra data saving
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
462 self.invitations[id_] = extra
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
463
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
464 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
465
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
466 return extra
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
467
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
468 def _simple_create(self, invitee_email, invitee_name, url_template, extra_s, profile):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
469 client = self.host.get_client(profile)
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
470 # 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
471 invitee_email = str(invitee_email)
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
472 invitee_name = str(invitee_name)
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
473 url_template = str(url_template)
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
474 extra = data_format.deserialise(extra_s)
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
475 d = defer.ensureDeferred(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
476 self.simple_create(client, invitee_email, invitee_name, url_template, extra)
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
477 )
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
478 d.addCallback(lambda data: {k: str(v) for k, v in data.items()})
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
479 return d
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
480
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
481 async def simple_create(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
482 self, client, invitee_email, invitee_name, url_template, extra
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
483 ):
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
484 """Simplified method to invite somebody by email"""
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
485 return await self.create(
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
486 name=invitee_name,
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
487 email=invitee_email,
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
488 url_template=url_template,
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
489 profile=client.profile,
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
490 )
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
491
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
492 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
493 """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
494
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
495 @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
496 @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
497 @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
498 """
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
499 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
500
3337
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
501 def _delete(self, id_):
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
502 return defer.ensureDeferred(self.delete(id_))
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
503
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
504 async def delete(self, id_):
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
505 """Delete an invitation data and associated XMPP account"""
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
506 log.info(f"deleting invitation {id_}")
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
507 data = await self.get(id_)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
508 guest_profile = data["guest_profile"]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
509 password = data["password"]
3337
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
510 try:
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
511 await self.host.connect(guest_profile, password)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
512 guest_client = self.host.get_client(guest_profile)
3337
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
513 # XXX: be extra careful to use guest_client and not client below, as this will
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
514 # delete the associated XMPP account
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
515 log.debug("deleting XMPP account")
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
516 await self.host.plugins["XEP-0077"].unregister(guest_client, None)
3337
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
517 except (error.StanzaError, sasl.SASLAuthError) as e:
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
518 log.warning(
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
519 f"Can't delete {guest_profile}'s XMPP account, maybe it as already been "
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
520 f"deleted: {e}"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
521 )
3337
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
522 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
523 await self.host.memory.profile_delete_async(guest_profile, True)
3337
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
524 except Exception as e:
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
525 log.warning(f"Can't delete guest profile {guest_profile}: {e}")
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
526 log.debug("removing guest data")
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
527 await self.invitations.adel(id_)
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
528 log.info(f"{id_} invitation has been deleted")
932cf08dfdc3 plugin email invitation: new `invitationDelete` method
Goffi <goffi@goffi.org>
parents: 3336
diff changeset
529
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
530 def _modify(self, id_, new_extra, replace):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
531 return self.modify(id_, {str(k): str(v) for k, v in new_extra.items()}, replace)
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
532
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
533 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
534 """Modify invitation data
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
535
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
536 @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
537 @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
538 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
539 @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
540 else update them
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
541 @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
542 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
543 self.check_extra(new_extra)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
544
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
545 def got_current_data(current_data):
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
546 if replace:
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
547 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
548 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
549 try:
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
550 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
551 except KeyError:
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
552 continue
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
553 else:
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
554 new_data = current_data
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
555 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
556 if k in EXTRA_RESERVED:
3323
44a9438d6608 plugin email invitation: simple invitation creation
Goffi <goffi@goffi.org>
parents: 3253
diff changeset
557 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
558 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
559 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
560 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
561 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
562 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
563 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
564 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
565 pass
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
566
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
567 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
568
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
569 d = self.invitations[id_]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3700
diff changeset
570 d.addCallback(got_current_data)
2219
77a3d0a28642 plugin invitations: added modify method (+ bridge) and fixed email setting in extra
Goffi <goffi@goffi.org>
parents: 2212
diff changeset
571 return d
2230
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
572
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
573 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
574 return defer.ensureDeferred(self.list(profile))
2230
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
575
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
576 async def list(self, profile=C.PROF_KEY_NONE):
2230
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
577 """List invitations
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
578
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
579 @param profile(unicode): return invitation linked to this profile only
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
580 C.PROF_KEY_NONE: don't filter invitations
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
581 @return list(unicode): invitations uids
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
582 """
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
583 invitations = await self.invitations.all()
2230
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
584 if profile != C.PROF_KEY_NONE:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
585 invitations = {
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
586 id_: data
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
587 for id_, data in invitations.items()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
588 if data.get("profile") == profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
589 }
2230
ebc0c1701811 plugin invitations: added invitationList command
Goffi <goffi@goffi.org>
parents: 2223
diff changeset
590
3335
83bc9d46a417 plugin email invitation: fixed create/simpleCreate + invitee_name:
Goffi <goffi@goffi.org>
parents: 3323
diff changeset
591 return invitations