annotate sat/plugins/plugin_misc_lists.py @ 3483:5945c24cd745

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