Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
2389:5675af905725 | 2390:f57a8eaec8ed |
---|---|
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core import exceptions | |
22 from sat.core.log import getLogger | 23 from sat.core.log import getLogger |
23 log = getLogger(__name__) | 24 log = getLogger(__name__) |
24 from twisted.internet import defer | 25 from twisted.internet import defer |
26 from sat.tools.common import uri | |
25 | 27 |
26 | 28 |
27 PLUGIN_INFO = { | 29 PLUGIN_INFO = { |
28 C.PI_NAME: "tickets import", | 30 C.PI_NAME: "tickets import", |
29 C.PI_IMPORT_NAME: "TICKETS_IMPORT", | 31 C.PI_IMPORT_NAME: "TICKETS_IMPORT", |
30 C.PI_TYPE: C.PLUG_TYPE_IMPORT, | 32 C.PI_TYPE: C.PLUG_TYPE_IMPORT, |
31 C.PI_DEPENDENCIES: ["IMPORT", "XEP-0060", "PUBSUB_SCHEMA"], | 33 C.PI_DEPENDENCIES: ["IMPORT", "XEP-0060", "XEP-0277", "PUBSUB_SCHEMA"], |
32 C.PI_MAIN: "TicketsImportPlugin", | 34 C.PI_MAIN: "TicketsImportPlugin", |
33 C.PI_HANDLER: "no", | 35 C.PI_HANDLER: "no", |
34 C.PI_DESCRIPTION: _(u"""Tickets import management: | 36 C.PI_DESCRIPTION: _(u"""Tickets import management: |
35 This plugin manage the different tickets importers which can register to it, and handle generic importing tasks.""") | 37 This plugin manage the different tickets importers which can register to it, and handle generic importing tasks.""") |
36 } | 38 } |
45 def __init__(self, host): | 47 def __init__(self, host): |
46 log.info(_("plugin Tickets Import initialization")) | 48 log.info(_("plugin Tickets Import initialization")) |
47 self.host = host | 49 self.host = host |
48 self._importers = {} | 50 self._importers = {} |
49 self._p = host.plugins['XEP-0060'] | 51 self._p = host.plugins['XEP-0060'] |
52 self._m = host.plugins['XEP-0277'] | |
50 self._s = host.plugins['PUBSUB_SCHEMA'] | 53 self._s = host.plugins['PUBSUB_SCHEMA'] |
51 host.plugins['IMPORT'].initialize(self, u'tickets') | 54 host.plugins['IMPORT'].initialize(self, u'tickets') |
52 | 55 |
53 @defer.inlineCallbacks | 56 @defer.inlineCallbacks |
54 def importItem(self, client, item_import_data, session, options, return_data, service, node): | 57 def importItem(self, client, item_import_data, session, options, return_data, service, node): |
59 'id': unique id (must be unique in the node) of the ticket | 62 'id': unique id (must be unique in the node) of the ticket |
60 'title': title (or short description/summary) of the ticket | 63 'title': title (or short description/summary) of the ticket |
61 'body': main description of the ticket | 64 'body': main description of the ticket |
62 'creation': date of creation | 65 'creation': date of creation |
63 'update': date of last update | 66 'update': date of last update |
64 'reporter_name': full name of reporter | 67 'reporter': full name of reporter |
68 'reporter_jid': jid of reporter | |
65 'reporter_email': email of reporter | 69 'reporter_email': email of reporter |
66 'assigned_to_name': full name of person working on it | 70 'assigned_to_name': full name of person working on it |
67 'assigned_to_email': email of person working on it | 71 'assigned_to_email': email of person working on it |
68 'cc_emails': iterable of emails subscribed to the ticket | 72 'cc_emails': iterable of emails subscribed to the ticket |
69 'priority': priority of the ticket | 73 'priority': priority of the ticket |
77 - "queued": ticket is waiting | 81 - "queued": ticket is waiting |
78 - "started": progress is ongoing | 82 - "started": progress is ongoing |
79 - "review": ticket is fixed and waiting for review | 83 - "review": ticket is fixed and waiting for review |
80 - "closed": ticket is finished or invalid | 84 - "closed": ticket is finished or invalid |
81 'milestone': target milestone for this ticket | 85 'milestone': target milestone for this ticket |
86 'comments': list of microblog data (comment metadata, check [XEP_0277.send] data argument) | |
82 """ | 87 """ |
88 if 'comments_uri' in item_import_data: | |
89 raise exceptions.DataError(_(u'comments_uri key will be generated and must not be used by importer')) | |
90 if session[u'root_node'] is None: | |
91 session[u'root_node'] = NS_TICKETS | |
83 if not 'schema' in session: | 92 if not 'schema' in session: |
84 session['schema'] = yield self._s.getSchemaForm(client, service, node or NS_TICKETS) | 93 session['schema'] = yield self._s.getSchemaForm(client, service, node or session[u'root_node']) |
85 defer.returnValue(item_import_data) | 94 defer.returnValue(item_import_data) |
86 | 95 |
96 @defer.inlineCallbacks | |
87 def importSubItems(self, client, item_import_data, ticket_data, session, options): | 97 def importSubItems(self, client, item_import_data, ticket_data, session, options): |
88 return None | 98 # TODO: force "open" permission (except if private, check below) |
99 # TODO: handle "private" metadata, to have non public access for node | |
100 comments = ticket_data.get('comments', []) | |
101 service, node = self._m.getCommentsService(client), self._m.getCommentsNode(session['root_node'] + u'_' + ticket_data['id']) | |
102 yield self._p.createIfNewNode(client, service, node) | |
103 ticket_data['comments_uri'] = uri.buildXMPPUri(u'pubsub', subtype='microblog', path=service.full(), node=node) | |
104 for comment in comments: | |
105 if 'updated' not in comment and 'published' in comment: | |
106 # we don't want an automatic update date | |
107 comment['updated'] = comment['published'] | |
108 yield self._m.send(client, comment, service, node) | |
89 | 109 |
90 def publishItem(self, client, ticket_data, service, node, session): | 110 def publishItem(self, client, ticket_data, service, node, session): |
91 if node is None: | 111 if node is None: |
92 node = NS_TICKETS | 112 node = NS_TICKETS |
93 id_ = ticket_data.pop('id', None) | 113 id_ = ticket_data.pop('id', None) |