comparison src/plugins/plugin_misc_tickets.py @ 2430:3faf18111d61

plugin tickets: fill reporter field when it is not already filled
author Goffi <goffi@goffi.org>
date Sat, 11 Nov 2017 18:39:26 +0100
parents 03da3ef5fb5b
children 7fa9456032e7
comparison
equal deleted inserted replaced
2429:941fdf81958c 2430:3faf18111d61
33 PLUGIN_INFO = { 33 PLUGIN_INFO = {
34 C.PI_NAME: _("Tickets management"), 34 C.PI_NAME: _("Tickets management"),
35 C.PI_IMPORT_NAME: "TICKETS", 35 C.PI_IMPORT_NAME: "TICKETS",
36 C.PI_TYPE: "EXP", 36 C.PI_TYPE: "EXP",
37 C.PI_PROTOCOLS: [], 37 C.PI_PROTOCOLS: [],
38 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277"], 38 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277", "IDENTITY"],
39 C.PI_MAIN: "Tickets", 39 C.PI_MAIN: "Tickets",
40 C.PI_HANDLER: "no", 40 C.PI_HANDLER: "no",
41 C.PI_DESCRIPTION: _("""Tickets management plugin""") 41 C.PI_DESCRIPTION: _("""Tickets management plugin""")
42 } 42 }
43 43
48 log.info(_(u"Tickets plugin initialization")) 48 log.info(_(u"Tickets plugin initialization"))
49 self.host = host 49 self.host = host
50 self._p = self.host.plugins["XEP-0060"] 50 self._p = self.host.plugins["XEP-0060"]
51 self._s = self.host.plugins["PUBSUB_SCHEMA"] 51 self._s = self.host.plugins["PUBSUB_SCHEMA"]
52 self._m = self.host.plugins["XEP-0277"] 52 self._m = self.host.plugins["XEP-0277"]
53 self._i = self.host.plugins["IDENTITY"]
53 host.bridge.addMethod("ticketsGet", ".plugin", 54 host.bridge.addMethod("ticketsGet", ".plugin",
54 in_sign='ssiassa{ss}s', out_sign='(asa{ss})', 55 in_sign='ssiassa{ss}s', out_sign='(asa{ss})',
55 method=self._get, 56 method=self._get,
56 async=True 57 async=True
57 ) 58 )
62 host.bridge.addMethod("ticketsSchemaGet", ".plugin", 63 host.bridge.addMethod("ticketsSchemaGet", ".plugin",
63 in_sign='sss', out_sign='s', 64 in_sign='sss', out_sign='s',
64 method=self._getSchema, 65 method=self._getSchema,
65 async=True) 66 async=True)
66 67
67 def _labelsFilter(self, widget_type, args, kwargs): 68 def _reporterFilter(self, client, form_xmlui, widget_type, args, kwargs):
69 if not args[0]:
70 # if reporter is not filled, we use user part of publisher
71 # (if we have it)
72 try:
73 publisher = jid.JID(form_xmlui.named_widgets['publisher'].value)
74 except (KeyError, RuntimeError):
75 pass
76 else:
77 args[0] = publisher.user.capitalize()
78 return widget_type, args, kwargs
79
80 def _labelsFilter(self, form_xmlui, widget_type, args, kwargs):
68 if widget_type != u'textbox': 81 if widget_type != u'textbox':
69 return widget_type, args, kwargs 82 return widget_type, args, kwargs
70 widget_type = u'list' 83 widget_type = u'list'
71 options = [o for o in args.pop(0).split(u'\n') if o] 84 options = [o for o in args.pop(0).split(u'\n') if o]
72 kwargs = {'options': options, 85 kwargs = {'options': options,
73 'name': kwargs.get('name'), 86 'name': kwargs.get('name'),
74 'styles': (u'noselect', u'extensible', u'reducible')} 87 'styles': (u'noselect', u'extensible', u'reducible')}
75 return widget_type, args, kwargs 88 return widget_type, args, kwargs
76 89
77 def _dateFilter(self, widget_type, args, kwargs): 90 def _dateFilter(self, form_xmlui, widget_type, args, kwargs):
78 if widget_type != u'string': 91 if widget_type != u'string':
79 return widget_type, args, kwargs 92 return widget_type, args, kwargs
80 # we convert XMPP date to timestamp 93 # we convert XMPP date to timestamp
81 args[0] = unicode(utils.date_parse(args[0])) 94 args[0] = unicode(utils.date_parse(args[0]))
82 return widget_type, args, kwargs 95 return widget_type, args, kwargs
99 other parameters as the same as for [XEP_0060.getItems] 112 other parameters as the same as for [XEP_0060.getItems]
100 @return (list[unicode]): XMLUI of the tickets 113 @return (list[unicode]): XMLUI of the tickets
101 """ 114 """
102 if not node: 115 if not node:
103 node = NS_TICKETS 116 node = NS_TICKETS
104 filters = {u'labels': self._labelsFilter, 117 filters = {u'reporter': lambda *args: self._reporterFilter(client, *args),
118 u'labels': self._labelsFilter,
105 u'created': self._dateFilter, 119 u'created': self._dateFilter,
106 u'updated': self._dateFilter, 120 u'updated': self._dateFilter,
107 } 121 }
108 tickets, metadata = yield self._s.getDataFormItems( 122 tickets, metadata = yield self._s.getDataFormItems(
109 client, 123 client,
165 } 179 }
166 yield self._p.createNode(client, comments_service, comments_node, options) 180 yield self._p.createNode(client, comments_service, comments_node, options)
167 values['comments_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', path=comments_service.full(), node=comments_node) 181 values['comments_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', path=comments_service.full(), node=comments_node)
168 182
169 values['updated'] = now 183 values['updated'] = now
184 if not values.get('reporter'):
185 identity = yield self._i.getIdentity(client, client.jid)
186 values['reporter'] = identity['nick']
170 item_id = yield self._s.sendDataFormItem(client, service, node, values, schema, item_id, extra, deserialise) 187 item_id = yield self._s.sendDataFormItem(client, service, node, values, schema, item_id, extra, deserialise)
171 defer.returnValue(item_id) 188 defer.returnValue(item_id)
172 189
173 def _getSchema(self, service, node, profile_key=C.PROF_KEY_NONE): 190 def _getSchema(self, service, node, profile_key=C.PROF_KEY_NONE):
174 if not node: 191 if not node: