comparison sat/plugins/plugin_misc_tickets.py @ 3309:71761e9fb984

plugins tickets, merge-requests: `ticketsGet` and `mergeRequestsGet` serialisation: those methods now return data serialised with `data_format.serialise`
author Goffi <goffi@goffi.org>
date Thu, 16 Jul 2020 09:07:26 +0200
parents 559a625a236b
children bb0225aaf4e6
comparison
equal deleted inserted replaced
3308:384283adcce1 3309:71761e9fb984
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2
3 2
4 # SAT plugin for Pubsub Schemas 3 # SAT plugin for Pubsub Schemas
5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) 4 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
6 5
7 # This program is free software: you can redistribute it and/or modify 6 # This program is free software: you can redistribute it and/or modify
50 self._m = self.host.plugins["XEP-0277"] 49 self._m = self.host.plugins["XEP-0277"]
51 host.bridge.addMethod( 50 host.bridge.addMethod(
52 "ticketsGet", 51 "ticketsGet",
53 ".plugin", 52 ".plugin",
54 in_sign="ssiassa{ss}s", 53 in_sign="ssiassa{ss}s",
55 out_sign="(asa{ss})", 54 out_sign="s",
56 method=lambda service, node, max_items, items_ids, sub_id, extra, profile_key: 55 method=lambda service, node, max_items, items_ids, sub_id, extra, profile_key:
57 self._s._get( 56 self._s._get(
58 service, 57 service,
59 node, 58 node,
60 max_items, 59 max_items,
93 def _set(self, service, node, values, schema=None, item_id=None, extra='', 92 def _set(self, service, node, values, schema=None, item_id=None, extra='',
94 profile_key=C.PROF_KEY_NONE): 93 profile_key=C.PROF_KEY_NONE):
95 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet( 94 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(
96 service, node, schema, item_id, extra, profile_key 95 service, node, schema, item_id, extra, profile_key
97 ) 96 )
98 d = self.set( 97 d = defer.ensureDeferred(self.set(
99 client, service, node, values, schema, item_id, extra, deserialise=True 98 client, service, node, values, schema, item_id, extra, deserialise=True
100 ) 99 ))
101 d.addCallback(lambda ret: ret or "") 100 d.addCallback(lambda ret: ret or "")
102 return d 101 return d
103 102
104 @defer.inlineCallbacks 103 async def set(self, client, service, node, values, schema=None, item_id=None, extra=None,
105 def set(self, client, service, node, values, schema=None, item_id=None, extra=None,
106 deserialise=False, form_ns=NS_TICKETS): 104 deserialise=False, form_ns=NS_TICKETS):
107 """Publish a tickets 105 """Publish a tickets
108 106
109 @param node(unicode, None): Pubsub node to use 107 @param node(unicode, None): Pubsub node to use
110 None to use default tickets node 108 None to use default tickets node
122 """ 120 """
123 if not node: 121 if not node:
124 node = NS_TICKETS 122 node = NS_TICKETS
125 123
126 if not item_id: 124 if not item_id:
127 comments_service = yield self._m.getCommentsService(client, service) 125 comments_service = await self._m.getCommentsService(client, service)
128 126
129 # we need to use uuid for comments node, because we don't know item id in 127 # we need to use uuid for comments node, because we don't know item id in
130 # advance (we don't want to set it ourselves to let the server choose, so we 128 # advance (we don't want to set it ourselves to let the server choose, so we
131 # can have a nicer id if serial ids is activated) 129 # can have a nicer id if serial ids is activated)
132 comments_node = self._m.getCommentsNode( 130 comments_node = self._m.getCommentsNode(
138 self._p.OPT_MAX_ITEMS: -1, 136 self._p.OPT_MAX_ITEMS: -1,
139 self._p.OPT_DELIVER_PAYLOADS: 1, 137 self._p.OPT_DELIVER_PAYLOADS: 1,
140 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, 138 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
141 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, 139 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
142 } 140 }
143 yield self._p.createNode(client, comments_service, comments_node, options) 141 await self._p.createNode(client, comments_service, comments_node, options)
144 values["comments_uri"] = uri.buildXMPPUri( 142 values["comments_uri"] = uri.buildXMPPUri(
145 "pubsub", 143 "pubsub",
146 subtype="microblog", 144 subtype="microblog",
147 path=comments_service.full(), 145 path=comments_service.full(),
148 node=comments_node, 146 node=comments_node,
149 ) 147 )
150 148
151 item_id = yield self._s.set( 149 return await self._s.set(
152 client, service, node, values, schema, item_id, extra, deserialise, form_ns 150 client, service, node, values, schema, item_id, extra, deserialise, form_ns
153 ) 151 )
154 defer.returnValue(item_id)