Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_misc_lists.py @ 4332:71c939e34ca6
XEP-0373 (OX): Adjust to gpgme updates: generate with explicit algorithm and subkeys
author | Syndace <me@syndace.dev> |
---|---|
date | Sat, 13 Jul 2024 18:28:28 +0200 |
parents | a5d27f69eedb |
children |
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 | |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 from libervia.backend.core.i18n import _, D_ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
24 from libervia.backend.core.xmpp import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
25 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
|
26 from libervia.backend.tools import xml_tools |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
27 from libervia.backend.tools.common import uri |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
28 from libervia.backend.tools.common import data_format |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
29 from libervia.backend.core.log import getLogger |
3458 | 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: [], | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
43 C.PI_DEPENDENCIES: [ |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
44 "XEP-0060", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
45 "XEP-0346", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
46 "XEP-0277", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
47 "IDENTITY", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
48 "PUBSUB_INVITATION", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
49 ], |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
50 C.PI_MAIN: "PubsubLists", |
3458 | 51 C.PI_HANDLER: "no", |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
52 C.PI_DESCRIPTION: _("""Pubsub lists management plugin"""), |
3458 | 53 } |
54 | |
3460 | 55 TEMPLATES = { |
56 "todo": { | |
57 "name": D_("TODO List"), | |
58 "icon": "check", | |
59 "fields": [ | |
60 {"name": "title"}, | |
61 {"name": "author"}, | |
62 {"name": "created"}, | |
63 {"name": "updated"}, | |
64 {"name": "time_limit"}, | |
65 {"name": "labels", "type": "text-multi"}, | |
66 { | |
67 "name": "status", | |
68 "label": D_("status"), | |
69 "type": "list-single", | |
70 "options": [ | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
71 {"label": D_("to do"), "value": "todo"}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
72 {"label": D_("in progress"), "value": "in_progress"}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
73 {"label": D_("done"), "value": "done"}, |
3460 | 74 ], |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
75 "value": "todo", |
3460 | 76 }, |
77 { | |
78 "name": "priority", | |
79 "label": D_("priority"), | |
80 "type": "list-single", | |
81 "options": [ | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
82 {"label": D_("major"), "value": "major"}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
83 {"label": D_("normal"), "value": "normal"}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
84 {"label": D_("minor"), "value": "minor"}, |
3460 | 85 ], |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
86 "value": "normal", |
3460 | 87 }, |
88 {"name": "body", "type": "xhtml"}, | |
89 {"name": "comments_uri"}, | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
90 ], |
3460 | 91 }, |
3470
ca76767185e3
plugin list: rename `shopping` list to `grocery` list
Goffi <goffi@goffi.org>
parents:
3469
diff
changeset
|
92 "grocery": { |
ca76767185e3
plugin list: rename `shopping` list to `grocery` list
Goffi <goffi@goffi.org>
parents:
3469
diff
changeset
|
93 "name": D_("Grocery List"), |
3460 | 94 "icon": "basket", |
95 "fields": [ | |
96 {"name": "name", "label": D_("name")}, | |
97 {"name": "quantity", "label": D_("quantity")}, | |
98 { | |
99 "name": "status", | |
100 "label": D_("status"), | |
101 "type": "list-single", | |
102 "options": [ | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
103 {"label": D_("to buy"), "value": "to_buy"}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
104 {"label": D_("bought"), "value": "bought"}, |
3460 | 105 ], |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
106 "value": "to_buy", |
3460 | 107 }, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
108 ], |
3460 | 109 }, |
110 "tickets": { | |
111 "name": D_("Tickets"), | |
112 "icon": "clipboard", | |
113 "fields": [ | |
114 {"name": "title"}, | |
115 {"name": "author"}, | |
116 {"name": "created"}, | |
117 {"name": "updated"}, | |
118 {"name": "labels", "type": "text-multi"}, | |
119 { | |
120 "name": "type", | |
121 "label": D_("type"), | |
122 "type": "list-single", | |
123 "options": [ | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
124 {"label": D_("bug"), "value": "bug"}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
125 {"label": D_("feature request"), "value": "feature"}, |
3460 | 126 ], |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
127 "value": "bug", |
3460 | 128 }, |
129 { | |
130 "name": "status", | |
131 "label": D_("status"), | |
132 "type": "list-single", | |
133 "options": [ | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
134 {"label": D_("queued"), "value": "queued"}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
135 {"label": D_("started"), "value": "started"}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
136 {"label": D_("review"), "value": "review"}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
137 {"label": D_("closed"), "value": "closed"}, |
3460 | 138 ], |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
139 "value": "queued", |
3460 | 140 }, |
141 { | |
142 "name": "priority", | |
143 "label": D_("priority"), | |
144 "type": "list-single", | |
145 "options": [ | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
146 {"label": D_("major"), "value": "major"}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
147 {"label": D_("normal"), "value": "normal"}, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
148 {"label": D_("minor"), "value": "minor"}, |
3460 | 149 ], |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
150 "value": "normal", |
3460 | 151 }, |
152 {"name": "body", "type": "xhtml"}, | |
153 {"name": "comments_uri"}, | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
154 ], |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
155 }, |
3460 | 156 } |
157 | |
3458 | 158 |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
159 class PubsubLists: |
3458 | 160 |
161 def __init__(self, host): | |
3459
8dc26e5edcd3
plugin tickets, merge_requests: renamed "tickets" feature to "lists":
Goffi <goffi@goffi.org>
parents:
3458
diff
changeset
|
162 log.info(_("Pubsub lists plugin initialization")) |
3458 | 163 self.host = host |
164 self._s = self.host.plugins["XEP-0346"] | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
165 self.namespace = self._s.get_submitted_ns(APP_NS_TICKETS) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
166 host.register_namespace("tickets", APP_NS_TICKETS) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
167 host.register_namespace("tickets_type", NS_TICKETS_TYPE) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
168 self.host.plugins["PUBSUB_INVITATION"].register(APP_NS_TICKETS, self) |
3458 | 169 self._p = self.host.plugins["XEP-0060"] |
170 self._m = self.host.plugins["XEP-0277"] | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
171 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
172 "list_get", |
3458 | 173 ".plugin", |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3508
diff
changeset
|
174 in_sign="ssiassss", |
3458 | 175 out_sign="s", |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
176 method=lambda service, node, max_items, items_ids, sub_id, extra, profile_key: self._s._get( |
3458 | 177 service, |
178 node, | |
179 max_items, | |
180 items_ids, | |
181 sub_id, | |
182 extra, | |
183 default_node=self.namespace, | |
184 form_ns=APP_NS_TICKETS, | |
185 filters={ | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
186 "author": self._s.value_or_publisher_filter, |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
187 "created": self._s.date_filter, |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
188 "updated": self._s.date_filter, |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
189 "time_limit": self._s.date_filter, |
3458 | 190 }, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
191 profile_key=profile_key, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
192 ), |
3458 | 193 async_=True, |
194 ) | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
195 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
196 "list_set", |
3458 | 197 ".plugin", |
198 in_sign="ssa{sas}ssss", | |
199 out_sign="s", | |
200 method=self._set, | |
201 async_=True, | |
202 ) | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
203 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
204 "list_delete_item", |
3508
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
205 ".plugin", |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
206 in_sign="sssbs", |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
207 out_sign="", |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
208 method=self._delete, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
209 async_=True, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
210 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
211 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
212 "list_schema_get", |
3458 | 213 ".plugin", |
214 in_sign="sss", | |
215 out_sign="s", | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
216 method=lambda service, nodeIdentifier, profile_key: self._s._get_ui_schema( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
217 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
218 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
219 default_node=self.namespace, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
220 profile_key=profile_key, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
221 ), |
3458 | 222 async_=True, |
223 ) | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
224 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
225 "lists_list", |
3464
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
226 ".plugin", |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
227 in_sign="sss", |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
228 out_sign="s", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
229 method=self._lists_list, |
3464
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
230 async_=True, |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
231 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
232 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
233 "list_templates_names_get", |
3460 | 234 ".plugin", |
235 in_sign="ss", | |
236 out_sign="s", | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
237 method=self._get_templates_names, |
3460 | 238 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
239 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
240 "list_template_get", |
3460 | 241 ".plugin", |
242 in_sign="sss", | |
243 out_sign="s", | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
244 method=self._get_template, |
3460 | 245 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
246 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
247 "list_template_create", |
3460 | 248 ".plugin", |
249 in_sign="ssss", | |
250 out_sign="(ss)", | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
251 method=self._create_template, |
3460 | 252 async_=True, |
253 ) | |
3458 | 254 |
4027
26c3e1bc7fb7
plugin XEP-0471: renamed "events" plugin to XEP-0471 now that there is a XEP
Goffi <goffi@goffi.org>
parents:
3931
diff
changeset
|
255 async def on_invitation_preflight( |
3463
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
256 self, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
257 client: SatXMPPEntity, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
258 namespace: str, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
259 name: str, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
260 extra: dict, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
261 service: jid.JID, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
262 node: str, |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
263 item_id: Optional[str], |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
264 item_elt: domish.Element, |
3463
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
265 ) -> None: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
266 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
267 schema = await self._s.get_schema_form(client, service, node) |
3463
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
268 except Exception as e: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
269 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
|
270 else: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
271 try: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
272 field_type = schema[NS_TICKETS_TYPE] |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
273 except KeyError: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
274 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
|
275 else: |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
276 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
|
277 list_elt["type"] = field_type |
483bcfeb11c9
plugin misc list: register lists for pubsub invitations
Goffi <goffi@goffi.org>
parents:
3461
diff
changeset
|
278 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
279 def _set( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
280 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
281 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
282 node, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
283 values, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
284 schema=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
285 item_id=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
286 extra_s="", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
287 profile_key=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
288 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
289 client, service, node, schema, item_id, extra = self._s.prepare_bridge_set( |
3930
0a6d4168968a
plugin lists: fix double deserialisation
Goffi <goffi@goffi.org>
parents:
3928
diff
changeset
|
290 service, node, schema, item_id, extra_s, profile_key |
3458 | 291 ) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
292 d = defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
293 self.set( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
294 client, service, node, values, schema, item_id, extra, deserialise=True |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
295 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
296 ) |
3458 | 297 d.addCallback(lambda ret: ret or "") |
298 return d | |
299 | |
3460 | 300 async def set( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
301 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
302 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
303 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
304 node, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
305 values, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
306 schema=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
307 item_id=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
308 extra=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
309 deserialise=False, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
310 form_ns=APP_NS_TICKETS, |
3460 | 311 ): |
3458 | 312 """Publish a tickets |
313 | |
314 @param node(unicode, None): Pubsub node to use | |
315 None to use default tickets node | |
316 @param values(dict[key(unicode), [iterable[object]|object]]): values of the ticket | |
317 | |
318 if value is not iterable, it will be put in a list | |
319 'created' and 'updated' will be forced to current time: | |
320 - 'created' is set if item_id is None, i.e. if it's a new ticket | |
321 - 'updated' is set everytime | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
322 @param extra(dict, None): same as for [XEP-0060.send_item] with additional keys: |
3458 | 323 - 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
|
324 if True, item_id must be set |
4271
a5d27f69eedb
plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
325 - comments(bool): indicate if a new comment node must be created. |
a5d27f69eedb
plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
326 If True a new comment node will be create, and replace existing one if |
a5d27f69eedb
plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
327 there is already one. |
a5d27f69eedb
plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
328 If not set, comment node will be create if not ``item_id`` is specified, |
a5d27f69eedb
plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
329 and won't be modified otherwise. |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
330 other arguments are same as for [self._s.send_data_form_item] |
3458 | 331 @return (unicode): id of the created item |
332 """ | |
333 if not node: | |
334 node = self.namespace | |
335 | |
4271
a5d27f69eedb
plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
336 if extra is None: |
a5d27f69eedb
plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
337 extra = {} |
a5d27f69eedb
plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
338 |
a5d27f69eedb
plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
339 # FIXME: presence of a field where comments node can be added must be checked. |
a5d27f69eedb
plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
340 add_comments_node = extra.get("comments") |
a5d27f69eedb
plugin misc list: Comments node creation can now be specified with `comments` field in `extra`.
Goffi <goffi@goffi.org>
parents:
4270
diff
changeset
|
341 if add_comments_node or (add_comments_node is None and not item_id): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
342 comments_service = await self._m.get_comments_service(client, service) |
3458 | 343 |
344 # we need to use uuid for comments node, because we don't know item id in | |
345 # advance (we don't want to set it ourselves to let the server choose, so we | |
346 # can have a nicer id if serial ids is activated) | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
347 comments_node = self._m.get_comments_node(node + "_" + str(shortuuid.uuid())) |
3458 | 348 options = { |
349 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN, | |
350 self._p.OPT_PERSIST_ITEMS: 1, | |
351 self._p.OPT_DELIVER_PAYLOADS: 1, | |
352 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, | |
353 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, | |
354 } | |
355 await self._p.createNode(client, comments_service, comments_node, options) | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
356 values["comments_uri"] = uri.build_xmpp_uri( |
3458 | 357 "pubsub", |
358 subtype="microblog", | |
359 path=comments_service.full(), | |
360 node=comments_node, | |
361 ) | |
362 | |
363 return await self._s.set( | |
364 client, service, node, values, schema, item_id, extra, deserialise, form_ns | |
365 ) | |
3460 | 366 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
367 def _delete(self, service_s, nodeIdentifier, itemIdentifier, notify, profile_key): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
368 client = self.host.get_client(profile_key) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
369 return defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
370 self.delete( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
371 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
372 jid.JID(service_s) if service_s else None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
373 nodeIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
374 itemIdentifier, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
375 notify, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
376 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
377 ) |
3508
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
378 |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
379 async def delete( |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
380 self, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
381 client: SatXMPPEntity, |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
382 service: Optional[jid.JID], |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
383 node: Optional[str], |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
384 itemIdentifier: str, |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
385 notify: Optional[bool] = None, |
3508
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
386 ) -> None: |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
387 if not node: |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
388 node = self.namespace |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
389 return await self._p.retract_items( |
3508
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
390 service, node, (itemIdentifier,), notify, client.profile |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
391 ) |
9d9fb871a75c
plugin list: `delete` implementation:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
392 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
393 def _lists_list(self, service, node, profile): |
3464
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
394 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
|
395 node = node or None |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
396 client = self.host.get_client(profile) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
397 d = defer.ensureDeferred(self.lists_list(client, service, node)) |
3464
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
398 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
|
399 return d |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
400 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
401 async def lists_list( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
402 self, client, service: Optional[jid.JID], node: Optional[str] = None |
3464
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
403 ) -> List[dict]: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
404 """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
|
405 |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
406 @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
|
407 """ |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
408 items, metadata = await self.host.plugins["LIST_INTEREST"].list_interests( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
409 client, service, node, namespace=APP_NS_TICKETS |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
410 ) |
3464
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
411 lists = [] |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
412 for item in items: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
413 interest_elt = item.interest |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
414 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
|
415 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
|
416 continue |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
417 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
|
418 continue |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
419 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
|
420 list_data = { |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
421 "id": item["id"], |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
422 "name": interest_elt["name"], |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
423 "service": pubsub_elt["service"], |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
424 "node": pubsub_elt["node"], |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
425 "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
|
426 } |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
427 try: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
428 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
|
429 except StopIteration: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
430 pass |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
431 else: |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
432 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
|
433 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
|
434 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
|
435 lists.append(list_data) |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
436 |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
437 return lists |
54b9cdbeb335
plugin lists: new `listsList` method to retrieve lists from personal interests
Goffi <goffi@goffi.org>
parents:
3463
diff
changeset
|
438 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
439 def _get_templates_names(self, language, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
440 client = self.host.get_client(profile) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
441 return data_format.serialise(self.get_templates_names(client, language)) |
3460 | 442 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
443 def get_templates_names(self, client, language: str) -> list: |
3460 | 444 """Retrieve well known list templates""" |
445 | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
446 templates = [ |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
447 {"id": tpl_id, "name": d["name"], "icon": d["icon"]} |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
448 for tpl_id, d in TEMPLATES.items() |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
449 ] |
3460 | 450 return templates |
451 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
452 def _get_template(self, name, language, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
453 client = self.host.get_client(profile) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
454 return data_format.serialise(self.get_template(client, name, language)) |
3460 | 455 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
456 def get_template(self, client, name: str, language: str) -> dict: |
3460 | 457 """Retrieve a well known template""" |
458 return TEMPLATES[name] | |
459 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
460 def _create_template(self, template_id, name, access_model, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
461 client = self.host.get_client(profile) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
462 d = defer.ensureDeferred( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
463 self.create_template(client, template_id, name, access_model) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
464 ) |
3460 | 465 d.addCallback(lambda node_data: (node_data[0].full(), node_data[1])) |
466 return d | |
467 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
468 async def create_template( |
3460 | 469 self, client, template_id: str, name: str, access_model: str |
470 ) -> Tuple[jid.JID, str]: | |
471 """Create a list from a template""" | |
472 name = name.strip() | |
473 if not name: | |
474 name = shortuuid.uuid() | |
3472
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
475 fields = TEMPLATES[template_id]["fields"].copy() |
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
476 fields.insert( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
477 0, {"type": "hidden", "name": NS_TICKETS_TYPE, "value": template_id} |
3472
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
478 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
479 schema = xml_tools.data_dict_2_data_form( |
3472
e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
Goffi <goffi@goffi.org>
parents:
3471
diff
changeset
|
480 {"namespace": APP_NS_TICKETS, "fields": fields} |
3460 | 481 ).toElement() |
482 | |
483 service = client.jid.userhostJID() | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
484 node = self._s.get_submitted_ns(f"{APP_NS_TICKETS}_{name}") |
3460 | 485 options = { |
3471
d897597cfa94
plugin list: set `overwrite_policy` to `any_publisher` for `grocery` list
Goffi <goffi@goffi.org>
parents:
3470
diff
changeset
|
486 self._p.OPT_ACCESS_MODEL: access_model, |
3460 | 487 } |
3471
d897597cfa94
plugin list: set `overwrite_policy` to `any_publisher` for `grocery` list
Goffi <goffi@goffi.org>
parents:
3470
diff
changeset
|
488 if template_id == "grocery": |
d897597cfa94
plugin list: set `overwrite_policy` to `any_publisher` for `grocery` list
Goffi <goffi@goffi.org>
parents:
3470
diff
changeset
|
489 # 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
|
490 # 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
|
491 options[self._p.OPT_OVERWRITE_POLICY] = self._p.OWPOL_ANY_PUB |
3460 | 492 await self._p.createNode(client, service, node, options) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4027
diff
changeset
|
493 await self._s.set_schema(client, service, node, schema) |
3460 | 494 list_elt = domish.Element((APP_NS_TICKETS, "list")) |
495 list_elt["type"] = template_id | |
496 try: | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
497 await self.host.plugins["LIST_INTEREST"].register_pubsub( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
498 client, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
499 APP_NS_TICKETS, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
500 service, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
501 node, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
502 creator=True, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
503 name=name, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
504 element=list_elt, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
505 ) |
3460 | 506 except Exception as e: |
507 log.warning(f"Can't add list to interests: {e}") | |
508 return service, node |