annotate src/plugins/plugin_misc_tickets.py @ 2528:65e278997715

component file sharing: comments metadata: new <comments> element is added to file metadata, it contains the URL to the comments virtual node and the count of comments (this way client knows if it make sense to request comments or not). Fixed triggers in plugin XEP-0264 (return value was missing). New trigger in plugin XEP-0329 to allow component to add metadata (used here for comments url).
author Goffi <goffi@goffi.org>
date Fri, 16 Mar 2018 18:43:11 +0100
parents 0046283a285d
children 0062d3e79d12
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for Pubsub Schemas
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2472
diff changeset
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # 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
8 # 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
9 # 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
10 # (at your option) any later version.
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # 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
13 # 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
14 # 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
15 # GNU Affero General Public License for more details.
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # 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
18 # 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
19
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.i18n import _
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.constants import Const as C
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from twisted.internet import defer
2471
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
23 from sat.tools.common import uri
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.tools import utils
2471
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
25 import shortuuid
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.core.log import getLogger
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 log = getLogger(__name__)
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 NS_TICKETS = 'org.salut-a-toi.tickets:0'
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 PLUGIN_INFO = {
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 C.PI_NAME: _("Tickets management"),
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 C.PI_IMPORT_NAME: "TICKETS",
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 C.PI_TYPE: "EXP",
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 C.PI_PROTOCOLS: [],
2430
3faf18111d61 plugin tickets: fill reporter field when it is not already filled
Goffi <goffi@goffi.org>
parents: 2420
diff changeset
36 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277", "IDENTITY"],
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 C.PI_MAIN: "Tickets",
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_HANDLER: "no",
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 C.PI_DESCRIPTION: _("""Tickets management plugin""")
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 }
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 class Tickets(object):
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 def __init__(self, host):
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 log.info(_(u"Tickets plugin initialization"))
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.host = host
2443
81a45e7886c9 core: added a mechanism to associate short names to namespaces:
Goffi <goffi@goffi.org>
parents: 2434
diff changeset
48 host.registerNamespace('tickets', NS_TICKETS)
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self._p = self.host.plugins["XEP-0060"]
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self._s = self.host.plugins["PUBSUB_SCHEMA"]
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
51 self._m = self.host.plugins["XEP-0277"]
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 host.bridge.addMethod("ticketsGet", ".plugin",
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 in_sign='ssiassa{ss}s', out_sign='(asa{ss})',
2471
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
54 method=utils.partial(
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
55 self._s._get,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
56 default_node=NS_TICKETS,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
57 form_ns=NS_TICKETS,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
58 filters = {u'author': self._s.valueOrPublisherFilter,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
59 u'labels': self._s.textbox2ListFilter,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
60 u'created': self._s.dateFilter,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
61 u'updated': self._s.dateFilter,
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
62 }),
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
63
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 async=True
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 )
2447
9e692f09f367 plugin tickets: handle "update" flag + various improvments:
Goffi <goffi@goffi.org>
parents: 2443
diff changeset
66 host.bridge.addMethod("ticketSet", ".plugin",
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
67 in_sign='ssa{sas}ssa{ss}s', out_sign='s',
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
68 method=self._set,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
69 async=True)
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
70 host.bridge.addMethod("ticketsSchemaGet", ".plugin",
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
71 in_sign='sss', out_sign='s',
2471
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
72 method=utils.partial(self._s._getUISchema, default_node=NS_TICKETS),
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
73 async=True)
2404
f05c884cd3ef plugin tickets: high level tickets handling, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
75 def _set(self, service, node, values, schema=None, item_id=None, extra=None, profile_key=C.PROF_KEY_NONE):
2472
3f0a3a0ed290 plugins tickets, merge-requests: fixed call of prepareBridgeSet
Goffi <goffi@goffi.org>
parents: 2471
diff changeset
76 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(service, node, schema, item_id, extra, profile_key)
3f0a3a0ed290 plugins tickets, merge-requests: fixed call of prepareBridgeSet
Goffi <goffi@goffi.org>
parents: 2471
diff changeset
77 d = self.set(client, service, node, values, schema, item_id, extra, deserialise=True)
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
78 d.addCallback(lambda ret: ret or u'')
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
79 return d
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
80
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
81 @defer.inlineCallbacks
2447
9e692f09f367 plugin tickets: handle "update" flag + various improvments:
Goffi <goffi@goffi.org>
parents: 2443
diff changeset
82 def set(self, client, service, node, values, schema=None, item_id=None, extra=None, deserialise=False, form_ns=NS_TICKETS):
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
83 """Publish a tickets
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
84
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
85 @param node(unicode, None): Pubsub node to use
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
86 None to use default tickets node
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
87 @param values(dict[key(unicode), [iterable[object], object]]): values of the ticket
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
88 if not iterable, will be put in a list
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
89 '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
90 - '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
91 - 'updated' is set everytime
2447
9e692f09f367 plugin tickets: handle "update" flag + various improvments:
Goffi <goffi@goffi.org>
parents: 2443
diff changeset
92 @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
93 - 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
94 if True, item_id must be None
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
95 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
96 @return (unicode): id of the created item
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
97 """
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
98 if not node:
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
99 node = NS_TICKETS
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
100 if not item_id:
2434
7fa9456032e7 plugin tickets: specify parent service when using getCommentsService + fill reporter_jid is missing (will be discarded later if not in the schema)
Goffi <goffi@goffi.org>
parents: 2430
diff changeset
101 comments_service = yield self._m.getCommentsService(client, service)
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
102
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
103 # we need to use uuid for comments node, because we don't know item id in advance
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
104 # (we don't want to set it ourselves to let the server choose, so we can have
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
105 # a nicer id if serial ids is activated)
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
106 comments_node = self._m.getCommentsNode(node + u'_' + unicode(shortuuid.uuid()))
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
107 options = {self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
108 self._p.OPT_PERSIST_ITEMS: 1,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
109 self._p.OPT_MAX_ITEMS: -1,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
110 self._p.OPT_DELIVER_PAYLOADS: 1,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
111 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
112 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
113 }
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
114 yield self._p.createNode(client, comments_service, comments_node, options)
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
115 values['comments_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', path=comments_service.full(), node=comments_node)
2471
544c4d2fec45 plugins schema, merge_requests, tickets*: factorisation
Goffi <goffi@goffi.org>
parents: 2447
diff changeset
116 item_id = yield self._s.set(client, service, node, values, schema, item_id, extra, deserialise, form_ns)
2420
03da3ef5fb5b plugin tickets: added ticketsSet and ticketsSchemaGet methods:
Goffi <goffi@goffi.org>
parents: 2404
diff changeset
117 defer.returnValue(item_id)