changeset 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 (2017-11-11)
parents 941fdf81958c
children a9fac72825a2
files src/plugins/plugin_misc_tickets.py
diffstat 1 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_tickets.py	Sat Nov 11 18:39:26 2017 +0100
+++ b/src/plugins/plugin_misc_tickets.py	Sat Nov 11 18:39:26 2017 +0100
@@ -35,7 +35,7 @@
     C.PI_IMPORT_NAME: "TICKETS",
     C.PI_TYPE: "EXP",
     C.PI_PROTOCOLS: [],
-    C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277"],
+    C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277", "IDENTITY"],
     C.PI_MAIN: "Tickets",
     C.PI_HANDLER: "no",
     C.PI_DESCRIPTION: _("""Tickets management plugin""")
@@ -50,6 +50,7 @@
         self._p = self.host.plugins["XEP-0060"]
         self._s = self.host.plugins["PUBSUB_SCHEMA"]
         self._m = self.host.plugins["XEP-0277"]
+        self._i = self.host.plugins["IDENTITY"]
         host.bridge.addMethod("ticketsGet", ".plugin",
                               in_sign='ssiassa{ss}s', out_sign='(asa{ss})',
                               method=self._get,
@@ -64,7 +65,19 @@
                               method=self._getSchema,
                               async=True)
 
-    def _labelsFilter(self, widget_type, args, kwargs):
+    def _reporterFilter(self, client, form_xmlui, widget_type, args, kwargs):
+        if not args[0]:
+            # if reporter is not filled, we use user part of publisher
+            # (if we have it)
+            try:
+                publisher = jid.JID(form_xmlui.named_widgets['publisher'].value)
+            except (KeyError, RuntimeError):
+                pass
+            else:
+                args[0] = publisher.user.capitalize()
+        return widget_type, args, kwargs
+
+    def _labelsFilter(self, form_xmlui, widget_type, args, kwargs):
         if widget_type != u'textbox':
             return widget_type, args, kwargs
         widget_type = u'list'
@@ -74,7 +87,7 @@
                   'styles': (u'noselect', u'extensible', u'reducible')}
         return widget_type, args, kwargs
 
-    def _dateFilter(self, widget_type, args, kwargs):
+    def _dateFilter(self, form_xmlui, widget_type, args, kwargs):
         if widget_type != u'string':
             return widget_type, args, kwargs
         # we convert XMPP date to timestamp
@@ -101,7 +114,8 @@
         """
         if not node:
             node = NS_TICKETS
-        filters = {u'labels': self._labelsFilter,
+        filters = {u'reporter': lambda *args: self._reporterFilter(client, *args),
+                   u'labels': self._labelsFilter,
                    u'created': self._dateFilter,
                    u'updated': self._dateFilter,
                    }
@@ -167,6 +181,9 @@
             values['comments_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', path=comments_service.full(), node=comments_node)
 
         values['updated'] = now
+        if not values.get('reporter'):
+            identity = yield self._i.getIdentity(client, client.jid)
+            values['reporter'] = identity['nick']
         item_id = yield self._s.sendDataFormItem(client, service, node, values, schema, item_id, extra, deserialise)
         defer.returnValue(item_id)