Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_invitation.py @ 3732:0fac164ff2d8
tools (xml_tools): fix `widget_args` modification in `_dataFormField2XMLUIData`:
in `textbox` widget, the first arg was modified with all values, lettings other ones
unchanger, resulting in invalid number of arguments. This has been fixed by replacing all
args with the new value.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 31 Jan 2022 18:35:52 +0100 |
parents | 04283582966f |
children | 524856bd7b19 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # jp: a SàT command line tool |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
3028 | 21 from . import base |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core.i18n import _ |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat_frontends.jp.constants import Const as C |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
24 from sat.tools.common.ansi import ANSI as A |
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:
2285
diff
changeset
|
25 from sat.tools.common import data_format |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 __commands__ = ["Invitation"] |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 class Create(base.CommandBase): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
32 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
33 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
34 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
35 "create", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
36 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
37 use_output=C.OUTPUT_DICT, |
3028 | 38 help=_("create and send an invitation"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
42 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 "-j", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
44 "--jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
45 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 help="jid of the invitee (default: generate one)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
47 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 "-P", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 "--password", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 help="password of the invitee profile/XMPP account (default: generate one)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 "--name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 help="name of the invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
61 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 "--host-name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 help="name of the host", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 "-e", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 "--email", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 help="email(s) to send the invitation to (if --no-email is set, email will just be saved)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 "--no-email", action="store_true", help="do NOT send invitation email" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
76 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 "-l", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
78 "--lang", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
79 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 help="main language spoken by the invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
82 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
83 "-u", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
84 "--url", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
85 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
86 help="template to construct the URL", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
87 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
88 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
89 "-s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
90 "--subject", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
91 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 help="subject of the invitation email (default: generic subject)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
93 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 "-b", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 "--body", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
97 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
98 help="body of the invitation email (default: generic body)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
99 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
100 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
101 "-x", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 "--extra", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 metavar=("KEY", "VALUE"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
107 help="extra data to associate with invitation/invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
108 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
109 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
110 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
111 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
112 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 help="profile doing the invitation (default: don't associate profile)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
3040 | 116 async def start(self): |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 extra = dict(self.args.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:
2285
diff
changeset
|
118 email = self.args.email[0] if self.args.email else 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:
2285
diff
changeset
|
119 emails_extra = self.args.email[1:] |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 if self.args.no_email: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 if email: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 extra["email"] = email |
3028 | 123 data_format.iter2dict("emails_extra", emails_extra) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 else: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 if not email: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 self.parser.error( |
3028 | 127 _("you need to specify an email address to send email invitation") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
128 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
3040 | 130 try: |
131 invitation_data = await self.host.bridge.invitationCreate( | |
132 email, | |
133 emails_extra, | |
134 self.args.jid, | |
135 self.args.password, | |
136 self.args.name, | |
137 self.args.host_name, | |
138 self.args.lang, | |
139 self.args.url, | |
140 self.args.subject, | |
141 self.args.body, | |
142 extra, | |
143 self.args.profile, | |
144 ) | |
145 except Exception as e: | |
146 self.disp(f"can't create invitation: {e}", error=True) | |
147 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
148 else: | |
149 await self.output(invitation_data) | |
150 self.host.quit(C.EXIT_OK) | |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 class Get(base.CommandBase): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
155 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
156 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
157 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
158 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
159 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
160 use_output=C.OUTPUT_DICT, |
3028 | 161 help=_("get invitation data"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
162 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 def add_parser_options(self): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
165 self.parser.add_argument("id", help=_("invitation UUID")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
166 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
167 "-j", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
168 "--with-jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 action="store_true", |
3028 | 170 help=_("start profile session and retrieve jid"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 |
3040 | 173 async def output_data(self, data, jid_=None): |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 if jid_ is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
175 data["jid"] = jid_ |
3040 | 176 await self.output(data) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 self.host.quit() |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 |
3040 | 179 async def start(self): |
180 try: | |
181 invitation_data = await self.host.bridge.invitationGet( | |
182 self.args.id, | |
183 ) | |
184 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
185 self.disp(msg=_("can't get invitation data: {e}").format(e=e), error=True) |
3040 | 186 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
187 | |
188 if not self.args.with_jid: | |
189 await self.output_data(invitation_data) | |
190 else: | |
3028 | 191 profile = invitation_data["guest_profile"] |
3040 | 192 try: |
193 await self.host.bridge.profileStartSession( | |
194 invitation_data["password"], | |
195 profile, | |
196 ) | |
197 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
198 self.disp(msg=_("can't start session: {e}").format(e=e), error=True) |
3040 | 199 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
200 |
3040 | 201 try: |
202 jid_ = await self.host.bridge.asyncGetParamA( | |
3028 | 203 "JabberID", |
204 "Connection", | |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 profile_key=profile, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
206 ) |
3040 | 207 except Exception as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
208 self.disp(msg=_("can't retrieve jid: {e}").format(e=e), error=True) |
3040 | 209 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 |
3040 | 211 await self.output_data(invitation_data, jid_) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 |
3339
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
214 class Delete(base.CommandBase): |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
215 def __init__(self, host): |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
216 base.CommandBase.__init__( |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
217 self, |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
218 host, |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
219 "delete", |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
220 use_profile=False, |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
221 help=_("delete guest account"), |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
222 ) |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
223 |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
224 def add_parser_options(self): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
225 self.parser.add_argument("id", help=_("invitation UUID")) |
3339
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
226 |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
227 async def start(self): |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
228 try: |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
229 await self.host.bridge.invitationDelete( |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
230 self.args.id, |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
231 ) |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
232 except Exception as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
233 self.disp(msg=_("can't delete guest account: {e}").format(e=e), error=True) |
3339
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
234 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
235 |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
236 self.host.quit() |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
237 |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
238 |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
239 class Modify(base.CommandBase): |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
240 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
241 base.CommandBase.__init__( |
3028 | 242 self, host, "modify", use_profile=False, help=_("modify existing invitation") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
243 ) |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
244 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
245 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
246 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
247 "--replace", action="store_true", help="replace the whole data" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
248 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
249 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
250 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
251 "--name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
252 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
253 help="name of the invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
254 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
255 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
256 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
257 "--host-name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
258 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
259 help="name of the host", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
260 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
261 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
262 "-e", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
263 "--email", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
264 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
265 help="email to send the invitation to (if --no-email is set, email will just be saved)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
266 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
267 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
268 "-l", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
269 "--lang", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
270 dest="language", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
271 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
272 help="main language spoken by the invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
274 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
275 "-x", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
276 "--extra", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
277 metavar=("KEY", "VALUE"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
279 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
280 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
281 help="extra data to associate with invitation/invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
282 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
283 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
284 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
285 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
286 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
287 help="profile doing the invitation (default: don't associate profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
288 ) |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
289 self.parser.add_argument("id", help=_("invitation UUID")) |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
290 |
3040 | 291 async def start(self): |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
292 extra = dict(self.args.extra) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
293 for arg_name in ("name", "host_name", "email", "language", "profile"): |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
294 value = getattr(self.args, arg_name) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
295 if not value: |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
296 continue |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
297 if arg_name in extra: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
298 self.parser.error( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
299 _( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
300 "you can't set {arg_name} in both optional argument and extra" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
301 ).format(arg_name=arg_name) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
302 ) |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
303 extra[arg_name] = value |
3040 | 304 try: |
305 await self.host.bridge.invitationModify( | |
306 self.args.id, | |
307 extra, | |
308 self.args.replace, | |
309 ) | |
310 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
311 self.disp(f"can't modify invitation: {e}", error=True) |
3040 | 312 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
313 else: | |
314 self.disp(_("invitations have been modified successfuly")) | |
315 self.host.quit(C.EXIT_OK) | |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
316 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
317 |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
318 class List(base.CommandBase): |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
319 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
320 extra_outputs = {"default": self.default_output} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
321 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
322 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
323 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
324 "list", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
325 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
326 use_output=C.OUTPUT_COMPLEX, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
327 extra_outputs=extra_outputs, |
3028 | 328 help=_("list invitations data"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
329 ) |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
330 |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
331 def default_output(self, data): |
3028 | 332 for idx, datum in enumerate(data.items()): |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
333 if idx: |
3028 | 334 self.disp("\n") |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
335 key, invitation_data = datum |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
336 self.disp(A.color(C.A_HEADER, key)) |
3028 | 337 indent = " " |
338 for k, v in invitation_data.items(): | |
339 self.disp(indent + A.color(C.A_SUBHEADER, k + ":") + " " + str(v)) | |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
340 |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
341 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
342 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
343 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
344 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
345 default=C.PROF_KEY_NONE, |
3028 | 346 help=_("return only invitations linked to this profile"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
347 ) |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
348 |
3040 | 349 async def start(self): |
350 try: | |
351 data = await self.host.bridge.invitationList( | |
352 self.args.profile, | |
353 ) | |
354 except Exception as e: | |
355 self.disp(f"return only invitations linked to this profile: {e}", error=True) | |
356 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
357 else: | |
358 await self.output(data) | |
359 self.host.quit() | |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
360 |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
361 |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 class Invitation(base.CommandBase): |
3339
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
363 subcommands = (Create, Get, Delete, Modify, List) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
366 super(Invitation, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
367 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
368 "invitation", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
369 use_profile=False, |
3028 | 370 help=_("invitation of user(s) without XMPP account"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
371 ) |