diff src/plugins/plugin_tickets_import.py @ 2390:f57a8eaec8ed

plugins import, tickets import, bugzilla import: comments handling: - comments are put in "comments" key in import data, it's a list of microblog data - in resulting item, the comments uri is put in comments_uri field - (plugin import) root_service and root_node are kept in session - (plugin ticket) reporter name is now in "reporter" key instead of "reporter_name" - (plugin bugizlla): if not reporter name is found, first part of email address is used
author Goffi <goffi@goffi.org>
date Fri, 20 Oct 2017 08:48:41 +0200
parents a49a19f06e38
children 8ed4ac10cb5e
line wrap: on
line diff
--- a/src/plugins/plugin_tickets_import.py	Fri Oct 20 08:44:09 2017 +0200
+++ b/src/plugins/plugin_tickets_import.py	Fri Oct 20 08:48:41 2017 +0200
@@ -19,16 +19,18 @@
 
 from sat.core.i18n import _
 from sat.core.constants import Const as C
+from sat.core import exceptions
 from sat.core.log import getLogger
 log = getLogger(__name__)
 from twisted.internet import defer
+from sat.tools.common import uri
 
 
 PLUGIN_INFO = {
     C.PI_NAME: "tickets import",
     C.PI_IMPORT_NAME: "TICKETS_IMPORT",
     C.PI_TYPE: C.PLUG_TYPE_IMPORT,
-    C.PI_DEPENDENCIES: ["IMPORT", "XEP-0060", "PUBSUB_SCHEMA"],
+    C.PI_DEPENDENCIES: ["IMPORT", "XEP-0060", "XEP-0277", "PUBSUB_SCHEMA"],
     C.PI_MAIN: "TicketsImportPlugin",
     C.PI_HANDLER: "no",
     C.PI_DESCRIPTION: _(u"""Tickets import management:
@@ -47,6 +49,7 @@
         self.host = host
         self._importers = {}
         self._p = host.plugins['XEP-0060']
+        self._m = host.plugins['XEP-0277']
         self._s = host.plugins['PUBSUB_SCHEMA']
         host.plugins['IMPORT'].initialize(self, u'tickets')
 
@@ -61,7 +64,8 @@
             'body': main description of the ticket
             'creation': date of creation
             'update': date of last update
-            'reporter_name': full name of reporter
+            'reporter': full name of reporter
+            'reporter_jid': jid of reporter
             'reporter_email': email of reporter
             'assigned_to_name': full name of person working on it
             'assigned_to_email': email of person working on it
@@ -79,13 +83,29 @@
                 - "review": ticket is fixed and waiting for review
                 - "closed": ticket is finished or invalid
             'milestone': target milestone for this ticket
+            'comments': list of microblog data (comment metadata, check [XEP_0277.send] data argument)
         """
+        if 'comments_uri' in item_import_data:
+            raise exceptions.DataError(_(u'comments_uri key will be generated and must not be used by importer'))
+        if session[u'root_node'] is None:
+            session[u'root_node'] = NS_TICKETS
         if not 'schema' in session:
-            session['schema'] = yield self._s.getSchemaForm(client, service, node or NS_TICKETS)
+            session['schema'] = yield self._s.getSchemaForm(client, service, node or session[u'root_node'])
         defer.returnValue(item_import_data)
 
+    @defer.inlineCallbacks
     def importSubItems(self, client, item_import_data, ticket_data, session, options):
-        return None
+        # TODO: force "open" permission (except if private, check below)
+        # TODO: handle "private" metadata, to have non public access for node
+        comments = ticket_data.get('comments', [])
+        service, node = self._m.getCommentsService(client), self._m.getCommentsNode(session['root_node'] + u'_' + ticket_data['id'])
+        yield self._p.createIfNewNode(client, service, node)
+        ticket_data['comments_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', path=service.full(), node=node)
+        for comment in comments:
+            if 'updated' not in comment and 'published' in comment:
+                # we don't want an automatic update date
+                comment['updated'] = comment['published']
+            yield self._m.send(client, comment, service, node)
 
     def publishItem(self, client, ticket_data, service, node, session):
         if node is None: