comparison sat/plugins/plugin_misc_tickets.py @ 2959:989b622faff6

plugins schema, tickets, merge_requests: use serialised data for extra dict + some cosmetic changes
author Goffi <goffi@goffi.org>
date Fri, 14 Jun 2019 12:37:34 +0200
parents f18d8315929e
children ab2696e34d29
comparison
equal deleted inserted replaced
2958:e2cb04b381bb 2959:989b622faff6
28 log = getLogger(__name__) 28 log = getLogger(__name__)
29 29
30 NS_TICKETS = "org.salut-a-toi.tickets:0" 30 NS_TICKETS = "org.salut-a-toi.tickets:0"
31 31
32 PLUGIN_INFO = { 32 PLUGIN_INFO = {
33 C.PI_NAME: _("Tickets management"), 33 C.PI_NAME: _(u"Tickets management"),
34 C.PI_IMPORT_NAME: "TICKETS", 34 C.PI_IMPORT_NAME: u"TICKETS",
35 C.PI_TYPE: "EXP", 35 C.PI_TYPE: u"EXP",
36 C.PI_PROTOCOLS: [], 36 C.PI_PROTOCOLS: [],
37 C.PI_DEPENDENCIES: ["XEP-0060", "PUBSUB_SCHEMA", "XEP-0277", "IDENTITY"], 37 C.PI_DEPENDENCIES: [u"XEP-0060", u"PUBSUB_SCHEMA", u"XEP-0277", u"IDENTITY"],
38 C.PI_MAIN: "Tickets", 38 C.PI_MAIN: u"Tickets",
39 C.PI_HANDLER: "no", 39 C.PI_HANDLER: u"no",
40 C.PI_DESCRIPTION: _("""Tickets management plugin"""), 40 C.PI_DESCRIPTION: _(u"""Tickets management plugin"""),
41 } 41 }
42 42
43 43
44 class Tickets(object): 44 class Tickets(object):
45 def __init__(self, host): 45 def __init__(self, host):
46 log.info(_(u"Tickets plugin initialization")) 46 log.info(_(u"Tickets plugin initialization"))
47 self.host = host 47 self.host = host
48 host.registerNamespace("tickets", NS_TICKETS) 48 host.registerNamespace(u"tickets", NS_TICKETS)
49 self._p = self.host.plugins["XEP-0060"] 49 self._p = self.host.plugins[u"XEP-0060"]
50 self._s = self.host.plugins["PUBSUB_SCHEMA"] 50 self._s = self.host.plugins[u"PUBSUB_SCHEMA"]
51 self._m = self.host.plugins["XEP-0277"] 51 self._m = self.host.plugins[u"XEP-0277"]
52 host.bridge.addMethod( 52 host.bridge.addMethod(
53 "ticketsGet", 53 u"ticketsGet",
54 ".plugin", 54 u".plugin",
55 in_sign="ssiassa{ss}s", 55 in_sign=u"ssiassa{ss}s",
56 out_sign="(asa{ss})", 56 out_sign=u"(asa{ss})",
57 method=utils.partial( 57 method=utils.partial(
58 self._s._get, 58 self._s._get,
59 default_node=NS_TICKETS, 59 default_node=NS_TICKETS,
60 form_ns=NS_TICKETS, 60 form_ns=NS_TICKETS,
61 filters={ 61 filters={
67 async=True, 67 async=True,
68 ) 68 )
69 host.bridge.addMethod( 69 host.bridge.addMethod(
70 "ticketSet", 70 "ticketSet",
71 ".plugin", 71 ".plugin",
72 in_sign="ssa{sas}ssa{ss}s", 72 in_sign="ssa{sas}ssss",
73 out_sign="s", 73 out_sign="s",
74 method=self._set, 74 method=self._set,
75 async=True, 75 async=True,
76 ) 76 )
77 host.bridge.addMethod( 77 host.bridge.addMethod(
81 out_sign="s", 81 out_sign="s",
82 method=utils.partial(self._s._getUISchema, default_node=NS_TICKETS), 82 method=utils.partial(self._s._getUISchema, default_node=NS_TICKETS),
83 async=True, 83 async=True,
84 ) 84 )
85 85
86 def _set(self, service, node, values, schema=None, item_id=None, extra=None, 86 def _set(self, service, node, values, schema=None, item_id=None, extra=u'',
87 profile_key=C.PROF_KEY_NONE): 87 profile_key=C.PROF_KEY_NONE):
88 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet( 88 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(
89 service, node, schema, item_id, extra, profile_key 89 service, node, schema, item_id, extra, profile_key
90 ) 90 )
91 d = self.set( 91 d = self.set(
100 """Publish a tickets 100 """Publish a tickets
101 101
102 @param node(unicode, None): Pubsub node to use 102 @param node(unicode, None): Pubsub node to use
103 None to use default tickets node 103 None to use default tickets node
104 @param values(dict[key(unicode), [iterable[object]|object]]): values of the ticket 104 @param values(dict[key(unicode), [iterable[object]|object]]): values of the ticket
105
105 if value is not iterable, it will be put in a list 106 if value is not iterable, it will be put in a list
106 'created' and 'updated' will be forced to current time: 107 'created' and 'updated' will be forced to current time:
107 - 'created' is set if item_id is None, i.e. if it's a new ticket 108 - 'created' is set if item_id is None, i.e. if it's a new ticket
108 - 'updated' is set everytime 109 - 'updated' is set everytime
109 @param extra(dict, None): same as for [XEP-0060.sendItem] with additional keys: 110 @param extra(dict, None): same as for [XEP-0060.sendItem] with additional keys:
112 other arguments are same as for [self._s.sendDataFormItem] 113 other arguments are same as for [self._s.sendDataFormItem]
113 @return (unicode): id of the created item 114 @return (unicode): id of the created item
114 """ 115 """
115 if not node: 116 if not node:
116 node = NS_TICKETS 117 node = NS_TICKETS
118
117 if not item_id: 119 if not item_id:
118 comments_service = yield self._m.getCommentsService(client, service) 120 comments_service = yield self._m.getCommentsService(client, service)
119 121
120 # we need to use uuid for comments node, because we don't know item id in 122 # we need to use uuid for comments node, because we don't know item id in
121 # advance (we don't want to set it ourselves to let the server choose, so we 123 # advance (we don't want to set it ourselves to let the server choose, so we
130 self._p.OPT_DELIVER_PAYLOADS: 1, 132 self._p.OPT_DELIVER_PAYLOADS: 1,
131 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, 133 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
132 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, 134 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
133 } 135 }
134 yield self._p.createNode(client, comments_service, comments_node, options) 136 yield self._p.createNode(client, comments_service, comments_node, options)
135 values["comments_uri"] = uri.buildXMPPUri( 137 values[u"comments_uri"] = uri.buildXMPPUri(
136 u"pubsub", 138 u"pubsub",
137 subtype="microblog", 139 subtype="microblog",
138 path=comments_service.full(), 140 path=comments_service.full(),
139 node=comments_node, 141 node=comments_node,
140 ) 142 )
143
141 item_id = yield self._s.set( 144 item_id = yield self._s.set(
142 client, service, node, values, schema, item_id, extra, deserialise, form_ns 145 client, service, node, values, schema, item_id, extra, deserialise, form_ns
143 ) 146 )
144 defer.returnValue(item_id) 147 defer.returnValue(item_id)