Mercurial > libervia-backend
annotate sat/plugins/plugin_misc_lists.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 | 5f65f4e9f8cb |
children | 6c36eb30afb8 |
rev | line source |
---|---|
3458 | 1 #!/usr/bin/env python3 |
2 | |
3479 | 3 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
3458 | 4 |
5 # This program is free software: you can redistribute it and/or modify | |
6 # it under the terms of the GNU Affero General Public License as published by | |
7 # the Free Software Foundation, either version 3 of the License, or | |
8 # (at your option) any later version. | |
9 | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU Affero General Public License for more details. | |
14 | |
15 # You should have received a copy of the GNU Affero General Public License | |
16 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | |
3460 | 18 import shortuuid |
3463
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
19 from typing import List, Tuple, Optional |
3460 | 20 from twisted.internet import defer |
21 from twisted.words.xish import domish | |
22 from twisted.words.protocols.jabber import jid | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
23 from sat.core.i18n import _, D_ |
3463
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
24 from sat.core.xmpp import SatXMPPEntity |
3458 | 25 from sat.core.constants import Const as C |
3472
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
26 from sat.tools import xml_tools |
3458 | 27 from sat.tools.common import uri |
3460 | 28 from sat.tools.common import data_format |
3458 | 29 from sat.core.log import getLogger |
30 | |
31 log = getLogger(__name__) | |
32 | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
33 # XXX: this plugin was formely named "tickets", thus the namespace keeps this |
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
34 # name |
3458 | 35 APP_NS_TICKETS = "org.salut-a-toi.tickets:0" |
3460 | 36 NS_TICKETS_TYPE = "org.salut-a-toi.tickets#type:0" |
3458 | 37 |
38 PLUGIN_INFO = { | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
39 C.PI_NAME: _("Pubsub Lists"), |
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
40 C.PI_IMPORT_NAME: "LISTS", |
3458 | 41 C.PI_TYPE: "EXP", |
42 C.PI_PROTOCOLS: [], | |
3463
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
43 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0346", "XEP-0277", "IDENTITY", |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
44 "PUBSUB_INVITATION"], |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
45 C.PI_MAIN: "PubsubLists", |
3458 | 46 C.PI_HANDLER: "no", |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
47 C.PI_DESCRIPTION: _("""Pubsub lists management plugin"""), |
3458 | 48 } |
49 | |
3460 | 50 TEMPLATES = { |
51 "todo": { | |
52 "name": D_("TODO List"), | |
53 "icon": "check", | |
54 "fields": [ | |
55 {"name": "title"}, | |
56 {"name": "author"}, | |
57 {"name": "created"}, | |
58 {"name": "updated"}, | |
59 {"name": "time_limit"}, | |
60 {"name": "labels", "type": "text-multi"}, | |
61 { | |
62 "name": "status", | |
63 "label": D_("status"), | |
64 "type": "list-single", | |
65 "options": [ | |
66 { | |
67 "label": D_("to do"), | |
68 "value": "todo" | |
69 }, | |
70 { | |
71 "label": D_("in progress"), | |
72 "value": "in_progress" | |
73 }, | |
74 { | |
75 "label": D_("done"), | |
76 "value": "done" | |
77 }, | |
78 ], | |
79 "value": "todo" | |
80 }, | |
81 { | |
82 "name": "priority", | |
83 "label": D_("priority"), | |
84 "type": "list-single", | |
85 "options": [ | |
86 { | |
87 "label": D_("major"), | |
88 "value": "major" | |
89 }, | |
90 { | |
91 "label": D_("normal"), | |
92 "value": "normal" | |
93 }, | |
94 { | |
95 "label": D_("minor"), | |
96 "value": "minor" | |
97 }, | |
98 ], | |
99 "value": "normal" | |
100 }, | |
101 {"name": "body", "type": "xhtml"}, | |
102 {"name": "comments_uri"}, | |
103 ] | |
104 }, | |
3470
ca76767185e3
plugin list: rename `shopping` list to `grocery` list
Goffi <goffi@goffi.org>
parents:
3469
diff
changeset
|
105 "grocery": { |
ca76767185e3
plugin list: rename `shopping` list to `grocery` list
Goffi <goffi@goffi.org>
parents:
3469
diff
changeset
|
106 "name": D_("Grocery List"), |
3460 | 107 "icon": "basket", |
108 "fields": [ | |
109 {"name": "name", "label": D_("name")}, | |
110 {"name": "quantity", "label": D_("quantity")}, | |
111 { | |
112 "name": "status", | |
113 "label": D_("status"), | |
114 "type": "list-single", | |
115 "options": [ | |
116 { | |
117 "label": D_("to buy"), | |
118 "value": "to_buy" | |
119 }, | |
120 { | |
121 "label": D_("bought"), | |
122 "value": "bought" | |
123 }, | |
124 ], | |
125 "value": "to_buy" | |
126 }, | |
127 ] | |
128 }, | |
129 "tickets": { | |
130 "name": D_("Tickets"), | |
131 "icon": "clipboard", | |
132 "fields": [ | |
133 {"name": "title"}, | |
134 {"name": "author"}, | |
135 {"name": "created"}, | |
136 {"name": "updated"}, | |
137 {"name": "labels", "type": "text-multi"}, | |
138 { | |
139 "name": "type", | |
140 "label": D_("type"), | |
141 "type": "list-single", | |
142 "options": [ | |
143 { | |
144 "label": D_("bug"), | |
145 "value": "bug" | |
146 }, | |
147 { | |
148 "label": D_("feature request"), | |
149 "value": "feature" | |
150 }, | |
151 ], | |
152 "value": "bug" | |
153 }, | |
154 { | |
155 "name": "status", | |
156 "label": D_("status"), | |
157 "type": "list-single", | |
158 "options": [ | |
159 { | |
160 "label": D_("queued"), | |
161 "value": "queued" | |
162 }, | |
163 { | |
164 "label": D_("started"), | |
165 "value": "started" | |
166 }, | |
167 { | |
168 "label": D_("review"), | |
169 "value": "review" | |
170 }, | |
171 { | |
172 "label": D_("closed"), | |
173 "value": "closed" | |
174 }, | |
175 ], | |
176 "value": "queued" | |
177 }, | |
178 { | |
179 "name": "priority", | |
180 "label": D_("priority"), | |
181 "type": "list-single", | |
182 "options": [ | |
183 { | |
184 "label": D_("major"), | |
185 "value": "major" | |
186 }, | |
187 { | |
188 "label": D_("normal"), | |
189 "value": "normal" | |
190 }, | |
191 { | |
192 "label": D_("minor"), | |
193 "value": "minor" | |
194 }, | |
195 ], | |
196 "value": "normal" | |
197 }, | |
198 {"name": "body", "type": "xhtml"}, | |
199 {"name": "comments_uri"}, | |
200 ] | |
201 } | |
202 } | |
203 | |
3458 | 204 |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
205 class PubsubLists: |
3458 | 206 |
207 def __init__(self, host): | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
208 log.info(_("Pubsub lists plugin initialization")) |
3458 | 209 self.host = host |
210 self._s = self.host.plugins["XEP-0346"] | |
211 self.namespace = self._s.getSubmittedNS(APP_NS_TICKETS) | |
3461
02a8d227d5bb
plugin misc lists: register app NS for "tickets" NS instead of XEP-0346 submitted one
Goffi <goffi@goffi.org>
parents:
3460
diff
changeset
|
212 host.registerNamespace("tickets", APP_NS_TICKETS) |
3469
c063cbb2ad6e
plugin lists: register `tickets_type` namespace
Goffi <goffi@goffi.org>
parents:
3464
diff
changeset
|
213 host.registerNamespace("tickets_type", NS_TICKETS_TYPE) |
3463
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
214 self.host.plugins["PUBSUB_INVITATION"].register( |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
215 APP_NS_TICKETS, self |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
216 ) |
3458 | 217 self._p = self.host.plugins["XEP-0060"] |
218 self._m = self.host.plugins["XEP-0277"] | |
219 host.bridge.addMethod( | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
220 "listGet", |
3458 | 221 ".plugin", |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3508
diff
changeset
|
222 in_sign="ssiassss", |
3458 | 223 out_sign="s", |
224 method=lambda service, node, max_items, items_ids, sub_id, extra, profile_key: | |
225 self._s._get( | |
226 service, | |
227 node, | |
228 max_items, | |
229 items_ids, | |
230 sub_id, | |
231 extra, | |
232 default_node=self.namespace, | |
233 form_ns=APP_NS_TICKETS, | |
234 filters={ | |
235 "author": self._s.valueOrPublisherFilter, | |
236 "created": self._s.dateFilter, | |
237 "updated": self._s.dateFilter, | |
3460 | 238 "time_limit": self._s.dateFilter, |
3458 | 239 }, |
240 profile_key=profile_key), | |
241 async_=True, | |
242 ) | |
243 host.bridge.addMethod( | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
244 "listSet", |
3458 | 245 ".plugin", |
246 in_sign="ssa{sas}ssss", | |
247 out_sign="s", | |
248 method=self._set, | |
249 async_=True, | |
250 ) | |
251 host.bridge.addMethod( | |
3508
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
252 "listDeleteItem", |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
253 ".plugin", |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
254 in_sign="sssbs", |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
255 out_sign="", |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
256 method=self._delete, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
257 async_=True, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
258 ) |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
259 host.bridge.addMethod( |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
260 "listSchemaGet", |
3458 | 261 ".plugin", |
262 in_sign="sss", | |
263 out_sign="s", | |
264 method=lambda service, nodeIdentifier, profile_key: self._s._getUISchema( | |
265 service, nodeIdentifier, default_node=self.namespace, | |
266 profile_key=profile_key), | |
267 async_=True, | |
268 ) | |
3460 | 269 host.bridge.addMethod( |
3464
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
270 "listsList", |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
271 ".plugin", |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
272 in_sign="sss", |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
273 out_sign="s", |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
274 method=self._listsList, |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
275 async_=True, |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
276 ) |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
277 host.bridge.addMethod( |
3460 | 278 "listTemplatesNamesGet", |
279 ".plugin", | |
280 in_sign="ss", | |
281 out_sign="s", | |
282 method=self._getTemplatesNames, | |
283 ) | |
284 host.bridge.addMethod( | |
285 "listTemplateGet", | |
286 ".plugin", | |
287 in_sign="sss", | |
288 out_sign="s", | |
289 method=self._getTemplate, | |
290 ) | |
291 host.bridge.addMethod( | |
292 "listTemplateCreate", | |
293 ".plugin", | |
294 in_sign="ssss", | |
295 out_sign="(ss)", | |
296 method=self._createTemplate, | |
297 async_=True, | |
298 ) | |
3458 | 299 |
3463
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
300 async def onInvitationPreflight( |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
301 self, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
302 client: SatXMPPEntity, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
303 namespace: str, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
304 name: str, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
305 extra: dict, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
306 service: jid.JID, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
307 node: str, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
308 item_id: Optional[str], |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
309 item_elt: domish.Element |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
310 ) -> None: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
311 try: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
312 schema = await self._s.getSchemaForm(client, service, node) |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
313 except Exception as e: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
314 log.warning(f"Can't retrive node schema as {node!r} [{service}]: {e}") |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
315 else: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
316 try: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
317 field_type = schema[NS_TICKETS_TYPE] |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
318 except KeyError: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
319 log.debug("no type found in list schema") |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
320 else: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
321 list_elt = extra["element"] = domish.Element((APP_NS_TICKETS, "list")) |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
322 list_elt["type"] = field_type |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
323 |
3458 | 324 def _set(self, service, node, values, schema=None, item_id=None, extra='', |
325 profile_key=C.PROF_KEY_NONE): | |
326 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet( | |
327 service, node, schema, item_id, extra, profile_key | |
328 ) | |
329 d = defer.ensureDeferred(self.set( | |
330 client, service, node, values, schema, item_id, extra, deserialise=True | |
331 )) | |
332 d.addCallback(lambda ret: ret or "") | |
333 return d | |
334 | |
3460 | 335 async def set( |
336 self, client, service, node, values, schema=None, item_id=None, extra=None, | |
337 deserialise=False, form_ns=APP_NS_TICKETS | |
338 ): | |
3458 | 339 """Publish a tickets |
340 | |
341 @param node(unicode, None): Pubsub node to use | |
342 None to use default tickets node | |
343 @param values(dict[key(unicode), [iterable[object]|object]]): values of the ticket | |
344 | |
345 if value is not iterable, it will be put in a list | |
346 'created' and 'updated' will be forced to current time: | |
347 - 'created' is set if item_id is None, i.e. if it's a new ticket | |
348 - 'updated' is set everytime | |
349 @param extra(dict, None): same as for [XEP-0060.sendItem] with additional keys: | |
350 - update(bool): if True, get previous item data to merge with current one | |
3508
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
351 if True, item_id must be set |
3458 | 352 other arguments are same as for [self._s.sendDataFormItem] |
353 @return (unicode): id of the created item | |
354 """ | |
355 if not node: | |
356 node = self.namespace | |
357 | |
358 if not item_id: | |
359 comments_service = await self._m.getCommentsService(client, service) | |
360 | |
361 # we need to use uuid for comments node, because we don't know item id in | |
362 # advance (we don't want to set it ourselves to let the server choose, so we | |
363 # can have a nicer id if serial ids is activated) | |
364 comments_node = self._m.getCommentsNode( | |
365 node + "_" + str(shortuuid.uuid()) | |
366 ) | |
367 options = { | |
368 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN, | |
369 self._p.OPT_PERSIST_ITEMS: 1, | |
370 self._p.OPT_MAX_ITEMS: -1, | |
371 self._p.OPT_DELIVER_PAYLOADS: 1, | |
372 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, | |
373 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, | |
374 } | |
375 await self._p.createNode(client, comments_service, comments_node, options) | |
376 values["comments_uri"] = uri.buildXMPPUri( | |
377 "pubsub", | |
378 subtype="microblog", | |
379 path=comments_service.full(), | |
380 node=comments_node, | |
381 ) | |
382 | |
383 return await self._s.set( | |
384 client, service, node, values, schema, item_id, extra, deserialise, form_ns | |
385 ) | |
3460 | 386 |
3508
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
387 def _delete( |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
388 self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
389 ): |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
390 client = self.host.getClient(profile_key) |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
391 return defer.ensureDeferred(self.delete( |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
392 client, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
393 jid.JID(service_s) if service_s else None, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
394 nodeIdentifier, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
395 itemIdentifier, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
396 notify |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
397 )) |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
398 |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
399 async def delete( |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
400 self, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
401 client: SatXMPPEntity, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
402 service: Optional[jid.JID], |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
403 node: Optional[str], |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
404 itemIdentifier: str, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
405 notify: Optional[bool] = None |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
406 ) -> None: |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
407 if not node: |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
408 node = self.namespace |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
409 return await self._p.retractItems( |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
410 service, node, (itemIdentifier,), notify, client.profile |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
411 ) |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
412 |
3464
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
413 def _listsList(self, service, node, profile): |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
414 service = jid.JID(service) if service else None |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
415 node = node or None |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
416 client = self.host.getClient(profile) |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
417 d = defer.ensureDeferred(self.listsList(client, service, node)) |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
418 d.addCallback(data_format.serialise) |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
419 return d |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
420 |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
421 async def listsList( |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
422 self, client, service: Optional[jid.JID], node: Optional[str]=None |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
423 ) -> List[dict]: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
424 """Retrieve list of pubsub lists registered in personal interests |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
425 |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
426 @return list: list of lists metadata |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
427 """ |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
428 items, metadata = await self.host.plugins['LIST_INTEREST'].listInterests( |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
429 client, service, node, namespace=APP_NS_TICKETS) |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
430 lists = [] |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
431 for item in items: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
432 interest_elt = item.interest |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
433 if interest_elt is None: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
434 log.warning(f"invalid interest for {client.profile}: {item.toXml}") |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
435 continue |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
436 if interest_elt.getAttribute("namespace") != APP_NS_TICKETS: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
437 continue |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
438 pubsub_elt = interest_elt.pubsub |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
439 list_data = { |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
440 "id": item["id"], |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
441 "name": interest_elt["name"], |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
442 "service": pubsub_elt["service"], |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
443 "node": pubsub_elt["node"], |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
444 "creator": C.bool(pubsub_elt.getAttribute("creator", C.BOOL_FALSE)), |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
445 } |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
446 try: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
447 list_elt = next(pubsub_elt.elements(APP_NS_TICKETS, "list")) |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
448 except StopIteration: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
449 pass |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
450 else: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
451 list_type = list_data["type"] = list_elt["type"] |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
452 if list_type in TEMPLATES: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
453 list_data["icon_name"] = TEMPLATES[list_type]["icon"] |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
454 lists.append(list_data) |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
455 |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
456 return lists |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
457 |
3460 | 458 def _getTemplatesNames(self, language, profile): |
459 client = self.host.getClient(profile) | |
460 return data_format.serialise(self.getTemplatesNames(client, language)) | |
461 | |
462 def getTemplatesNames(self, client, language: str) -> list: | |
463 """Retrieve well known list templates""" | |
464 | |
465 templates = [{"id": tpl_id, "name": d["name"], "icon": d["icon"]} | |
466 for tpl_id, d in TEMPLATES.items()] | |
467 return templates | |
468 | |
469 def _getTemplate(self, name, language, profile): | |
470 client = self.host.getClient(profile) | |
471 return data_format.serialise(self.getTemplate(client, name, language)) | |
472 | |
473 def getTemplate(self, client, name: str, language: str) -> dict: | |
474 """Retrieve a well known template""" | |
475 return TEMPLATES[name] | |
476 | |
477 def _createTemplate(self, template_id, name, access_model, profile): | |
478 client = self.host.getClient(profile) | |
479 d = defer.ensureDeferred(self.createTemplate( | |
480 client, template_id, name, access_model | |
481 )) | |
482 d.addCallback(lambda node_data: (node_data[0].full(), node_data[1])) | |
483 return d | |
484 | |
485 async def createTemplate( | |
486 self, client, template_id: str, name: str, access_model: str | |
487 ) -> Tuple[jid.JID, str]: | |
488 """Create a list from a template""" | |
489 name = name.strip() | |
490 if not name: | |
491 name = shortuuid.uuid() | |
3472
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
492 fields = TEMPLATES[template_id]["fields"].copy() |
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
493 fields.insert( |
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
494 0, |
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
495 {"type": "hidden", "name": NS_TICKETS_TYPE, "value": template_id} |
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
496 ) |
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
497 schema = xml_tools.dataDict2dataForm( |
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
498 {"namespace": APP_NS_TICKETS, "fields": fields} |
3460 | 499 ).toElement() |
500 | |
501 service = client.jid.userhostJID() | |
502 node = self._s.getSubmittedNS(f"{APP_NS_TICKETS}_{name}") | |
503 options = { | |
3471
d897597cfa94
plugin list: set `overwrite_policy` to `any_publisher` for `grocery` list
Goffi <goffi@goffi.org>
parents:
3470
diff
changeset
|
504 self._p.OPT_ACCESS_MODEL: access_model, |
3460 | 505 } |
3471
d897597cfa94
plugin list: set `overwrite_policy` to `any_publisher` for `grocery` list
Goffi <goffi@goffi.org>
parents:
3470
diff
changeset
|
506 if template_id == "grocery": |
d897597cfa94
plugin list: set `overwrite_policy` to `any_publisher` for `grocery` list
Goffi <goffi@goffi.org>
parents:
3470
diff
changeset
|
507 # for grocery list, we want all publishers to be able to set all items |
d897597cfa94
plugin list: set `overwrite_policy` to `any_publisher` for `grocery` list
Goffi <goffi@goffi.org>
parents:
3470
diff
changeset
|
508 # XXX: should node options be in TEMPLATE? |
d897597cfa94
plugin list: set `overwrite_policy` to `any_publisher` for `grocery` list
Goffi <goffi@goffi.org>
parents:
3470
diff
changeset
|
509 options[self._p.OPT_OVERWRITE_POLICY] = self._p.OWPOL_ANY_PUB |
3460 | 510 await self._p.createNode(client, service, node, options) |
511 await self._s.setSchema(client, service, node, schema) | |
512 list_elt = domish.Element((APP_NS_TICKETS, "list")) | |
513 list_elt["type"] = template_id | |
514 try: | |
515 await self.host.plugins['LIST_INTEREST'].registerPubsub( | |
516 client, APP_NS_TICKETS, service, node, creator=True, | |
517 name=name, element=list_elt) | |
518 except Exception as e: | |
519 log.warning(f"Can't add list to interests: {e}") | |
520 return service, node |