Mercurial > libervia-backend
annotate sat/plugins/plugin_misc_tickets.py @ 3452:bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
this implementation replaces the former non standard node schema, and works in a similar
way (the schema is put in a separated node instead of a special field, thus it will now
work with most/all PubSub services, and not only SàT PubSub).
The implementation has been done in a way that nothing should be changed in frontends
(bridge methods names and arguments stay the same). The nodes are modified, but if values
are taken from backend, it's automatically adapted.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 11 Dec 2020 17:57:00 +0100 |
parents | 71761e9fb984 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
3136 | 3 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # This program is free software: you can redistribute it and/or modify |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # it under the terms of the GNU Affero General Public License as published by |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # the Free Software Foundation, either version 3 of the License, or |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # (at your option) any later version. |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # This program is distributed in the hope that it will be useful, |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # GNU Affero General Public License for more details. |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # You should have received a copy of the GNU Affero General Public License |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 from sat.core.i18n import _ |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from sat.core.constants import Const as C |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from twisted.internet import defer |
2471
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2447
diff
changeset
|
21 from sat.tools.common import uri |
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2447
diff
changeset
|
22 import shortuuid |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
24 |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 log = getLogger(__name__) |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
3452
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
27 APP_NS_TICKETS = "org.salut-a-toi.tickets:0" |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 PLUGIN_INFO = { |
3028 | 30 C.PI_NAME: _("Tickets management"), |
31 C.PI_IMPORT_NAME: "TICKETS", | |
32 C.PI_TYPE: "EXP", | |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 C.PI_PROTOCOLS: [], |
3452
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
34 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0346", "XEP-0277", "IDENTITY"], |
3028 | 35 C.PI_MAIN: "Tickets", |
36 C.PI_HANDLER: "no", | |
37 C.PI_DESCRIPTION: _("""Tickets management plugin"""), | |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 } |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
3452
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
41 class Tickets: |
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
42 |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 def __init__(self, host): |
3028 | 44 log.info(_("Tickets plugin initialization")) |
2404
f05c884cd3ef
plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 self.host = host |
3452
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
46 self._s = self.host.plugins["XEP-0346"] |
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
47 self.namespace = self._s.getSubmittedNS(APP_NS_TICKETS) |
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
48 host.registerNamespace("tickets", self.namespace) |
3028 | 49 self._p = self.host.plugins["XEP-0060"] |
50 self._m = self.host.plugins["XEP-0277"] | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
51 host.bridge.addMethod( |
3028 | 52 "ticketsGet", |
53 ".plugin", | |
54 in_sign="ssiassa{ss}s", | |
3309
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
55 out_sign="s", |
3028 | 56 method=lambda service, node, max_items, items_ids, sub_id, extra, profile_key: |
57 self._s._get( | |
58 service, | |
59 node, | |
60 max_items, | |
61 items_ids, | |
62 sub_id, | |
63 extra, | |
3452
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
64 default_node=self.namespace, |
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
65 form_ns=APP_NS_TICKETS, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
66 filters={ |
3028 | 67 "author": self._s.valueOrPublisherFilter, |
68 "created": self._s.dateFilter, | |
69 "updated": self._s.dateFilter, | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
70 }, |
3028 | 71 profile_key=profile_key), |
72 async_=True, | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
73 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
74 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
75 "ticketSet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
76 ".plugin", |
2959
989b622faff6
plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents:
2785
diff
changeset
|
77 in_sign="ssa{sas}ssss", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
78 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
79 method=self._set, |
3028 | 80 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
81 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
82 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
83 "ticketsSchemaGet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
84 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
85 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
86 out_sign="s", |
3028 | 87 method=lambda service, nodeIdentifier, profile_key: self._s._getUISchema( |
3452
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
88 service, nodeIdentifier, default_node=self.namespace, |
3028 | 89 profile_key=profile_key), |
90 async_=True, | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
91 ) |
2471
544c4d2fec45
plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents:
2447
diff
changeset
|
92 |
3028 | 93 def _set(self, service, node, values, schema=None, item_id=None, extra='', |
2785
f18d8315929e
merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
94 profile_key=C.PROF_KEY_NONE): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
95 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
96 service, node, schema, item_id, extra, profile_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
97 ) |
3309
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
98 d = defer.ensureDeferred(self.set( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
99 client, service, node, values, schema, item_id, extra, deserialise=True |
3309
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
100 )) |
3028 | 101 d.addCallback(lambda ret: ret or "") |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
102 return d |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
103 |
3309
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
104 async def set(self, client, service, node, values, schema=None, item_id=None, extra=None, |
3452
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
105 deserialise=False, form_ns=APP_NS_TICKETS): |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
106 """Publish a tickets |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
107 |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
108 @param node(unicode, None): Pubsub node to use |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
109 None to use default tickets node |
2554
0062d3e79d12
plugin uri finder, jp (merge-request): labels handling:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
110 @param values(dict[key(unicode), [iterable[object]|object]]): values of the ticket |
2959
989b622faff6
plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents:
2785
diff
changeset
|
111 |
2554
0062d3e79d12
plugin uri finder, jp (merge-request): labels handling:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
112 if value is not iterable, it will be put in a list |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
113 'created' and 'updated' will be forced to current time: |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
114 - 'created' is set if item_id is None, i.e. if it's a new ticket |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
115 - 'updated' is set everytime |
2447
9e692f09f367
plugin tickets: handle "update" flag + various improvments:
Goffi <goffi@goffi.org>
parents:
2443
diff
changeset
|
116 @param extra(dict, None): same as for [XEP-0060.sendItem] with additional keys: |
9e692f09f367
plugin tickets: handle "update" flag + various improvments:
Goffi <goffi@goffi.org>
parents:
2443
diff
changeset
|
117 - update(bool): if True, get previous item data to merge with current one |
9e692f09f367
plugin tickets: handle "update" flag + various improvments:
Goffi <goffi@goffi.org>
parents:
2443
diff
changeset
|
118 if True, item_id must be None |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
119 other arguments are same as for [self._s.sendDataFormItem] |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
120 @return (unicode): id of the created item |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
121 """ |
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
122 if not node: |
3452
bb0225aaf4e6
plugin XEP-0346: "Form Discovery and Publishing" implementation:
Goffi <goffi@goffi.org>
parents:
3309
diff
changeset
|
123 node = self.namespace |
2959
989b622faff6
plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents:
2785
diff
changeset
|
124 |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
125 if not item_id: |
3309
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
126 comments_service = await self._m.getCommentsService(client, service) |
2420
03da3ef5fb5b
plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents:
2404
diff
changeset
|
127 |
2785
f18d8315929e
merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
128 # we need to use uuid for comments node, because we don't know item id in |
f18d8315929e
merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
129 # advance (we don't want to set it ourselves to let the server choose, so we |
f18d8315929e
merge_requests: use XHTML for body
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
130 # can have a nicer id if serial ids is activated) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
131 comments_node = self._m.getCommentsNode( |
3028 | 132 node + "_" + str(shortuuid.uuid()) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
133 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
134 options = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
135 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
136 self._p.OPT_PERSIST_ITEMS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
137 self._p.OPT_MAX_ITEMS: -1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
138 self._p.OPT_DELIVER_PAYLOADS: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
139 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
140 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
141 } |
3309
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
142 await self._p.createNode(client, comments_service, comments_node, options) |
3028 | 143 values["comments_uri"] = uri.buildXMPPUri( |
144 "pubsub", | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
145 subtype="microblog", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
146 path=comments_service.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
147 node=comments_node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
148 ) |
2959
989b622faff6
plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
Goffi <goffi@goffi.org>
parents:
2785
diff
changeset
|
149 |
3309
71761e9fb984
plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
150 return await self._s.set( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
151 client, service, node, values, schema, item_id, extra, deserialise, form_ns |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2603
diff
changeset
|
152 ) |